@@ -10,6 +10,8 @@ import (
1010const (
1111 //EmptySha represents the state of a brand new ref
1212 EmptySha string = "0000000000000000000000000000000000000000"
13+ //ShaId of the empty tree in Git
14+ EmptyTreeSha string = "4b825dc642cb6eb9a060e54bf8d69288fbee4904"
1315)
1416
1517type PrePushHook struct {
@@ -20,9 +22,8 @@ func NewPrePushHook(localRef, localCommit, remoteRef, remoteCommit string) *PreP
2022 return & PrePushHook {localRef , localCommit , remoteRef , remoteCommit }
2123}
2224
23- //Brand new repositoris are not validated at all
2425//If the outgoing ref does not exist on the remote, all commits on the local ref will be checked
25- //If the outgoing ref already exists, all additions in the range beween "localSha" and "remoteSha" will be validated
26+ //If the outgoing ref already exists, all additions in the range between "localSha" and "remoteSha" will be validated
2627func (p * PrePushHook ) GetRepoAdditions () []git_repo.Addition {
2728 if p .runningOnDeletedRef () {
2829 log .WithFields (log.Fields {
@@ -43,7 +44,7 @@ func (p *PrePushHook) GetRepoAdditions() []git_repo.Addition {
4344 "remoteCommit" : p .remoteCommit ,
4445 }).Info ("Running on a new ref. All changes in the ref will be verified." )
4546
46- return []git_repo. Addition {}
47+ return p . getRepoAdditionsFrom ( EmptyTreeSha , p . localCommit )
4748 }
4849
4950 log .WithFields (log.Fields {
@@ -65,7 +66,11 @@ func (p *PrePushHook) runningOnNewRef() bool {
6566}
6667
6768func (p * PrePushHook ) getRepoAdditions () []git_repo.Addition {
69+ return p .getRepoAdditionsFrom (p .remoteCommit , p .localCommit )
70+ }
71+
72+ func (p * PrePushHook ) getRepoAdditionsFrom (oldCommit , newCommit string ) []git_repo.Addition {
6873 wd , _ := os .Getwd ()
6974 repo := git_repo .RepoLocatedAt (wd )
70- return repo .AdditionsWithinRange (p . remoteCommit , p . localCommit )
75+ return repo .AdditionsWithinRange (oldCommit , newCommit )
7176}
0 commit comments