entirely skip passing the --depth argument to git if the depth is configured to 0

fixes #7
This commit is contained in:
Massaki Archambault 2024-05-07 23:31:52 -04:00
parent 45cef75960
commit 38362eebdd
2 changed files with 18 additions and 7 deletions

View File

@ -64,14 +64,20 @@ func (c *gitClient) clone(url string, defaultBranch string, dst string) error {
}
} else {
// Clone the repo
_, err := utils.ExecProcess(
"git", "clone",
args := []string{
"clone",
"--origin", c.GitClientParam.Remote,
"--depth", strconv.Itoa(c.GitClientParam.Depth),
}
if c.GitClientParam.Depth != 0 {
args = append(args, "--depth", strconv.Itoa(c.GitClientParam.Depth))
}
args = append(args,
"--",
url, // repository
dst, // directory
)
_, err := utils.ExecProcess("git", args...)
if err != nil {
return fmt.Errorf("failed to clone git repo %v to %v: %v", url, dst, err)
}

View File

@ -20,14 +20,19 @@ func (c *gitClient) pull(repoPath string, defaultBranch string) error {
if branchName == defaultBranch {
// Pull the repo
_, err = utils.ExecProcessInDir(
repoPath, // workdir
"git", "pull",
"--depth", strconv.Itoa(c.GitClientParam.Depth),
args := []string{
"pull",
}
if c.GitClientParam.Depth != 0 {
args = append(args, "--depth", strconv.Itoa(c.GitClientParam.Depth))
}
args = append(args,
"--",
c.GitClientParam.Remote, // repository
defaultBranch, // refspec
)
_, err = utils.ExecProcessInDir(repoPath, "git", args...)
if err != nil {
return fmt.Errorf("failed to pull git repo %v: %v", repoPath, err)
}