mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-31 11:35:03 +01:00 
			
		
		
		
	Prevent server 500 on compare branches with no common history (#6555)
* Prevent 500 if there is no common mergebase * Prevent creation of PR with no history
This commit is contained in:
		
							parent
							
								
									7350e439bf
								
							
						
					
					
						commit
						89cc7c646d
					
				| @ -48,17 +48,22 @@ func (repo *Repository) GetPullRequestInfo(basePath, baseBranch, headBranch stri | |||||||
| 
 | 
 | ||||||
| 	prInfo := new(PullRequestInfo) | 	prInfo := new(PullRequestInfo) | ||||||
| 	prInfo.MergeBase, err = repo.GetMergeBase(remoteBranch, headBranch) | 	prInfo.MergeBase, err = repo.GetMergeBase(remoteBranch, headBranch) | ||||||
| 	if err != nil { | 	if err == nil { | ||||||
| 		return nil, fmt.Errorf("GetMergeBase: %v", err) | 		// We have a common base | ||||||
| 	} | 		logs, err := NewCommand("log", prInfo.MergeBase+"..."+headBranch, prettyLogFormat).RunInDirBytes(repo.Path) | ||||||
| 
 | 		if err != nil { | ||||||
| 	logs, err := NewCommand("log", prInfo.MergeBase+"..."+headBranch, prettyLogFormat).RunInDirBytes(repo.Path) | 			return nil, err | ||||||
| 	if err != nil { | 		} | ||||||
| 		return nil, err | 		prInfo.Commits, err = repo.parsePrettyFormatLogToList(logs) | ||||||
| 	} | 		if err != nil { | ||||||
| 	prInfo.Commits, err = repo.parsePrettyFormatLogToList(logs) | 			return nil, fmt.Errorf("parsePrettyFormatLogToList: %v", err) | ||||||
| 	if err != nil { | 		} | ||||||
| 		return nil, fmt.Errorf("parsePrettyFormatLogToList: %v", err) | 	} else { | ||||||
|  | 		prInfo.Commits = list.New() | ||||||
|  | 		prInfo.MergeBase, err = GetFullCommitID(repo.Path, remoteBranch) | ||||||
|  | 		if err != nil { | ||||||
|  | 			prInfo.MergeBase = remoteBranch | ||||||
|  | 		} | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	// Count number of changed files. | 	// Count number of changed files. | ||||||
|  | |||||||
| @ -684,6 +684,7 @@ editor.cannot_commit_to_protected_branch = Cannot commit to protected branch '%s | |||||||
| 
 | 
 | ||||||
| commits.desc = Browse source code change history. | commits.desc = Browse source code change history. | ||||||
| commits.commits = Commits | commits.commits = Commits | ||||||
|  | commits.no_commits = No commits in common. '%s' and '%s' have entirely different histories. | ||||||
| commits.search = Search commits… | commits.search = Search commits… | ||||||
| commits.find = Search | commits.find = Search | ||||||
| commits.search_all = All Branches | commits.search_all = All Branches | ||||||
|  | |||||||
| @ -1,9 +1,13 @@ | |||||||
| <h4 class="ui top attached header"> | <h4 class="ui top attached header"> | ||||||
| 	<div class="ui stackable grid"> | 	<div class="ui stackable grid"> | ||||||
| 		<div class="six wide column"> | 		<div class="ten wide column"> | ||||||
| 			{{.CommitCount}} {{.i18n.Tr "repo.commits.commits"}} {{if .Branch}}({{.Branch}}){{end}} | 			{{if or .PageIsCommits (gt .CommitCount 0)}} | ||||||
|  | 				{{.CommitCount}} {{.i18n.Tr "repo.commits.commits"}} {{if .Branch}}({{.Branch}}){{end}} | ||||||
|  | 			{{else}} | ||||||
|  | 				{{.i18n.Tr "repo.commits.no_commits" $.BaseBranch $.HeadBranch }} {{if .Branch}}({{.Branch}}){{end}} | ||||||
|  | 			{{end}} | ||||||
| 		</div> | 		</div> | ||||||
| 		<div class="ten wide right aligned column"> | 		<div class="six wide right aligned column"> | ||||||
| 			{{if .PageIsCommits}} | 			{{if .PageIsCommits}} | ||||||
| 				<form class="ignore-dirty" action="{{.RepoLink}}/commits/{{.BranchNameSubURL | EscapePound}}/search"> | 				<form class="ignore-dirty" action="{{.RepoLink}}/commits/{{.BranchNameSubURL | EscapePound}}/search"> | ||||||
| 					<div class="ui tiny search input"> | 					<div class="ui tiny search input"> | ||||||
| @ -23,7 +27,7 @@ | |||||||
| 	</div> | 	</div> | ||||||
| </h4> | </h4> | ||||||
| 
 | 
 | ||||||
| {{if .Commits}} | {{if and .Commits (gt .CommitCount 0)}} | ||||||
| 	<div class="ui attached table segment"> | 	<div class="ui attached table segment"> | ||||||
| 		<table class="ui very basic striped fixed table single line" id="commits-table"> | 		<table class="ui very basic striped fixed table single line" id="commits-table"> | ||||||
| 			<thead> | 			<thead> | ||||||
|  | |||||||
| @ -54,6 +54,9 @@ | |||||||
| 				<div class="ui segment"> | 				<div class="ui segment"> | ||||||
| 					{{.i18n.Tr "repo.pulls.has_pull_request" $.RepoLink $.RepoRelPath .PullRequest.Index | Safe}} | 					{{.i18n.Tr "repo.pulls.has_pull_request" $.RepoLink $.RepoRelPath .PullRequest.Index | Safe}} | ||||||
| 				</div> | 				</div> | ||||||
|  | 			{{else if eq .CommitCount 0 }} | ||||||
|  | 				{{template "repo/commits_table" .}} | ||||||
|  | 				{{template "repo/diff/box" .}} | ||||||
| 			{{else}} | 			{{else}} | ||||||
| 				{{template "repo/issue/new_form" .}} | 				{{template "repo/issue/new_form" .}} | ||||||
| 				{{template "repo/commits_table" .}} | 				{{template "repo/commits_table" .}} | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user