Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetch instead of pull if the working tree isn't tracking remote. #286

Merged
merged 3 commits into from
Jun 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion vcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,15 @@ var GitBackend = &VCSBackend{
if _, err := os.Stat(filepath.Join(vg.dir, ".git/svn")); err == nil {
return GitsvnBackend.Update(vg)
}
err := runInDir(vg.silent)(vg.dir, "git", "pull", "--ff-only")
err := runInDir(true)(vg.dir, "git", "rev-parse", "@{upstream}")
if err != nil {
err := runInDir(vg.silent)(vg.dir, "git", "fetch")
if err != nil {
return err
}
return nil
}
err = runInDir(vg.silent)(vg.dir, "git", "pull", "--ff-only")
if err != nil {
return err
}
Expand Down
19 changes: 19 additions & 0 deletions vcs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,25 @@ func TestVCSBackend(t *testing.T) {
},
expect: []string{"git", "pull", "--ff-only"},
dir: localDir,
}, {
name: "[git] fetch",
f: func() error {
defer func(orig func(cmd *exec.Cmd) error) {
cmdutil.CommandRunner = orig
}(cmdutil.CommandRunner)
cmdutil.CommandRunner = func(cmd *exec.Cmd) error {
_commands = append(_commands, cmd)
if reflect.DeepEqual(cmd.Args, []string{"git", "rev-parse", "@{upstream}"}) {
return fmt.Errorf("[test] failed to git rev-parse @{upstream}")
}
return nil
}
return GitBackend.Update(&vcsGetOption{
dir: localDir,
})
},
expect: []string{"git", "fetch"},
dir: localDir,
}, {
name: "[git] recursive",
f: func() error {
Expand Down