aboutsummaryrefslogtreecommitdiffstats
path: root/worktree.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2017-07-24 13:39:19 +0200
committerGitHub <noreply@github.com>2017-07-24 13:39:19 +0200
commit25a0420bc0544f826e5517365e986d83bbb926c8 (patch)
tree1ad85aa138fb9e3d9e1eefc3b3de40f5f2e16265 /worktree.go
parent4ee12ab91dc23ef1f6f04a6326ead904f21baf7b (diff)
parent460a7278e6fff2d58300e1855ef8429fec374fa0 (diff)
downloadgo-git-25a0420bc0544f826e5517365e986d83bbb926c8.tar.gz
Merge pull request #499 from mcuadros/move-pull
move Repository.Pull to Worktree.Pull
Diffstat (limited to 'worktree.go')
-rw-r--r--worktree.go41
1 files changed, 41 insertions, 0 deletions
diff --git a/worktree.go b/worktree.go
index 13b2497..0c15d4c 100644
--- a/worktree.go
+++ b/worktree.go
@@ -32,6 +32,47 @@ type Worktree struct {
fs billy.Filesystem
}
+// Pull incorporates changes from a remote repository into the current branch.
+// Returns nil if the operation is successful, NoErrAlreadyUpToDate if there are
+// no changes to be fetched, or an error.
+func (w *Worktree) Pull(o *PullOptions) error {
+ if err := o.Validate(); err != nil {
+ return err
+ }
+
+ head, err := w.r.fetchAndUpdateReferences(&FetchOptions{
+ RemoteName: o.RemoteName,
+ Depth: o.Depth,
+ Auth: o.Auth,
+ Progress: o.Progress,
+ }, o.ReferenceName)
+ if err != nil {
+ return err
+ }
+
+ if err := w.Reset(&ResetOptions{Commit: head.Hash()}); err != nil {
+ return err
+ }
+
+ if o.RecurseSubmodules != NoRecurseSubmodules {
+ return w.updateSubmodules(o.RecurseSubmodules)
+ }
+
+ return nil
+}
+
+func (w *Worktree) updateSubmodules(recursion SubmoduleRescursivity) error {
+ s, err := w.Submodules()
+ if err != nil {
+ return err
+ }
+
+ return s.Update(&SubmoduleUpdateOptions{
+ Init: true,
+ RecurseSubmodules: recursion,
+ })
+}
+
// Checkout switch branches or restore working tree files.
func (w *Worktree) Checkout(opts *CheckoutOptions) error {
if err := opts.Validate(); err != nil {