summaryrefslogtreecommitdiffstats
path: root/pkg/commands
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2020-08-11 21:18:38 +1000
committerJesse Duffield <jessedduffield@gmail.com>2020-08-12 18:47:16 +1000
commitfcd5aea04e9799f8cf078b4fe4c6b242a8c9b474 (patch)
treed889d51ca64db12ea8044a39d356b7c197b553de /pkg/commands
parent1c0da2967c50d6c8992adddf7c94ad2a4e5451e2 (diff)
support multiple modes of git pull
Diffstat (limited to 'pkg/commands')
-rw-r--r--pkg/commands/git.go39
-rw-r--r--pkg/commands/git_test.go2
2 files changed, 33 insertions, 8 deletions
diff --git a/pkg/commands/git.go b/pkg/commands/git.go
index 819bcca6a..89c903cc5 100644
--- a/pkg/commands/git.go
+++ b/pkg/commands/git.go
@@ -369,11 +369,26 @@ func (c *GitCommand) RebaseBranch(branchName string) error {
return c.OSCommand.RunPreparedCommand(cmd)
}
+type FetchOptions struct {
+ PromptUserForCredential func(string) string
+ RemoteName string
+ BranchName string
+}
+
// Fetch fetch git repo
-func (c *GitCommand) Fetch(promptUserForCredential func(string) string, canPromptForCredential bool) error {
- return c.OSCommand.DetectUnamePass("git fetch", func(question string) string {
- if canPromptForCredential {
- return promptUserForCredential(question)
+func (c *GitCommand) Fetch(opts FetchOptions) error {
+ command := "git fetch"
+
+ if opts.RemoteName != "" {
+ command = fmt.Sprintf("%s %s", command, opts.RemoteName)
+ }
+ if opts.BranchName != "" {
+ command = fmt.Sprintf("%s %s", command, opts.BranchName)
+ }
+
+ return c.OSCommand.DetectUnamePass(command, func(question string) string {
+ if opts.PromptUserForCredential != nil {
+ return opts.PromptUserForCredential(question)
}
return "\n"
})
@@ -430,10 +445,20 @@ func (c *GitCommand) ListStash() (string, error) {
return c.OSCommand.RunCommandWithOutput("git stash list")
}
+type MergeOpts struct {
+ FastForwardOnly bool
+}
+
// Merge merge
-func (c *GitCommand) Merge(branchName string) error {
+func (c *GitCommand) Merge(branchName string, opts MergeOpts) error {
mergeArgs := c.Config.GetUserConfig().GetString("git.merging.args")
- return c.OSCommand.RunCommand("git merge --no-edit %s %s", mergeArgs, branchName)
+
+ command := fmt.Sprintf("git merge --no-edit %s %s", mergeArgs, branchName)
+ if opts.FastForwardOnly {
+ command = fmt.Sprintf("%s --ff-only", command)
+ }
+
+ return c.OSCommand.RunCommand(command)
}
// AbortMerge abort merge
@@ -487,7 +512,7 @@ func (c *GitCommand) AmendHead() (*exec.Cmd, error) {
// Pull pulls from repo
func (c *GitCommand) Pull(args string, promptUserForCredential func(string) string) error {
- return c.OSCommand.DetectUnamePass("git pull --no-edit "+args, promptUserForCredential)
+ return c.OSCommand.DetectUnamePass("git pull --no-edit --rebase ", promptUserForCredential)
}
// PullWithoutPasswordCheck assumes that the pull will not prompt the user for a password
diff --git a/pkg/commands/git_test.go b/pkg/commands/git_test.go
index 9b0ef5e11..a376e10bf 100644
--- a/pkg/commands/git_test.go
+++ b/pkg/commands/git_test.go
@@ -703,7 +703,7 @@ func TestGitCommandMerge(t *testing.T) {
return exec.Command("echo")
}
- assert.NoError(t, gitCmd.Merge("test"))
+ assert.NoError(t, gitCmd.Merge("test", MergeOpts{}))
}
// TestGitCommandUsingGpg is a function.