aboutsummaryrefslogtreecommitdiffstats
path: root/config/branch.go
diff options
context:
space:
mode:
authorMike Riley <mriley@uber.com>2019-05-17 12:18:10 -0400
committerMike Riley <mikeriley@yelirekim.com>2019-05-17 12:33:55 -0400
commitf284cd4c2f97e3143e70e64cad4e6f490a6b49f1 (patch)
treed3984d80797aa1bd4d39ac168e66aacead508103 /config/branch.go
parent52fcf7d8a3c2da58769e105a26240e3e697fedeb (diff)
downloadgo-git-f284cd4c2f97e3143e70e64cad4e6f490a6b49f1.tar.gz
Support the 'rebase' config key for branches
Signed-off-by: Mike Riley <mikeriley@yelirekim.com>
Diffstat (limited to 'config/branch.go')
-rw-r--r--config/branch.go23
1 files changed, 21 insertions, 2 deletions
diff --git a/config/branch.go b/config/branch.go
index e18073c..af61bbb 100644
--- a/config/branch.go
+++ b/config/branch.go
@@ -8,8 +8,9 @@ import (
)
var (
- errBranchEmptyName = errors.New("branch config: empty name")
- errBranchInvalidMerge = errors.New("branch config: invalid merge")
+ errBranchEmptyName = errors.New("branch config: empty name")
+ errBranchInvalidMerge = errors.New("branch config: invalid merge")
+ errBranchInvalidRebase = errors.New("branch config: rebase must be one of 'true' or 'interactive'")
)
// Branch contains information on the
@@ -21,6 +22,10 @@ type Branch struct {
Remote string
// Merge is the local refspec for the branch
Merge plumbing.ReferenceName
+ // Rebase instead of merge when pulling. Valid values are
+ // "true" and "interactive". "false" is undocumented and
+ // typically represented by the non-existence of this field
+ Rebase string
raw *format.Subsection
}
@@ -35,6 +40,13 @@ func (b *Branch) Validate() error {
return errBranchInvalidMerge
}
+ if b.Rebase != "" &&
+ b.Rebase != "true" &&
+ b.Rebase != "interactive" &&
+ b.Rebase != "false" {
+ return errBranchInvalidRebase
+ }
+
return nil
}
@@ -57,6 +69,12 @@ func (b *Branch) marshal() *format.Subsection {
b.raw.SetOption(mergeKey, string(b.Merge))
}
+ if b.Rebase == "" {
+ b.raw.RemoveOption(rebaseKey)
+ } else {
+ b.raw.SetOption(rebaseKey, string(b.Rebase))
+ }
+
return b.raw
}
@@ -66,6 +84,7 @@ func (b *Branch) unmarshal(s *format.Subsection) error {
b.Name = b.raw.Name
b.Remote = b.raw.Options.Get(remoteSection)
b.Merge = plumbing.ReferenceName(b.raw.Options.Get(mergeKey))
+ b.Rebase = b.raw.Options.Get(rebaseKey)
return b.Validate()
}