Skip to content

Commit 3907914

Browse files
committed
Guard against filesystem paths in git.ReadBranchConfig
A valid remote specificication read from `branch.<name>.remote` git config can be a URL, a `.`, a filesystem path, and a remote name. When detecting the remote name, be sure not to take filesystem paths instead.
1 parent c36b84e commit 3907914

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

git/git.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ func ReadBranchConfig(branch string) (cfg BranchConfig) {
173173
continue
174174
}
175175
cfg.RemoteURL = u
176-
} else {
176+
} else if !isFilesystemPath(parts[1]) {
177177
cfg.RemoteName = parts[1]
178178
}
179179
case "merge":
@@ -183,6 +183,10 @@ func ReadBranchConfig(branch string) (cfg BranchConfig) {
183183
return
184184
}
185185

186+
func isFilesystemPath(p string) bool {
187+
return p == "." || strings.HasPrefix(p, "./") || strings.HasPrefix(p, "/")
188+
}
189+
186190
// ToplevelDir returns the top-level directory path of the current repository
187191
func ToplevelDir() (string, error) {
188192
showCmd := exec.Command("git", "rev-parse", "--show-toplevel")

0 commit comments

Comments
 (0)