aboutsummaryrefslogtreecommitdiffstats
path: root/worktree.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2017-07-24 13:34:40 +0200
committerMáximo Cuadros <mcuadros@gmail.com>2017-07-24 13:34:40 +0200
commit460a7278e6fff2d58300e1855ef8429fec374fa0 (patch)
tree1ad85aa138fb9e3d9e1eefc3b3de40f5f2e16265 /worktree.go
parent4ee12ab91dc23ef1f6f04a6326ead904f21baf7b (diff)
downloadgo-git-460a7278e6fff2d58300e1855ef8429fec374fa0.tar.gz
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 {