Skip to content

Commit 377ff70

Browse files
committed
init: set up a better refspec
The previous 'git clone --mirror' approach also copied the 'refs/pull/*' ref namespace, which is very noisy for the bundle server. Instead, focus on the 'refs/heads/*' namespace and include only that during the bundling process.
1 parent 90fc20f commit 377ff70

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

cmd/git-bundle-server/init.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,22 @@ func (Init) run(args []string) error {
2929
}
3030

3131
fmt.Printf("Cloning repository from %s\n", url)
32-
gitErr := git.GitCommand("clone", "--mirror", url, repo.RepoDir)
32+
gitErr := git.GitCommand("clone", "--bare", url, repo.RepoDir)
3333

3434
if gitErr != nil {
3535
return fmt.Errorf("failed to clone repository: %w", gitErr)
3636
}
3737

38+
gitErr = git.GitCommand("-C", repo.RepoDir, "config", "remote.origin.fetch", "+refs/heads/*:refs/heads/*")
39+
if gitErr != nil {
40+
return fmt.Errorf("failed to configure refspec: %w", gitErr)
41+
}
42+
43+
gitErr = git.GitCommand("-C", repo.RepoDir, "fetch", "origin")
44+
if gitErr != nil {
45+
return fmt.Errorf("failed to fetch latest refs: %w", gitErr)
46+
}
47+
3848
bundle := bundles.CreateInitialBundle(repo)
3949
fmt.Printf("Constructing base bundle file at %s\n", bundle.Filename)
4050

internal/git/git.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func GitCommandWithStdin(stdinLines []string, args ...string) error {
7575
func CreateBundle(repoDir string, filename string) (bool, error) {
7676
err := GitCommand(
7777
"-C", repoDir, "bundle", "create",
78-
filename, "--all")
78+
filename, "--branches")
7979
if err != nil {
8080
if strings.Contains(err.Error(), "Refusing to create empty bundle") {
8181
return false, nil
@@ -112,7 +112,7 @@ func CreateBundleFromRefs(repoDir string, filename string, refs map[string]strin
112112
func CreateIncrementalBundle(repoDir string, filename string, prereqs []string) (bool, error) {
113113
err := GitCommandWithStdin(
114114
prereqs, "-C", repoDir, "bundle", "create",
115-
filename, "--stdin", "--all")
115+
filename, "--stdin", "--branches")
116116
if err != nil {
117117
if strings.Contains(err.Error(), "Refusing to create empty bundle") {
118118
return false, nil

0 commit comments

Comments
 (0)