2020-12-31 02:18:18 +00:00
|
|
|
package git
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2021-03-03 04:43:38 +00:00
|
|
|
"strconv"
|
2020-12-31 02:18:18 +00:00
|
|
|
|
2021-03-03 04:43:38 +00:00
|
|
|
"github.com/badjware/gitlabfs/utils"
|
2020-12-31 02:18:18 +00:00
|
|
|
)
|
|
|
|
|
2022-03-03 22:47:36 +00:00
|
|
|
func (c *gitClient) pull(repoPath string, defaultBranch string) error {
|
2020-12-31 02:18:18 +00:00
|
|
|
// Check if the local repo is on default branch
|
2021-03-03 04:43:38 +00:00
|
|
|
branchName, err := utils.ExecProcessInDir(
|
2022-03-03 22:47:36 +00:00
|
|
|
repoPath, // workdir
|
2021-03-03 04:43:38 +00:00
|
|
|
"git", "branch",
|
|
|
|
"--show-current",
|
|
|
|
)
|
2020-12-31 02:18:18 +00:00
|
|
|
if err != nil {
|
2022-03-03 22:47:36 +00:00
|
|
|
return fmt.Errorf("failed to retrieve HEAD of git repo %v: %v", repoPath, err)
|
2020-12-31 02:18:18 +00:00
|
|
|
}
|
|
|
|
|
2022-03-03 22:47:36 +00:00
|
|
|
if branchName == defaultBranch {
|
2021-03-03 05:24:27 +00:00
|
|
|
// Pull the repo
|
2021-03-03 04:43:38 +00:00
|
|
|
_, err = utils.ExecProcessInDir(
|
2022-03-03 22:47:36 +00:00
|
|
|
repoPath, // workdir
|
2021-03-03 04:43:38 +00:00
|
|
|
"git", "pull",
|
2024-05-05 23:52:57 +00:00
|
|
|
"--depth", strconv.Itoa(c.GitClientParam.Depth),
|
2021-03-03 04:43:38 +00:00
|
|
|
"--",
|
2024-05-05 23:52:57 +00:00
|
|
|
c.GitClientParam.Remote, // repository
|
|
|
|
defaultBranch, // refspec
|
2021-03-03 04:43:38 +00:00
|
|
|
)
|
|
|
|
if err != nil {
|
2022-03-03 22:47:36 +00:00
|
|
|
return fmt.Errorf("failed to pull git repo %v: %v", repoPath, err)
|
2021-03-03 04:43:38 +00:00
|
|
|
}
|
|
|
|
} else {
|
2022-03-03 22:47:36 +00:00
|
|
|
fmt.Printf("%v != %v, skipping pull", branchName, defaultBranch)
|
2020-12-31 02:18:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|