ExtractGitRemote extracts the first Git remote from the Git repository at projectPath. If remoteName is provided, it will return the remote with that name. If detectDotGit is true, it will look for a .git directory in parent directories.
(projectPath, remoteName string, detectDotGit bool)
| 100 | // If remoteName is provided, it will return the remote with that name. |
| 101 | // If detectDotGit is true, it will look for a .git directory in parent directories. |
| 102 | func ExtractGitRemote(projectPath, remoteName string, detectDotGit bool) (Remote, error) { |
| 103 | remotes, err := ExtractRemotes(projectPath, detectDotGit) |
| 104 | if err != nil { |
| 105 | return Remote{}, err |
| 106 | } |
| 107 | if remoteName != "" { |
| 108 | for _, remote := range remotes { |
| 109 | if remote.Name == remoteName { |
| 110 | return remote, nil |
| 111 | } |
| 112 | } |
| 113 | return Remote{}, ErrGitRemoteNotFound |
| 114 | } |
| 115 | if len(remotes) == 0 { |
| 116 | return Remote{}, ErrGitRemoteNotFound |
| 117 | } |
| 118 | return remotes[0], nil |
| 119 | } |
| 120 | |
| 121 | // ExtractRemotes extracts all Git remotes from the Git repository at projectPath. |
| 122 | // If detectDotGit is true, it will look for a .git directory in parent directories. |