clean up logging of git runs
This commit is contained in:
parent
cd1f719e8b
commit
75998b9237
31
main.go
31
main.go
|
|
@ -194,22 +194,20 @@ func updateSymlink(gitRoot, link, newDir string) error {
|
||||||
// addWorktreeAndSwap creates a new worktree and calls updateSymlink to swap the symlink to point to the new worktree
|
// addWorktreeAndSwap creates a new worktree and calls updateSymlink to swap the symlink to point to the new worktree
|
||||||
func addWorktreeAndSwap(gitRoot, dest, branch, rev string) error {
|
func addWorktreeAndSwap(gitRoot, dest, branch, rev string) error {
|
||||||
// fetch branch
|
// fetch branch
|
||||||
output, err := runCommand(gitRoot, "git", "fetch", "origin", branch)
|
_, err := runCommand(gitRoot, "git", "fetch", "origin", branch)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
log.Printf("fetched origin/%s", branch)
|
||||||
log.Printf("fetch %q: %s", branch, output)
|
|
||||||
|
|
||||||
// add worktree in subdir
|
// add worktree in subdir
|
||||||
rand.Seed(time.Now().UnixNano())
|
rand.Seed(time.Now().UnixNano())
|
||||||
worktreePath := path.Join(gitRoot, "rev-"+strconv.Itoa(rand.Int()))
|
worktreePath := path.Join(gitRoot, "rev-"+strconv.Itoa(rand.Int()))
|
||||||
output, err = runCommand(gitRoot, "git", "worktree", "add", worktreePath, "origin/"+branch)
|
_, err = runCommand(gitRoot, "git", "worktree", "add", worktreePath, "origin/"+branch)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
log.Printf("added worktree %s for origin/%s", worktreePath, branch)
|
||||||
log.Printf("add worktree origin/%q: %v", branch, output)
|
|
||||||
|
|
||||||
// .git file in worktree directory holds a reference to /git/.git/worktrees/<worktree-dir-name>
|
// .git file in worktree directory holds a reference to /git/.git/worktrees/<worktree-dir-name>
|
||||||
// Replace it with a reference using relative paths, so that other containers can use a different volume mount name
|
// Replace it with a reference using relative paths, so that other containers can use a different volume mount name
|
||||||
|
|
@ -223,12 +221,11 @@ func addWorktreeAndSwap(gitRoot, dest, branch, rev string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// reset working copy
|
// reset working copy
|
||||||
output, err = runCommand(worktreePath, "git", "reset", "--hard", rev)
|
_, err = runCommand(worktreePath, "git", "reset", "--hard", rev)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
log.Printf("reset worktree %s to %s", worktreePath, rev)
|
||||||
log.Printf("reset %q: %v", rev, output)
|
|
||||||
|
|
||||||
if *flChmod != 0 {
|
if *flChmod != 0 {
|
||||||
// set file permissions
|
// set file permissions
|
||||||
|
|
@ -241,21 +238,17 @@ func addWorktreeAndSwap(gitRoot, dest, branch, rev string) error {
|
||||||
return updateSymlink(gitRoot, dest, worktreePath)
|
return updateSymlink(gitRoot, dest, worktreePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
func initRepo(repo, branch, rev string, depth int, gitRoot string) error {
|
func cloneRepo(repo, branch, rev string, depth int, gitRoot string) error {
|
||||||
// clone repo
|
|
||||||
args := []string{"clone", "--no-checkout", "-b", branch}
|
args := []string{"clone", "--no-checkout", "-b", branch}
|
||||||
if depth != 0 {
|
if depth != 0 {
|
||||||
args = append(args, "-depth")
|
args = append(args, "-depth", strconv.Itoa(depth))
|
||||||
args = append(args, string(depth))
|
|
||||||
}
|
}
|
||||||
args = append(args, repo)
|
args = append(args, repo, gitRoot)
|
||||||
args = append(args, gitRoot)
|
_, err := runCommand("", "git", args...)
|
||||||
output, err := runCommand("", "git", args...)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
log.Printf("cloned %s", repo)
|
||||||
log.Printf("clone %q: %s", repo, output)
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -267,7 +260,7 @@ func syncRepo(repo, branch, rev string, depth int, gitRoot, dest string) error {
|
||||||
_, err := os.Stat(gitRepoPath)
|
_, err := os.Stat(gitRepoPath)
|
||||||
switch {
|
switch {
|
||||||
case os.IsNotExist(err):
|
case os.IsNotExist(err):
|
||||||
err = initRepo(repo, branch, rev, depth, gitRoot)
|
err = cloneRepo(repo, branch, rev, depth, gitRoot)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue