in shells/abstract.go [56:94]
func (b *AbstractShell) writeFetchCmd(w ShellWriter, build *common.Build, projectDir string, gitDir string) {
depth := build.GetGitDepth()
w.IfDirectory(gitDir)
if depth != "" {
w.Notice("Fetching changes for %s with git depth set to %s...", build.GitInfo.Ref, depth)
} else {
w.Notice("Fetching changes...")
}
w.Cd(projectDir)
w.Command("git", "config", "fetch.recurseSubmodules", "false")
// Remove .git/{index,shallow}.lock files from .git, which can fail the fetch command
// The file can be left if previous build was terminated during git operation
w.RmFile(".git/index.lock")
w.RmFile(".git/shallow.lock")
w.IfFile(".git/hooks/post-checkout")
w.RmFile(".git/hooks/post-checkout")
w.EndIf()
w.Command("git", "clean", "-ffdx")
w.Command("git", "reset", "--hard")
w.Command("git", "remote", "set-url", "origin", build.GitInfo.RepoURL)
if depth != "" {
var refspec string
if build.GitInfo.RefType == common.RefTypeTag {
refspec = "+refs/tags/" + build.GitInfo.Ref + ":refs/tags/" + build.GitInfo.Ref
} else {
refspec = "+refs/heads/" + build.GitInfo.Ref + ":refs/remotes/origin/" + build.GitInfo.Ref
}
w.Command("git", "fetch", "--depth", depth, "origin", "--prune", refspec)
} else {
w.Command("git", "fetch", "origin", "--prune", "+refs/heads/*:refs/remotes/origin/*", "+refs/tags/*:refs/tags/*")
}
w.Else()
b.writeCloneCmd(w, build, projectDir)
w.EndIf()
}