Skip to content

Commit

Permalink
Use git worktree and partial clone to reduce network io
Browse files Browse the repository at this point in the history
Signed-off-by: Shinnosuke Sawada-Dazai <shin@warashi.dev>
  • Loading branch information
Warashi committed Dec 12, 2024
1 parent 8f23da4 commit e6a8296
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions pkg/git/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func (c *client) Clone(ctx context.Context, repoID, remote, branch, destination
return nil, err
}
out, err := retryCommand(3, time.Second, logger, func() ([]byte, error) {
args := []string{"clone", "--mirror", remote, repoCachePath}
args := []string{"clone", "--mirror", "--filter=blob:none", remote, repoCachePath}
args = append(authArgs, args...)
return runGitCommand(ctx, c.gitPath, "", c.envsForRepo(remote), args...)
})
Expand Down Expand Up @@ -214,11 +214,12 @@ func (c *client) Clone(ctx context.Context, repoID, remote, branch, destination
}
}

args := []string{"clone"}
// git worktree add [-f] [--detach] [--checkout] [--lock [--reason <string>]]
// [--orphan] [(-b | -B) <new-branch>] <path> [<commit-ish>]
args := []string{"-C", repoCachePath, "worktree", "add", "--detach", destination}
if branch != "" {
args = append(args, "-b", branch)
args = append(args, branch)
}
args = append(args, repoCachePath, destination)

logger.Info("cloning a repo from cached one in local",
zap.String("src", repoCachePath),
Expand Down

0 comments on commit e6a8296

Please sign in to comment.