File tree Expand file tree Collapse file tree
CodeEdit/Features/Git/Client Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -34,8 +34,7 @@ extension GitClient {
3434 " log -z --pretty=%h¦%H¦%s¦%aN¦%ae¦%cn¦%ce¦%aD¦%b¦%D¦ \( maxCountString) \( branchNameString) \( fileLocalPath) "
3535 . trimmingCharacters ( in: . whitespacesAndNewlines)
3636 )
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 ( )
3938
4039 return output
4140 . split ( separator: " \0 " )
Original file line number Diff line number Diff line change @@ -31,6 +31,23 @@ extension GitClient {
3131 func removeRemote( name: String ) async throws {
3232 _ = try await run ( " remote rm \( name) " )
3333 }
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+ }
3451}
3552
3653func parseGitRemotes( from output: String ) -> [ GitRemote ] {
Original file line number Diff line number Diff line change @@ -13,12 +13,14 @@ class GitClient {
1313 case outputError( String )
1414 case notGitRepository
1515 case failedToDecodeURL
16+ case noRemoteConfigured
1617
1718 var description : String {
1819 switch self {
1920 case . outputError( let string) : string
2021 case . notGitRepository: " Not a git repository "
2122 case . failedToDecodeURL: " Failed to decode URL "
23+ case . noRemoteConfigured: " No remote configured "
2224 }
2325 }
2426 }
@@ -63,6 +65,10 @@ class GitClient {
6365 throw GitClientError . notGitRepository
6466 }
6567
68+ if output. contains ( " fatal: No remote configured " ) {
69+ throw GitClientError . noRemoteConfigured
70+ }
71+
6672 if output. hasPrefix ( " fatal: " ) {
6773 throw GitClientError . outputError ( output)
6874 }
You can’t perform that action at this time.
0 commit comments