diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2017-07-26 06:24:47 +0200 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2017-07-26 06:24:47 +0200 |
commit | 064051f972e90dd55e6c941f04b58b4a36dfedf1 (patch) | |
tree | c535025453602cfa561d3622c78dc37693f55c82 /worktree.go | |
parent | fbf2a4ab4588c78e3d9d0265dba774ae6b388b5f (diff) | |
download | go-git-064051f972e90dd55e6c941f04b58b4a36dfedf1.tar.gz |
*: package context support in Repository, Remote and Submodule
Diffstat (limited to 'worktree.go')
-rw-r--r-- | worktree.go | 18 |
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 { |