aboutsummaryrefslogtreecommitdiffstats
path: root/worktree.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2017-07-26 14:41:59 +0200
committerGitHub <noreply@github.com>2017-07-26 14:41:59 +0200
commite19163e22eb19b352dd022f6edc9d81e1cd7a7ed (patch)
treeca08a52fdb31bd90637cec71351578436f254b4b /worktree.go
parentd7b898ea3be0342f064ad63f93aaffdb6518a5b3 (diff)
parent064051f972e90dd55e6c941f04b58b4a36dfedf1 (diff)
downloadgo-git-e19163e22eb19b352dd022f6edc9d81e1cd7a7ed.tar.gz
Merge pull request #509 from mcuadros/ctx-main
*: package context support in Repository, Remote and Submodule
Diffstat (limited to 'worktree.go')
-rw-r--r--worktree.go18
1 files changed, 16 insertions, 2 deletions
diff --git a/worktree.go b/worktree.go
index 0c15d4c..5768888 100644
--- a/worktree.go
+++ b/worktree.go
@@ -1,6 +1,7 @@
package git
import (
+ "context"
"errors"
"fmt"
"io"
@@ -36,11 +37,22 @@ type Worktree struct {
// 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 {
+ return w.PullContext(context.Background(), o)
+}
+
+// PullContext 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.
+//
+// The provided Context must be non-nil. If the context expires before the
+// operation is complete, an error is returned. The context only affects to the
+// transport operations.
+func (w *Worktree) PullContext(ctx context.Context, o *PullOptions) error {
if err := o.Validate(); err != nil {
return err
}
- head, err := w.r.fetchAndUpdateReferences(&FetchOptions{
+ head, err := w.r.fetchAndUpdateReferences(ctx, &FetchOptions{
RemoteName: o.RemoteName,
Depth: o.Depth,
Auth: o.Auth,
@@ -334,7 +346,9 @@ func (w *Worktree) checkoutChangeSubmodule(name string,
return err
}
- return sub.update(&SubmoduleUpdateOptions{}, e.Hash)
+ // TODO: the submodule update should be reviewed as reported at:
+ // https://github.com/src-d/go-git/issues/415
+ return sub.update(context.TODO(), &SubmoduleUpdateOptions{}, e.Hash)
case merkletrie.Insert:
mode, err := e.Mode.ToOSFileMode()
if err != nil {