@@ -51,6 +51,8 @@ type detachedContext struct {
5151 tagName string
5252 cherryPick bool
5353 cherryPickSHA string
54+ merge bool
55+ mergeHEAD string
5456}
5557
5658func setupHEADContextEnv (context * detachedContext ) environmentInfo {
@@ -65,12 +67,15 @@ func setupHEADContextEnv(context *detachedContext) environmentInfo {
6567 env .On ("getFileContent" , ".git/rebase-apply/last" ).Return (context .total )
6668 env .On ("getFileContent" , ".git/rebase-apply/head-name" ).Return (context .origin )
6769 env .On ("getFileContent" , ".git/CHERRY_PICK_HEAD" ).Return (context .cherryPickSHA )
70+ env .On ("getFileContent" , ".git/MERGE_HEAD" ).Return (context .mergeHEAD )
6871 env .On ("hasFiles" , ".git/CHERRY_PICK_HEAD" ).Return (context .cherryPick )
72+ env .On ("hasFiles" , ".git/MERGE_HEAD" ).Return (context .merge )
6973 env .On ("runCommand" , "git" , []string {"-c" , "core.quotepath=false" , "-c" , "color.status=false" , "rev-parse" , "--short" , "HEAD" }).Return (context .currentCommit )
7074 env .On ("runCommand" , "git" , []string {"-c" , "core.quotepath=false" , "-c" , "color.status=false" , "describe" , "--tags" , "--exact-match" }).Return (context .tagName )
7175 env .On ("runCommand" , "git" , []string {"-c" , "core.quotepath=false" , "-c" , "color.status=false" , "name-rev" , "--name-only" , "--exclude=tags/*" , context .origin }).Return (context .origin )
7276 env .On ("runCommand" , "git" , []string {"-c" , "core.quotepath=false" , "-c" , "color.status=false" , "name-rev" , "--name-only" , "--exclude=tags/*" , context .onto }).Return (context .onto )
7377 env .On ("runCommand" , "git" , []string {"-c" , "core.quotepath=false" , "-c" , "color.status=false" , "name-rev" , "--name-only" , "--exclude=tags/*" , context .cherryPickSHA }).Return (context .cherryPickSHA )
78+ env .On ("runCommand" , "git" , []string {"-c" , "core.quotepath=false" , "-c" , "color.status=false" , "name-rev" , "--name-only" , "--exclude=tags/*" , context .mergeHEAD }).Return (context .mergeHEAD )
7479 return env
7580}
7681
@@ -184,6 +189,35 @@ func TestGetGitHEADContextCherryPickOnTag(t *testing.T) {
184189 assert .Equal (t , want , got )
185190}
186191
192+ func TestGetGitHEADContextMerge (t * testing.T ) {
193+ want := "MERGING:BRANCH:feat into BRANCH:main"
194+ context := & detachedContext {
195+ merge : true ,
196+ mergeHEAD : "feat" ,
197+ }
198+ env := setupHEADContextEnv (context )
199+ g := & git {
200+ env : env ,
201+ }
202+ got := g .getGitHEADContext ("main" )
203+ assert .Equal (t , want , got )
204+ }
205+
206+ func TestGetGitHEADContextMergeTag (t * testing.T ) {
207+ want := "MERGING:BRANCH:feat into TAG:v3.4.6"
208+ context := & detachedContext {
209+ tagName : "v3.4.6" ,
210+ merge : true ,
211+ mergeHEAD : "feat" ,
212+ }
213+ env := setupHEADContextEnv (context )
214+ g := & git {
215+ env : env ,
216+ }
217+ got := g .getGitHEADContext ("" )
218+ assert .Equal (t , want , got )
219+ }
220+
187221func TestGetStashContextZeroEntries (t * testing.T ) {
188222 want := ""
189223 env := new (MockedEnvironment )
0 commit comments