@@ -1086,10 +1086,19 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption)
10861086
10871087 ctx .Repo .PullRequest .SameRepo = isSameRepo
10881088 log .Trace ("Repo path: %q, base branch: %q, head branch: %q" , ctx .Repo .GitRepo .Path , baseBranch , headBranch )
1089+
10891090 // Check if base branch is valid.
1090- if ! ctx .Repo .GitRepo .IsBranchExist (baseBranch ) && ! ctx .Repo .GitRepo .IsTagExist (baseBranch ) {
1091- ctx .NotFound ("BaseNotExist" )
1092- return nil , nil , nil , "" , ""
1091+ baseIsCommit := ctx .Repo .GitRepo .IsCommitExist (baseBranch )
1092+ baseIsBranch := ctx .Repo .GitRepo .IsBranchExist (baseBranch )
1093+ baseIsTag := ctx .Repo .GitRepo .IsTagExist (baseBranch )
1094+ if ! baseIsCommit && ! baseIsBranch && ! baseIsTag {
1095+ // Check for short SHA usage
1096+ if baseCommit , _ := ctx .Repo .GitRepo .GetCommit (baseBranch ); baseCommit != nil {
1097+ baseBranch = baseCommit .ID .String ()
1098+ } else {
1099+ ctx .NotFound ("BaseNotExist" )
1100+ return nil , nil , nil , "" , ""
1101+ }
10931102 }
10941103
10951104 // Check if current user has fork of repository or in the same repository.
@@ -1162,13 +1171,34 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption)
11621171 }
11631172
11641173 // Check if head branch is valid.
1165- if ! headGitRepo .IsBranchExist (headBranch ) && ! headGitRepo .IsTagExist (headBranch ) {
1166- headGitRepo .Close ()
1167- ctx .NotFound ()
1168- return nil , nil , nil , "" , ""
1174+ headIsCommit := headGitRepo .IsBranchExist (headBranch )
1175+ headIsBranch := headGitRepo .IsTagExist (headBranch )
1176+ headIsTag := headGitRepo .IsCommitExist (baseBranch )
1177+ if ! headIsCommit && ! headIsBranch && ! headIsTag {
1178+ // Check if headBranch is short sha commit hash
1179+ if headCommit , _ := headGitRepo .GetCommit (headBranch ); headCommit != nil {
1180+ headBranch = headCommit .ID .String ()
1181+ } else {
1182+ headGitRepo .Close ()
1183+ ctx .NotFound ("IsRefExist" , nil )
1184+ return nil , nil , nil , "" , ""
1185+ }
1186+ }
1187+
1188+ baseBranchRef := baseBranch
1189+ if baseIsBranch {
1190+ baseBranchRef = git .BranchPrefix + baseBranch
1191+ } else if baseIsTag {
1192+ baseBranchRef = git .TagPrefix + baseBranch
1193+ }
1194+ headBranchRef := headBranch
1195+ if headIsBranch {
1196+ headBranchRef = headBranch
1197+ } else if headIsTag {
1198+ headBranchRef = headBranch
11691199 }
11701200
1171- compareInfo , err := headGitRepo .GetCompareInfo (repo_model .RepoPath (baseRepo .Owner .Name , baseRepo .Name ), baseBranch , headBranch , false , false )
1201+ compareInfo , err := headGitRepo .GetCompareInfo (repo_model .RepoPath (baseRepo .Owner .Name , baseRepo .Name ), baseBranchRef , headBranchRef , false , false )
11721202 if err != nil {
11731203 headGitRepo .Close ()
11741204 ctx .Error (http .StatusInternalServerError , "GetCompareInfo" , err )
0 commit comments