@@ -46,7 +46,7 @@ func (repo *Repository) GetMergeBase(tmpRemote string, base, head string) (strin
46
46
}
47
47
48
48
// 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 ) {
50
50
var (
51
51
remoteBranch string
52
52
tmpRemote string
@@ -79,8 +79,15 @@ func (repo *Repository) GetCompareInfo(basePath, baseBranch, headBranch string)
79
79
if err != nil {
80
80
compareInfo .BaseCommitID = remoteBranch
81
81
}
82
+ separator := "..."
83
+ baseCommitID := compareInfo .MergeBase
84
+ if directComparison {
85
+ separator = ".."
86
+ baseCommitID = compareInfo .BaseCommitID
87
+ }
88
+
82
89
// 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 )
84
91
if err != nil {
85
92
return nil , err
86
93
}
@@ -100,7 +107,7 @@ func (repo *Repository) GetCompareInfo(basePath, baseBranch, headBranch string)
100
107
// Count number of changed files.
101
108
// This probably should be removed as we need to use shortstat elsewhere
102
109
// 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 )
104
111
if err != nil {
105
112
return nil , err
106
113
}
@@ -120,12 +127,17 @@ func (l *lineCountWriter) Write(p []byte) (n int, err error) {
120
127
121
128
// GetDiffNumChangedFiles counts the number of changed files
122
129
// 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 ) {
124
131
// Now there is git diff --shortstat but this appears to be slower than simply iterating with --nameonly
125
132
w := & lineCountWriter {}
126
133
stderr := new (bytes.Buffer )
127
134
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 ).
129
141
RunInDirPipeline (repo .Path , w , stderr ); err != nil {
130
142
if strings .Contains (stderr .String (), "no merge base" ) {
131
143
// git >= 2.28 now returns an error if base and head have become unrelated.
0 commit comments