File tree Expand file tree Collapse file tree 3 files changed +24
-2
lines changed
CodeEdit/Features/Git/Client Expand file tree Collapse file tree 3 files changed +24
-2
lines changed Original file line number Diff line number Diff line change @@ -34,8 +34,7 @@ extension GitClient {
34
34
" log -z --pretty=%h¦%H¦%s¦%aN¦%ae¦%cn¦%ce¦%aD¦%b¦%D¦ \( maxCountString) \( branchNameString) \( fileLocalPath) "
35
35
. trimmingCharacters ( in: . whitespacesAndNewlines)
36
36
)
37
- let remote = try await run ( " ls-remote --get-url " )
38
- let remoteURL = URL ( string: remote. trimmingCharacters ( in: . whitespacesAndNewlines) )
37
+ let remoteURL = try await getRemoteURL ( )
39
38
40
39
return output
41
40
. split ( separator: " \0 " )
Original file line number Diff line number Diff line change @@ -31,6 +31,23 @@ extension GitClient {
31
31
func removeRemote( name: String ) async throws {
32
32
_ = try await run ( " remote rm \( name) " )
33
33
}
34
+
35
+ /// Get the URL of the remote
36
+ /// > Note: If a git repository has multiple remotes, by default the `origin` remote
37
+ /// > will be used, unless there’s an upstream branch configured for the current branch.
38
+ /// > (Reference: https://git-scm.com/docs/git-ls-remote, https://git-scm.com/docs/git-fetch)
39
+ /// - Returns: A URL if a remote is configured, nil otherwise
40
+ /// - Throws: `GitClientError.outputError` if the underlying git command fails unexpectedly
41
+ func getRemoteURL( ) async throws -> URL ? {
42
+ do {
43
+ let remote = try await run ( " ls-remote --get-url " )
44
+ return URL ( string: remote. trimmingCharacters ( in: . whitespacesAndNewlines) )
45
+ } catch GitClientError . noRemoteConfigured {
46
+ return nil
47
+ } catch {
48
+ throw error
49
+ }
50
+ }
34
51
}
35
52
36
53
func parseGitRemotes( from output: String ) -> [ GitRemote ] {
Original file line number Diff line number Diff line change @@ -13,12 +13,14 @@ class GitClient {
13
13
case outputError( String )
14
14
case notGitRepository
15
15
case failedToDecodeURL
16
+ case noRemoteConfigured
16
17
17
18
var description : String {
18
19
switch self {
19
20
case . outputError( let string) : string
20
21
case . notGitRepository: " Not a git repository "
21
22
case . failedToDecodeURL: " Failed to decode URL "
23
+ case . noRemoteConfigured: " No remote configured "
22
24
}
23
25
}
24
26
}
@@ -63,6 +65,10 @@ class GitClient {
63
65
throw GitClientError . notGitRepository
64
66
}
65
67
68
+ if output. contains ( " fatal: No remote configured " ) {
69
+ throw GitClientError . noRemoteConfigured
70
+ }
71
+
66
72
if output. hasPrefix ( " fatal: " ) {
67
73
throw GitClientError . outputError ( output)
68
74
}
You can’t perform that action at this time.
0 commit comments