Skip to content

Commit ab17982

Browse files
Chris McDonnellstefanhaller
Chris McDonnell
authored andcommitted
Use full refname instead of short to prevent disambiguation with tag
In the unlikely scenario that you have a remote branch on `origin` called `foo`, and a local tag called `origin/foo`, git changes the behavior of the previous command such that it produces ``` $ git for-each-ref --sort=refname --format=%(refname:short) refs/remotes origin/branch1 remotes/origin/foo ``` with `remotes/` prepended. Presumably this is to disambiguate it from the local tag `origin/foo`. Unfortunately, this breaks the existing behavior of this function, so the remote branch is never shown. By changing the command, we now get ``` $ git for-each-ref --sort=refname --format=%(refname) refs/remotes refs/remotes/origin/branch1 refs/remotes/origin/foo ``` This allows easy parsing based on the `/`, and none of the code outside this function has to change.
1 parent c5ea445 commit ab17982

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

pkg/commands/git_commands/remote_loader.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,19 +96,19 @@ func (self *RemoteLoader) getRemoteBranchesByRemoteName() (map[string][]*models.
9696

9797
cmdArgs := NewGitCmd("for-each-ref").
9898
Arg(fmt.Sprintf("--sort=%s", sortOrder)).
99-
Arg("--format=%(refname:short)").
99+
Arg("--format=%(refname)").
100100
Arg("refs/remotes").
101101
ToArgv()
102102

103103
err := self.cmd.New(cmdArgs).DontLog().RunAndProcessLines(func(line string) (bool, error) {
104104
line = strings.TrimSpace(line)
105105

106-
split := strings.SplitN(line, "/", 2)
107-
if len(split) != 2 {
106+
split := strings.SplitN(line, "/", 4)
107+
if len(split) != 4 {
108108
return false, nil
109109
}
110-
remoteName := split[0]
111-
name := split[1]
110+
remoteName := split[2]
111+
name := split[3]
112112

113113
_, ok := remoteBranchesByRemoteName[remoteName]
114114
if !ok {

0 commit comments

Comments
 (0)