aboutsummaryrefslogtreecommitdiffstats
path: root/options.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2017-07-18 21:41:34 +0200
committerMáximo Cuadros <mcuadros@gmail.com>2017-07-18 21:41:34 +0200
commit9afc47237c301ecee66619d1ef8ec286185cb070 (patch)
tree5b7d67f820b14db690edcc6f506df64aaf28b717 /options.go
parentd3c7400c39f86a4c59340c7a9cda8497186e00fc (diff)
downloadgo-git-9afc47237c301ecee66619d1ef8ec286185cb070.tar.gz
worktree: checkout, create branch
Diffstat (limited to 'options.go')
-rw-r--r--options.go17
1 files changed, 16 insertions, 1 deletions
diff --git a/options.go b/options.go
index bbfe244..67a4870 100644
--- a/options.go
+++ b/options.go
@@ -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
}