-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathRevert.swift
59 lines (51 loc) · 2.09 KB
/
Revert.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//
// Revert.swift
// AuroraEditor
//
// Created by Nanashi Li on 2022/08/13.
// Copyright © 2022 Aurora Company. All rights reserved.
// This source code is restricted for Aurora Editor usage only.
//
import Foundation
public struct GitRevert {
/// Creates a new commit that reverts the changes of a previous commit
///
/// @param sha - The SHA of the commit to be reverted
func revertCommit(directoryURL: URL,
commit: Commit,
progressCallback: ((RevertProgress) -> Void)?
) throws {
var args = gitNetworkArguments + ["revert"]
if commit.parentSHAs.count > 1 {
args += ["-m", "1"]
}
args.append(commit.sha)
var opts: IGitExecutionOptions?
if let progressCallback = progressCallback {
opts = try FromProcess().executionOptionsWithProgress(
options: IGitExecutionOptions(trackLFSProgress: true),
parser: GitProgressParser(steps: [ProgressStep(title: "", weight: 0)]),
progressCallback: { progress in
var description: String = ""
var title: String = ""
if let gitProgress = progress as? IGitProgress, progress.kind == "progress" {
description = gitProgress.details.text
title = gitProgress.details.title
} else if let gitOutput = progress as? IGitOutput {
description = gitOutput.text
title = ""
}
let value = progress.percent
progressCallback(RevertProgress(kind: "revert",
value: value,
title: title,
description: description))
}
)
}
try GitShell().git(args: args,
path: directoryURL,
name: #function,
options: opts)
}
}