in shells/abstract.go [625:688]
func (b *AbstractShell) writeRefspecFetchCmd(w ShellWriter, info common.ShellScriptInfo, templateDir, credConfigFile string) error {
build := info.Build
projectDir := build.FullProjectDir()
depth := build.GitInfo.Depth
if depth > 0 {
w.Noticef("Fetching changes with git depth set to %d...", depth)
} else {
w.Noticef("Fetching changes...")
}
objectFormat := build.GetRepositoryObjectFormat()
b.writeGitCleanup(w, build)
if objectFormat != common.DefaultObjectFormat {
w.Command("git", "init", projectDir, "--template", templateDir, "--object-format", objectFormat)
} else {
w.Command("git", "init", projectDir, "--template", templateDir)
}
w.Cd(projectDir)
remoteURL, err := build.GetRemoteURL()
if err != nil {
return fmt.Errorf("writing fetch commands: %w", err)
}
if credConfigFile != "" {
w.Command("git", "config", "include.path", credConfigFile)
}
// Add `git remote` or update existing
w.IfCmd("git", "remote", "add", "origin", remoteURL)
w.Noticef("Created fresh repository.")
w.Else()
w.Command("git", "remote", "set-url", "origin", remoteURL)
w.EndIf()
v := common.AppVersion
userAgent := fmt.Sprintf("http.userAgent=%s %s %s/%s", v.Name, v.Version, v.OS, v.Architecture)
fetchArgs := []string{"-c", userAgent, "fetch", "origin", "--no-recurse-submodules"}
fetchArgs = append(fetchArgs, build.GitInfo.Refspecs...)
if depth > 0 {
fetchArgs = append(fetchArgs, "--depth", strconv.Itoa(depth))
}
fetchArgs = append(fetchArgs, build.GetGitFetchFlags()...) //nolint:gocritic
if depth <= 0 {
fetchUnshallowArgs := append(fetchArgs, "--unshallow") //nolint:gocritic
w.IfFile(".git/shallow")
w.Command("git", fetchUnshallowArgs...)
w.Else()
w.Command("git", fetchArgs...)
w.EndIf()
} else {
w.Command("git", fetchArgs...)
}
return nil
}