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 { } else {
// Clone the repo // Clone the repo
_, err := utils.ExecProcess( args := []string{
"git", "clone", "clone",
"--origin", c.GitClientParam.Remote, "--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 url, // repository
dst, // directory dst, // directory
) )
_, err := utils.ExecProcess("git", args...)
if err != nil { if err != nil {
return fmt.Errorf("failed to clone git repo %v to %v: %v", url, dst, err) 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 { if branchName == defaultBranch {
// Pull the repo // Pull the repo
_, err = utils.ExecProcessInDir( args := []string{
repoPath, // workdir "pull",
"git", "pull", }
"--depth", strconv.Itoa(c.GitClientParam.Depth), if c.GitClientParam.Depth != 0 {
args = append(args, "--depth", strconv.Itoa(c.GitClientParam.Depth))
}
args = append(args,
"--", "--",
c.GitClientParam.Remote, // repository c.GitClientParam.Remote, // repository
defaultBranch, // refspec defaultBranch, // refspec
) )
_, err = utils.ExecProcessInDir(repoPath, "git", args...)
if err != nil { if err != nil {
return fmt.Errorf("failed to pull git repo %v: %v", repoPath, err) return fmt.Errorf("failed to pull git repo %v: %v", repoPath, err)
} }