Skip to content

Commit 1542ff6

Browse files
committed
[Utility] Change git error handling.
- Don't exit on every git error, only if the git version is detected as unsupported. - Patch by Kostiantyn Koval, with modifications by me.
1 parent 7006b57 commit 1542ff6

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

Sources/Utility/Git.swift

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public class Git {
7070
do {
7171
try system(Git.tool, "-C", path, "fetch", "--tags", "origin", message: nil)
7272
} catch let errror {
73-
Git.handle(errror)
73+
try Git.checkGitVersion(errror)
7474
}
7575
}
7676
}
@@ -96,14 +96,15 @@ public class Git {
9696
return Int(String(first))
9797
}
9898

99-
@noreturn public class func handle(_ error: ErrorProtocol) {
99+
@noreturn public class func checkGitVersion(_ error: ErrorProtocol) throws {
100100
// Git 2.0 or higher is required
101101
if Git.majorVersionNumber < 2 {
102+
// FIXME: This does not belong here.
102103
print("error: ", Error.obsoleteGitVersion)
104+
exit(1)
103105
} else {
104-
print("error: ", Error.unknownGitError)
106+
throw error
105107
}
106-
exit(1)
107108
}
108109

109110
/// Execute a git command while suppressing output.
@@ -113,7 +114,7 @@ public class Git {
113114
do {
114115
try system(arguments)
115116
} catch let error {
116-
handle(error)
117+
try checkGitVersion(error)
117118
}
118119
}
119120

@@ -124,7 +125,7 @@ public class Git {
124125
do {
125126
return try popen(arguments)
126127
} catch let error {
127-
handle(error)
128+
try checkGitVersion(error)
128129
}
129130
}
130131
}

0 commit comments

Comments
 (0)