Skip to content

Commit 70dc42c

Browse files
Mura Litypeless
Mura Li
authored andcommitted
Use referecen repo to avoid fetching objects
1 parent 3c6b43c commit 70dc42c

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

models/pull.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,23 @@ func (pr *PullRequest) Merge(doer *User, baseGitRepo *git.Repository, mergeStyle
408408
remoteRepoName := "head_repo"
409409

410410
// Add head repo remote.
411+
addCacheRepo := func(staging, cache string) error {
412+
p := filepath.Join(staging, ".git", "objects", "info", "alternates")
413+
f, err := os.OpenFile(p, os.O_APPEND|os.O_WRONLY, 0600)
414+
if err != nil {
415+
return err
416+
}
417+
defer f.Close()
418+
data := filepath.Join(cache, "objects")
419+
if _, err := fmt.Fprintln(f, data); err != nil {
420+
return err
421+
}
422+
return nil
423+
}
424+
425+
if err := addCacheRepo(tmpBasePath, headRepoPath); err != nil {
426+
return fmt.Errorf("addCacheRepo [%s -> %s]: %v", headRepoPath, tmpBasePath, err)
427+
}
411428
if _, stderr, err = process.GetManager().ExecDir(-1, tmpBasePath,
412429
fmt.Sprintf("PullRequest.Merge (git remote add): %s", tmpBasePath),
413430
"git", "remote", "add", remoteRepoName, headRepoPath); err != nil {

0 commit comments

Comments
 (0)