mirror of
				https://github.com/go-gitea/gitea
				synced 2025-10-31 11:28:24 +00:00 
			
		
		
		
	Backport #33298 by Zettat123 Fix #33265 Fix #33370 This PR also fixes some bugs in `TestGitGeneral`. --------- Co-authored-by: Zettat123 <zettat123@gmail.com> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
		| @@ -360,5 +360,5 @@ func Test_GetCommitBranchStart(t *testing.T) { | ||||
| 	startCommitID, err := repo.GetCommitBranchStart(os.Environ(), "branch1", commit.ID.String()) | ||||
| 	assert.NoError(t, err) | ||||
| 	assert.NotEmpty(t, startCommitID) | ||||
| 	assert.EqualValues(t, "9c9aef8dd84e02bc7ec12641deb4c930a7c30185", startCommitID) | ||||
| 	assert.EqualValues(t, "95bb4d39648ee7e325106df01a621c530863a653", startCommitID) | ||||
| } | ||||
|   | ||||
| @@ -519,6 +519,7 @@ func (repo *Repository) AddLastCommitCache(cacheKey, fullName, sha string) error | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| // GetCommitBranchStart returns the commit where the branch diverged | ||||
| func (repo *Repository) GetCommitBranchStart(env []string, branch, endCommitID string) (string, error) { | ||||
| 	cmd := NewCommand(repo.Ctx, "log", prettyLogFormat) | ||||
| 	cmd.AddDynamicArguments(endCommitID) | ||||
| @@ -533,7 +534,8 @@ func (repo *Repository) GetCommitBranchStart(env []string, branch, endCommitID s | ||||
|  | ||||
| 	parts := bytes.Split(bytes.TrimSpace(stdout), []byte{'\n'}) | ||||
|  | ||||
| 	var startCommitID string | ||||
| 	// check the commits one by one until we find a commit contained by another branch | ||||
| 	// and we think this commit is the divergence point | ||||
| 	for _, commitID := range parts { | ||||
| 		branches, err := repo.getBranches(env, string(commitID), 2) | ||||
| 		if err != nil { | ||||
| @@ -541,11 +543,9 @@ func (repo *Repository) GetCommitBranchStart(env []string, branch, endCommitID s | ||||
| 		} | ||||
| 		for _, b := range branches { | ||||
| 			if b != branch { | ||||
| 				return startCommitID, nil | ||||
| 				return string(commitID), nil | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		startCommitID = string(commitID) | ||||
| 	} | ||||
|  | ||||
| 	return "", nil | ||||
|   | ||||
		Reference in New Issue
	
	Block a user