@@ -460,6 +460,65 @@ func TestGitGetter_checkoutRefOptionInjectionRejected(t *testing.T) {
460460 }
461461}
462462
463+ func TestGitGetter_checkoutRefLocalBranchResolved (t * testing.T ) {
464+ if ! testHasGit {
465+ t .Skip ("git not found, skipping" )
466+ }
467+
468+ g := new (GitGetter )
469+ repo := testGitRepo (t , "local-branch-repo" )
470+ repo .git ("config" , "commit.gpgsign" , "false" )
471+ repo .commitFile ("base.txt" , "base" )
472+ repo .git ("checkout" , "-b" , "test-branch" )
473+ repo .commitFile ("branch.txt" , "branch" )
474+ wantCommit , err := repo .latestCommit ()
475+ if err != nil {
476+ t .Fatal (err )
477+ }
478+ repo .git ("checkout" , "HEAD~1" )
479+
480+ err = g .checkout (context .Background (), repo .dir , "test-branch" )
481+ if err != nil {
482+ t .Fatalf ("checkout failed: %s" , err )
483+ }
484+
485+ gotCommit , err := repo .latestCommit ()
486+ if err != nil {
487+ t .Fatal (err )
488+ }
489+ if gotCommit != wantCommit {
490+ t .Fatalf ("wrong commit checked out: got %s want %s" , gotCommit , wantCommit )
491+ }
492+ }
493+
494+ func TestGitGetter_checkoutRefHEADResolved (t * testing.T ) {
495+ if ! testHasGit {
496+ t .Skip ("git not found, skipping" )
497+ }
498+
499+ g := new (GitGetter )
500+ repo := testGitRepo (t , "head-repo" )
501+ repo .git ("config" , "commit.gpgsign" , "false" )
502+ repo .commitFile ("head.txt" , "head" )
503+ wantCommit , err := repo .latestCommit ()
504+ if err != nil {
505+ t .Fatal (err )
506+ }
507+
508+ err = g .checkout (context .Background (), repo .dir , "HEAD" )
509+ if err != nil {
510+ t .Fatalf ("checkout failed: %s" , err )
511+ }
512+
513+ gotCommit , err := repo .latestCommit ()
514+ if err != nil {
515+ t .Fatal (err )
516+ }
517+ if gotCommit != wantCommit {
518+ t .Fatalf ("wrong commit checked out: got %s want %s" , gotCommit , wantCommit )
519+ }
520+ }
521+
463522func TestGitGetter_checkoutRefShellMetacharactersRejected (t * testing.T ) {
464523 if ! testHasGit {
465524 t .Skip ("git not found, skipping" )
0 commit comments