@@ -1403,45 +1403,45 @@ func resolveGitReference(ctx context.Context, githubClient *github.Client, owner
14031403
14041404 originalRef := ref // Keep original ref for clearer error messages down the line.
14051405
1406- if strings .HasPrefix (ref , "refs/" ) {
1407- // 2b) Already fully qualified. We will use it.
1408- } else if strings .HasPrefix (ref , "heads/" ) || strings .HasPrefix (ref , "tags/" ) {
1409- ref = "refs/" + ref // 2c) Partially qualified. Make it fully qualified.
1410- } else {
1411- // 2d) Short name. Try to resolve it as a branch or tag.
1412- _ , resp , err := githubClient .Git .GetRef (ctx , owner , repo , "refs/heads/" + ref )
1413-
1414- // try to resolve the ref as a branch first.
1415- if err == nil {
1416- ref = "refs/heads/" + ref // It's a branch.
1406+ // Only enter the resolution logic if the ref is NOT already fully qualified.
1407+ if ! strings .HasPrefix (ref , "refs/" ) {
1408+ if strings .HasPrefix (ref , "heads/" ) || strings .HasPrefix (ref , "tags/" ) {
1409+ // 2c) It's partially qualified. Make it fully qualified.
1410+ ref = "refs/" + ref
14171411 } else {
1418- // The branch lookup failed. Check if it was a 404 Not Found error.
1419- // If it was, we will try to resolve it as a tag.
1420- ghErr , isGhErr := err .(* github.ErrorResponse )
1421- if isGhErr && ghErr .Response .StatusCode == http .StatusNotFound {
1422- // The branch wasn't found, so try as a tag.
1423- _ , resp2 , err2 := githubClient .Git .GetRef (ctx , owner , repo , "refs/tags/" + ref )
1424- if err2 == nil {
1425- ref = "refs/tags/" + ref // It's a tag.
1426- } else {
1427- // The tag lookup also failed. Check if it was a 404 Not Found error.
1428- ghErr2 , isGhErr2 := err2 .(* github.ErrorResponse )
1429- if isGhErr2 && ghErr2 .Response .StatusCode == http .StatusNotFound {
1430- return nil , fmt .Errorf ("could not resolve ref %q as a branch or a tag" , originalRef )
1412+ // 2d) It's a short name; try to resolve it as a branch or tag.
1413+ _ , resp , err := githubClient .Git .GetRef (ctx , owner , repo , "refs/heads/" + ref )
1414+
1415+ if err == nil {
1416+ ref = "refs/heads/" + ref // It's a branch.
1417+ } else {
1418+ // The branch lookup failed. Check if it was a 404 Not Found error.
1419+ ghErr , isGhErr := err .(* github.ErrorResponse )
1420+ if isGhErr && ghErr .Response .StatusCode == http .StatusNotFound {
1421+ // The branch wasn't found, so try as a tag.
1422+ _ , resp2 , err2 := githubClient .Git .GetRef (ctx , owner , repo , "refs/tags/" + ref )
1423+ if err2 == nil {
1424+ ref = "refs/tags/" + ref // It's a tag.
1425+ } else {
1426+ // The tag lookup failed. Check if it was a 404 Not Found error.
1427+ ghErr2 , isGhErr2 := err2 .(* github.ErrorResponse )
1428+ if isGhErr2 && ghErr2 .Response .StatusCode == http .StatusNotFound {
1429+ return nil , fmt .Errorf ("could not resolve ref %q as a branch or a tag" , originalRef )
1430+ }
1431+ // The tag lookup failed for a different reason.
1432+ _ , _ = ghErrors .NewGitHubAPIErrorToCtx (ctx , "failed to get reference (tag)" , resp2 , err2 )
1433+ return nil , fmt .Errorf ("failed to get reference for tag '%s': %w" , originalRef , err2 )
14311434 }
1432- // The tag lookup failed for a different reason.
1433- _ , _ = ghErrors .NewGitHubAPIErrorToCtx (ctx , "failed to get reference (tag)" , resp2 , err2 )
1434- return nil , fmt .Errorf ("failed to get reference for tag '%s': %w" , originalRef , err2 )
1435+ } else {
1436+ // The branch lookup failed for a different reason.
1437+ _ , _ = ghErrors .NewGitHubAPIErrorToCtx (ctx , "failed to get reference (branch)" , resp , err )
1438+ return nil , fmt .Errorf ("failed to get reference for branch '%s': %w" , originalRef , err )
14351439 }
1436- } else {
1437- // The branch lookup failed for a different reason.
1438- _ , _ = ghErrors .NewGitHubAPIErrorToCtx (ctx , "failed to get reference (branch)" , resp , err )
1439- return nil , fmt .Errorf ("failed to get reference for branch '%s': %w" , originalRef , err )
14401440 }
14411441 }
14421442 }
14431443
1444- // Now that 'ref' is a valid, fully-qualified name , we get the definitive reference object.
1444+ // Now that 'ref' is fully qualified , we get the definitive reference object.
14451445 reference , resp , err := githubClient .Git .GetRef (ctx , owner , repo , ref )
14461446 if err != nil {
14471447 _ , _ = ghErrors .NewGitHubAPIErrorToCtx (ctx , "failed to get final reference" , resp , err )
0 commit comments