Skip to content

Commit 0df81b9

Browse files
authored
Add git dashes separator to some "log" and "diff" commands (#23606)
Reference: #22578 (comment) Credits to @tdesveaux , thank you very much for catching the problem. If you'd like to open a PR, feel free to replace this one. Git reports fatal errors for ambiguous arguments: ``` fatal: ambiguous argument 'refs/a...refs/b': unknown revision or path not in the working tree. Use '--' to separate paths from revisions, like this: 'git <command> [<revision>...] -- [<file>...]' ``` So the `--` separator is necessary in some cases.
1 parent d5f9a4e commit 0df81b9

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

modules/git/repo_compare.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,11 @@ func (repo *Repository) GetCompareInfo(basePath, baseBranch, headBranch string,
9292

9393
// We have a common base - therefore we know that ... should work
9494
if !fileOnly {
95+
// avoid: ambiguous argument 'refs/a...refs/b': unknown revision or path not in the working tree. Use '--': 'git <command> [<revision>...] -- [<file>...]'
9596
var logs []byte
96-
logs, _, err = NewCommand(repo.Ctx, "log").AddDynamicArguments(baseCommitID + separator + headBranch).AddArguments(prettyLogFormat).RunStdBytes(&RunOpts{Dir: repo.Path})
97+
logs, _, err = NewCommand(repo.Ctx, "log").AddArguments(prettyLogFormat).
98+
AddDynamicArguments(baseCommitID + separator + headBranch).AddArguments("--").
99+
RunStdBytes(&RunOpts{Dir: repo.Path})
97100
if err != nil {
98101
return nil, err
99102
}
@@ -146,7 +149,8 @@ func (repo *Repository) GetDiffNumChangedFiles(base, head string, directComparis
146149
separator = ".."
147150
}
148151

149-
if err := NewCommand(repo.Ctx, "diff", "-z", "--name-only").AddDynamicArguments(base + separator + head).
152+
// avoid: ambiguous argument 'refs/a...refs/b': unknown revision or path not in the working tree. Use '--': 'git <command> [<revision>...] -- [<file>...]'
153+
if err := NewCommand(repo.Ctx, "diff", "-z", "--name-only").AddDynamicArguments(base + separator + head).AddArguments("--").
150154
Run(&RunOpts{
151155
Dir: repo.Path,
152156
Stdout: w,
@@ -157,7 +161,7 @@ func (repo *Repository) GetDiffNumChangedFiles(base, head string, directComparis
157161
// previously it would return the results of git diff -z --name-only base head so let's try that...
158162
w = &lineCountWriter{}
159163
stderr.Reset()
160-
if err = NewCommand(repo.Ctx, "diff", "-z", "--name-only").AddDynamicArguments(base, head).Run(&RunOpts{
164+
if err = NewCommand(repo.Ctx, "diff", "-z", "--name-only").AddDynamicArguments(base, head).AddArguments("--").Run(&RunOpts{
161165
Dir: repo.Path,
162166
Stdout: w,
163167
Stderr: stderr,

0 commit comments

Comments
 (0)