Skip to content

Commit 6ca9c91

Browse files
committed
Git commands should be no-op in dry-run mode
1 parent d5b34b2 commit 6ca9c91

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

pkg/store/git/git.go

+14
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type Store struct {
2929
Author string
3030
Email string
3131
Msg string
32+
DryRun bool
3233
stopch chan struct{}
3334
donech chan struct{}
3435
}
@@ -42,6 +43,7 @@ func New(config *config.KfConfig) *Store {
4243
Author: "Katafygio", // XXX maybe this could be a cli option
4344
Email: "katafygio@localhost",
4445
Msg: "Kubernetes cluster change",
46+
DryRun: config.DryRun,
4547
}
4648
}
4749

@@ -83,6 +85,10 @@ func (s *Store) Stop() {
8385

8486
// Git wraps the git command
8587
func (s *Store) Git(args ...string) error {
88+
if s.DryRun {
89+
return nil
90+
}
91+
8692
ctx, cancel := context.WithTimeout(context.Background(), timeoutCommands)
8793
defer cancel()
8894

@@ -99,6 +105,10 @@ func (s *Store) Git(args ...string) error {
99105

100106
// Status tests the git status of a repository
101107
func (s *Store) Status() (changed bool, err error) {
108+
if s.DryRun {
109+
return false, nil
110+
}
111+
102112
ctx, cancel := context.WithTimeout(context.Background(), timeoutCommands)
103113
defer cancel()
104114

@@ -119,6 +129,10 @@ func (s *Store) Status() (changed bool, err error) {
119129

120130
// Clone does git clone, or git init (when there's no GiURL to clone from)
121131
func (s *Store) Clone() error {
132+
if s.DryRun {
133+
return nil
134+
}
135+
122136
err := os.MkdirAll(s.LocalDir, 0700)
123137
if err != nil {
124138
return fmt.Errorf("failed to created %s: %v", s.LocalDir, err)

0 commit comments

Comments
 (0)