Skip to content

Commit ea639a5

Browse files
author
epriestley
committed
Fix git rev-list when a file exists with the same name as the branch
Fixes issue git-lfs#1056. When you try to push `master` but also have a file named `master`, we run `git rev-list ... master`. This is ambiguous, because `rev-list` accepts paths or refs and `git` is unsure whether you mean the ref `master` or the path `master. Instead, run `git rev-list ... master --`, which is unambiguous. This adds a failing test (trying to push a file named `master` to LFS), then fixes the test by appending `--` to the command.
1 parent 8f90f59 commit ea639a5

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

lfs/scanner.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,11 @@ func revListShas(refLeft, refRight string, opt *ScanRefsOptions) (chan string, e
316316
return nil, errors.New("scanner: unknown scan type: " + strconv.Itoa(int(opt.ScanMode)))
317317
}
318318

319+
// Use "--" at the end of the command to disambiguate arguments as refs,
320+
// so Git doesn't complain about ambiguity if you happen to also have a
321+
// file named "master".
322+
refArgs = append(refArgs, "--")
323+
319324
cmd, err := startCommand("git", refArgs...)
320325
if err != nil {
321326
return nil, err
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
3+
. "test/testlib.sh"
4+
5+
begin_test "push a file with the same name as a branch"
6+
(
7+
set -e
8+
9+
reponame="$(basename "$0" ".sh")"
10+
setup_remote_repo "$reponame"
11+
clone_repo "$reponame" repo
12+
13+
git lfs track "master"
14+
echo "master" > master
15+
git add .gitattributes master
16+
git commit -m "add master"
17+
18+
git lfs push --all origin master 2>&1 | tee push.log
19+
grep "(1 of 1 files)" push.log
20+
)
21+
end_test

0 commit comments

Comments
 (0)