diff options
author | Calvin Behling <calvin.behling@gmail.com> | 2016-05-07 17:34:52 -0500 |
---|---|---|
committer | Calvin Behling <calvin.behling@gmail.com> | 2016-05-07 17:58:46 -0500 |
commit | 4cd57d7c5d2f05724c042d5bb8e83faf96638156 (patch) | |
tree | dc8dff2497fc3a4724aecff5a909f33b344347d2 /repository.go | |
parent | 36d14454b32eca89ac43d2934c50f3a1ae2e1d20 (diff) | |
download | go-git-4cd57d7c5d2f05724c042d5bb8e83faf96638156.tar.gz |
Fix PullDefault to not cause panics.
The `remote.upInfo` is not set until `Connect()` is called.
However, `repository.PullDefault()` requires that it exists when
it calls `remote.DefaultBranch()`. This can be solved by pushing
the default branch discovery into `repository.Pull()`.
The empty string "" is not a valid branch name, so by allowing
the empty string to mean 'default branch' in the `Pull()` function
we can allow `PullDefault()` to not need a `remote.Connect()` call
before calling `repository.Pull()`
Diffstat (limited to 'repository.go')
-rw-r--r-- | repository.go | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/repository.go b/repository.go index f4aa26d..87810a6 100644 --- a/repository.go +++ b/repository.go @@ -67,6 +67,10 @@ func (r *Repository) Pull(remoteName, branch string) (err error) { return err } + if branch == "" { + branch = remote.DefaultBranch() + } + ref, err := remote.Ref(branch) if err != nil { return err @@ -93,12 +97,7 @@ func (r *Repository) Pull(remoteName, branch string) (err error) { // PullDefault like Pull but retrieve the default branch from the default remote func (r *Repository) PullDefault() (err error) { - remote, ok := r.Remotes[DefaultRemoteName] - if !ok { - return fmt.Errorf("unable to find default remote %q", DefaultRemoteName) - } - - return r.Pull(DefaultRemoteName, remote.DefaultBranch()) + return r.Pull(DefaultRemoteName, "") } // Commit return the commit with the given hash |