diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2017-07-18 21:41:34 +0200 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2017-07-18 21:41:34 +0200 |
commit | 9afc47237c301ecee66619d1ef8ec286185cb070 (patch) | |
tree | 5b7d67f820b14db690edcc6f506df64aaf28b717 /options.go | |
parent | d3c7400c39f86a4c59340c7a9cda8497186e00fc (diff) | |
download | go-git-9afc47237c301ecee66619d1ef8ec286185cb070.tar.gz |
worktree: checkout, create branch
Diffstat (limited to 'options.go')
-rw-r--r-- | options.go | 17 |
1 files changed, 16 insertions, 1 deletions
@@ -194,13 +194,20 @@ type SubmoduleUpdateOptions struct { RecurseSubmodules SubmoduleRescursivity } +var ( + ErrBranchHashExclusive = errors.New("Branch and Hash are mutually exclusive") + ErrCreateRequiresBranch = errors.New("Branch is mandatory when Create is used") +) + // CheckoutOptions describes how a checkout 31operation should be performed. type CheckoutOptions struct { // Hash to be checked out, if used HEAD will in detached mode. Branch and - // Hash are mutual exclusive. + // Hash are mutually exclusive, if Create is not used. Hash plumbing.Hash // Branch to be checked out, if Branch and Hash are empty is set to `master`. Branch plumbing.ReferenceName + // Create a new branch named Branch and start it at Hash. + Create bool // Force, if true when switching branches, proceed even if the index or the // working tree differs from HEAD. This is used to throw away local changes Force bool @@ -208,6 +215,14 @@ type CheckoutOptions struct { // Validate validates the fields and sets the default values. func (o *CheckoutOptions) Validate() error { + if !o.Create && !o.Hash.IsZero() && o.Branch != "" { + return ErrBranchHashExclusive + } + + if o.Create && o.Branch == "" { + return ErrCreateRequiresBranch + } + if o.Branch == "" { o.Branch = plumbing.Master } |