Skip to content

Commit

Permalink
Fix unnecessary checkout
Browse files Browse the repository at this point in the history
  • Loading branch information
katainaka0503 committed Feb 21, 2022
1 parent 9bb0159 commit 41ba108
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
14 changes: 5 additions & 9 deletions pkg/argocd/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,6 @@ func commitChangesGit(app *v1alpha1.Application, wbc *WriteBackConfig, changeLis
}
}

err = gitC.Checkout(checkOutBranch)
if err != nil {
return err
}

// The push branch is by default the same as the checkout branch, unless
// specified after a : separator git-branch annotation, in which case a
// new branch will be made following a template that can use the list of
Expand All @@ -207,15 +202,16 @@ func commitChangesGit(app *v1alpha1.Application, wbc *WriteBackConfig, changeLis
if err != nil {
return err
}
err = gitC.Checkout(pushBranch)
if err != nil {
return err
}
} else {
return fmt.Errorf("Git branch name could not be created from the template: %s", wbc.GitWriteBranch)
}
}

err = gitC.Checkout(pushBranch)
if err != nil {
return err
}

if err, skip := write(app, wbc, gitC); err != nil {
return err
} else if skip {
Expand Down
5 changes: 1 addition & 4 deletions pkg/argocd/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1784,9 +1784,6 @@ func Test_CommitUpdates(t *testing.T) {
t.Run("Good commit to different than base branch", func(t *testing.T) {
gitMock, _, cleanup := mockGit(t)
defer cleanup()
gitMock.On("Checkout", mock.Anything).Run(func(args mock.Arguments) {
args.Assert(t, "mydefaultbranch")
}).Return(nil).Once()
gitMock.On("Add", mock.Anything).Return(nil)
gitMock.On("Branch", mock.Anything, mock.Anything).Return(nil)
gitMock.On("Commit", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil)
Expand All @@ -1806,7 +1803,7 @@ func Test_CommitUpdates(t *testing.T) {
NewTag: tag.NewImageTag("1.1", time.Now(), ""),
},
}
gitMock.On("Checkout", TemplateBranchName(wbc.GitWriteBranch, cl)).Return(nil).Once()
gitMock.On("Checkout", TemplateBranchName(wbc.GitWriteBranch, cl)).Return(nil)

err = commitChanges(&app, wbc, cl)
assert.NoError(t, err)
Expand Down

0 comments on commit 41ba108

Please sign in to comment.