@@ -653,46 +653,51 @@ func viewPullFiles(ctx *context.Context, beforeCommitID, afterCommitID string) {
653653 return
654654 }
655655
656- ctx .Data ["IsShowingOnlySingleCommit" ] = beforeCommitID != "" && beforeCommitID == afterCommitID
656+ isSingleCommit := beforeCommitID == "" && afterCommitID != ""
657+ ctx .Data ["IsShowingOnlySingleCommit" ] = isSingleCommit
657658 isShowAllCommits := (beforeCommitID == "" || beforeCommitID == prInfo .MergeBase ) && (afterCommitID == "" || afterCommitID == headCommitID )
658659 ctx .Data ["IsShowingAllCommits" ] = isShowAllCommits
659660
660- if beforeCommitID == "" {
661- beforeCommitID = prInfo .MergeBase
661+ var beforeCommit , afterCommit * git.Commit
662+ if ! isSingleCommit {
663+ if beforeCommitID == "" || beforeCommitID == prInfo .MergeBase {
664+ beforeCommitID = prInfo .MergeBase
665+ // mergebase commit is not in the list of the pull request commits
666+ beforeCommit , err = gitRepo .GetCommit (beforeCommitID )
667+ if err != nil {
668+ ctx .ServerError ("GetCommit" , err )
669+ return
670+ }
671+ } else {
672+ beforeCommit = indexCommit (prInfo .Commits , beforeCommitID )
673+ if beforeCommit == nil {
674+ ctx .HTTPError (http .StatusBadRequest , "before commit not found in PR commits" )
675+ return
676+ }
677+ }
662678 }
663- if afterCommitID == "" {
679+
680+ if afterCommitID == "" || afterCommitID == headCommitID {
664681 afterCommitID = headCommitID
665682 }
683+ afterCommit = indexCommit (prInfo .Commits , afterCommitID )
684+ if afterCommit == nil {
685+ ctx .HTTPError (http .StatusBadRequest , "after commit not found in PR commits" )
686+ return
687+ }
666688
667- var beforeCommit , afterCommit * git.Commit
668- if beforeCommitID != prInfo .MergeBase {
669- beforeCommit = indexCommit (prInfo .Commits , beforeCommitID )
670- if beforeCommit == nil {
671- ctx .NotFound (errors .New ("before commit not found in PR commits" ))
672- return
673- }
674- beforeCommit , err = beforeCommit .Parent (0 )
689+ if isSingleCommit {
690+ beforeCommit , err = afterCommit .Parent (0 )
675691 if err != nil {
676692 ctx .ServerError ("GetParentCommit" , err )
677693 return
678694 }
679695 beforeCommitID = beforeCommit .ID .String ()
680- } else { // mergebase commit is not in the list of the pull request commits
681- beforeCommit , err = gitRepo .GetCommit (beforeCommitID )
682- if err != nil {
683- ctx .ServerError ("GetCommit" , err )
684- return
685- }
686- }
687-
688- afterCommit = indexCommit (prInfo .Commits , afterCommitID )
689- if afterCommit == nil {
690- ctx .NotFound (errors .New ("after commit not found in PR commits" ))
691- return
692696 }
693697
694698 ctx .Data ["Username" ] = ctx .Repo .Owner .Name
695699 ctx .Data ["Reponame" ] = ctx .Repo .Repository .Name
700+ ctx .Data ["MergeBase" ] = prInfo .MergeBase
696701 ctx .Data ["AfterCommitID" ] = afterCommitID
697702 ctx .Data ["BeforeCommitID" ] = beforeCommitID
698703
@@ -883,7 +888,9 @@ func viewPullFiles(ctx *context.Context, beforeCommitID, afterCommitID string) {
883888}
884889
885890func ViewPullFilesForSingleCommit (ctx * context.Context ) {
886- viewPullFiles (ctx , ctx .PathParam ("sha" ), ctx .PathParam ("sha" ))
891+ // it doesn't support showing files from mergebase to the special commit
892+ // otherwise it will be ambiguous
893+ viewPullFiles (ctx , "" , ctx .PathParam ("sha" ))
887894}
888895
889896func ViewPullFilesForRange (ctx * context.Context ) {
0 commit comments