@@ -68,3 +68,34 @@ func TestToFromEqual(t *testing.T) {
6868 assert .Equal (t , 0 , len (commits ))
6969 assert .NoError (t , err )
7070}
71+
72+ func TestCommitsBetweenDetachedHead (t * testing.T ) {
73+ testGit , err := OpenGit ("./testdata/detached_head" )
74+ assert .NoError (t , err )
75+
76+ // Verify we're in detached HEAD state
77+ currentBranch , err := testGit .CurrentBranch ()
78+ assert .NoError (t , err )
79+ assert .Equal (t , "HEAD" , currentBranch .Name ())
80+
81+ // Get HEAD commit hash (second commit)
82+ headHash := currentBranch .Hash ()
83+
84+ // Get origin/master commit hash (third commit)
85+ masterHashStr , err := testGit .runGitCommand ("rev-parse" , "origin/master" )
86+ assert .NoError (t , err )
87+ masterHash , err := NewHash (masterHashStr )
88+ assert .NoError (t , err )
89+
90+ // CommitsBetween should work even in detached HEAD state
91+ // Get commits between HEAD (second commit) and origin/master (third commit)
92+ commits , err := testGit .CommitsBetween (masterHash , headHash )
93+
94+ assert .NoError (t , err )
95+ // Should have 1 commit (the third commit)
96+ assert .Equal (t , 1 , len (commits ))
97+
98+ commit , err := testGit .Commit (commits [0 ])
99+ assert .NoError (t , err )
100+ assert .Equal (t , "third commit\n " , commit .Message )
101+ }
0 commit comments