@@ -46,7 +46,7 @@ func (repo *Repository) GetMergeBase(tmpRemote string, base, head string) (strin
4646}
4747
4848// GetCompareInfo generates and returns compare information between base and head branches of repositories.
49- func (repo * Repository ) GetCompareInfo (basePath , baseBranch , headBranch string ) (_ * CompareInfo , err error ) {
49+ func (repo * Repository ) GetCompareInfo (basePath , baseBranch , headBranch string , directComparison bool ) (_ * CompareInfo , err error ) {
5050 var (
5151 remoteBranch string
5252 tmpRemote string
@@ -79,8 +79,15 @@ func (repo *Repository) GetCompareInfo(basePath, baseBranch, headBranch string)
7979 if err != nil {
8080 compareInfo .BaseCommitID = remoteBranch
8181 }
82+ separator := "..."
83+ baseCommitID := compareInfo .MergeBase
84+ if directComparison {
85+ separator = ".."
86+ baseCommitID = compareInfo .BaseCommitID
87+ }
88+
8289 // We have a common base - therefore we know that ... should work
83- logs , err := NewCommand ("log" , compareInfo . MergeBase + "..." + headBranch , prettyLogFormat ).RunInDirBytes (repo .Path )
90+ logs , err := NewCommand ("log" , baseCommitID + separator + headBranch , prettyLogFormat ).RunInDirBytes (repo .Path )
8491 if err != nil {
8592 return nil , err
8693 }
@@ -100,7 +107,7 @@ func (repo *Repository) GetCompareInfo(basePath, baseBranch, headBranch string)
100107 // Count number of changed files.
101108 // This probably should be removed as we need to use shortstat elsewhere
102109 // Now there is git diff --shortstat but this appears to be slower than simply iterating with --nameonly
103- compareInfo .NumFiles , err = repo .GetDiffNumChangedFiles (remoteBranch , headBranch )
110+ compareInfo .NumFiles , err = repo .GetDiffNumChangedFiles (remoteBranch , headBranch , directComparison )
104111 if err != nil {
105112 return nil , err
106113 }
@@ -120,12 +127,17 @@ func (l *lineCountWriter) Write(p []byte) (n int, err error) {
120127
121128// GetDiffNumChangedFiles counts the number of changed files
122129// This is substantially quicker than shortstat but...
123- func (repo * Repository ) GetDiffNumChangedFiles (base , head string ) (int , error ) {
130+ func (repo * Repository ) GetDiffNumChangedFiles (base , head string , directComparison bool ) (int , error ) {
124131 // Now there is git diff --shortstat but this appears to be slower than simply iterating with --nameonly
125132 w := & lineCountWriter {}
126133 stderr := new (bytes.Buffer )
127134
128- if err := NewCommand ("diff" , "-z" , "--name-only" , base + "..." + head ).
135+ separator := "..."
136+ if directComparison {
137+ separator = ".."
138+ }
139+
140+ if err := NewCommand ("diff" , "-z" , "--name-only" , base + separator + head ).
129141 RunInDirPipeline (repo .Path , w , stderr ); err != nil {
130142 if strings .Contains (stderr .String (), "no merge base" ) {
131143 // git >= 2.28 now returns an error if base and head have become unrelated.
0 commit comments