@@ -23,9 +23,6 @@ const (
2323 stashMessage = "lefthook auto backup"
2424 unstagedPatchName = "lefthook-unstaged.patch"
2525 infoDirMode = 0o775
26-
27- // The result of `git hash-object -t tree /dev/null`.
28- emptyTreeSHA = "4b825dc642cb6eb9a060e54bf8d69288fbee4904"
2926)
3027
3128var (
3532 reStashMessage = regexp .MustCompile (`^(?P<stash>[^ ]+):\s*` + stashMessage )
3633 cmdPushFilesBase = []string {"git" , "diff" , "--name-only" , "HEAD" , "@{push}" }
3734 cmdPushFilesHead = []string {"git" , "diff" , "--name-only" , "HEAD" }
35+ cmdPushFilesTreeBase = []string {"git" , "ls-tree" , "-r" , "--name-only" }
3836 cmdStagedFiles = []string {"git" , "diff" , "--name-only" , "--cached" , "--diff-filter=ACMR" }
3937 cmdStagedFilesWithDeleted = []string {"git" , "diff" , "--name-only" , "--cached" , "--diff-filter=ACMRD" }
4038 cmdStatusShort = []string {"git" , "status" , "--short" , "--porcelain" , "-z" }
@@ -212,7 +210,12 @@ func (r *Repository) resolveHeadBranch() string {
212210 }
213211 }
214212
215- return emptyTreeSHA
213+ // Nothing has been pushed yet or upstream is not set
214+ if len (r .headBranch ) == 0 {
215+ return r .FindExistingFiles (append (cmdPushFilesTreeBase , "HEAD" ), "" )
216+ }
217+
218+ return r .FindExistingFiles (append (cmdPushFilesHead , r .headBranch ), "" )
216219}
217220
218221// PartiallyStagedFiles returns the list of files that have both staged and
0 commit comments