aboutsummaryrefslogtreecommitdiffstats
path: root/options.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2017-07-19 13:59:56 +0200
committerGitHub <noreply@github.com>2017-07-19 13:59:56 +0200
commit9775f829d6fb8026a2d73af89896a8f2cc5f7c50 (patch)
treec5231e480e9714554cec99e356200429b9fcbab2 /options.go
parentbebcb4f19a002ed2845baa9fbd725ac25b2e742c (diff)
parent9afc47237c301ecee66619d1ef8ec286185cb070 (diff)
downloadgo-git-9775f829d6fb8026a2d73af89896a8f2cc5f7c50.tar.gz
Merge pull request #487 from mcuadros/checkout-create
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
}