summaryrefslogtreecommitdiff
path: root/ext/git/writer.go
diff options
context:
space:
mode:
Diffstat (limited to 'ext/git/writer.go')
-rw-r--r--ext/git/writer.go35
1 files changed, 35 insertions, 0 deletions
diff --git a/ext/git/writer.go b/ext/git/writer.go
index 8e6f0f2..d2d2f75 100644
--- a/ext/git/writer.go
+++ b/ext/git/writer.go
@@ -3,6 +3,7 @@ package git
import (
"fmt"
"os/exec"
+ "strconv"
"strings"
"github.com/argoproj-labs/argocd-image-updater/pkg/log"
@@ -159,3 +160,37 @@ func (m *nativeGitClient) runCredentialedCmdWithOutput(args ...string) (string,
cmd.Env = append(cmd.Env, environ...)
return m.runCmdOutput(cmd, runOpts{})
}
+
+func (m *nativeGitClient) shallowFetch(revision string, depth int) error {
+ var err error
+ if revision != "" {
+ err = m.runCredentialedCmd("fetch", "origin", revision, "--force", "--prune", "--depth", strconv.Itoa(depth))
+ } else {
+ err = m.runCredentialedCmd("fetch", "origin", "--force", "--prune", "--depth", strconv.Itoa(depth))
+ }
+ return err
+}
+
+// Fetch fetches latest updates from origin
+func (m *nativeGitClient) ShallowFetch(revision string, depth int) error {
+ if m.OnFetch != nil {
+ done := m.OnFetch(m.repoURL)
+ defer done()
+ }
+
+ err := m.shallowFetch(revision, depth)
+
+ // When we have LFS support enabled, check for large files and fetch them too.
+ // No shallow fetch is possible here
+ if err == nil && m.IsLFSEnabled() {
+ largeFiles, err := m.LsLargeFiles()
+ if err == nil && len(largeFiles) > 0 {
+ err = m.runCredentialedCmd("lfs", "fetch", "--all")
+ if err != nil {
+ return err
+ }
+ }
+ }
+
+ return err
+}