Skip to content

Commit

Permalink
Merge pull request eksctl-io#1226 from weaveworks/1219-set-cwd-in-git…
Browse files Browse the repository at this point in the history
…-commands

 Fix CloneRepoInPath() for relative directories
  • Loading branch information
2opremio committed Aug 29, 2019
2 parents 9de33e6 + 91c7606 commit 6a53a2e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
1 change: 0 additions & 1 deletion pkg/ctl/gitops/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ func doApplyGitops(cmd *cmdutils.Cmd, opts options) error {
gitClient := git.NewGitClient(context.Background(), git.ClientParams{
PrivateSSHKeyPath: opts.gitPrivateSSHKeyPath,
Timeout: git.DefaultGitTimeout,
Dir: usersRepoDir,
})

gitOps := gitops.Applier{
Expand Down
14 changes: 9 additions & 5 deletions pkg/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ type Client struct {
type ClientParams struct {
Timeout time.Duration
PrivateSSHKeyPath string
Dir string
}

// Options holds options for cloning a git repository
Expand Down Expand Up @@ -81,12 +80,17 @@ func (git *Client) CloneRepo(cloneDirPrefix string, branch string, gitURL string

// CloneRepoInPath clones a repo to the specified directory
func (git *Client) CloneRepoInPath(clonePath string, branch string, gitURL string) error {
git.dir = clonePath
if err := os.MkdirAll(git.dir, 0700); err != nil {
if err := os.MkdirAll(clonePath, 0700); err != nil {
return errors.Wrapf(err, "unable to create directory for cloning")
}
args := []string{"clone", "-b", branch, gitURL, git.dir}
return git.runGitCmd(args...)
args := []string{"clone", "-b", branch, gitURL, clonePath}
if err := git.runGitCmd(args...); err != nil {
return err
}
// Set the working directory only after the clone so that
// it doesn't create an undesirable nested directory
git.dir = clonePath
return nil
}

// Add performs can perform a `git add` operation on the given file paths
Expand Down
2 changes: 1 addition & 1 deletion pkg/git/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ var _ = Describe("GitClient", func() {

// It called clone
Expect(err).To(Not(HaveOccurred()))
Expect(fakeExecutor.Dir).To(Equal(tempCloneDir))
Expect(fakeExecutor.Dir).To(Equal(""))
Expect(fakeExecutor.Args).To(
Equal([]string{"clone", "-b", "my-branch", "git@example.com:test/example-repo.git", tempCloneDir}))

Expand Down

0 comments on commit 6a53a2e

Please sign in to comment.