aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2019-05-20 00:16:19 +0200
committerGitHub <noreply@github.com>2019-05-20 00:16:19 +0200
commit91db86b5c1068539f3c64d536f8af80503234f41 (patch)
treee1f1745266b9512cfa7cb15200188bc38f19dedb
parent7bdcd80a8c4ff0dab240d603258ba60b28102683 (diff)
parentf284cd4c2f97e3143e70e64cad4e6f490a6b49f1 (diff)
downloadgo-git-91db86b5c1068539f3c64d536f8af80503234f41.tar.gz
Merge pull request #1154 from yelirekim/rebase_config
Support the 'rebase' config key for branches
-rw-r--r--config/branch.go23
-rw-r--r--config/branch_test.go4
-rw-r--r--config/config.go1
3 files changed, 26 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()
}
diff --git a/config/branch_test.go b/config/branch_test.go
index d74122e..2dbe888 100644
--- a/config/branch_test.go
+++ b/config/branch_test.go
@@ -44,6 +44,7 @@ func (b *BranchSuite) TestMarshall(c *C) {
[branch "branch-tracking-on-clone"]
remote = fork
merge = refs/heads/branch-tracking-on-clone
+ rebase = interactive
`)
cfg := NewConfig()
@@ -51,6 +52,7 @@ func (b *BranchSuite) TestMarshall(c *C) {
Name: "branch-tracking-on-clone",
Remote: "fork",
Merge: plumbing.ReferenceName("refs/heads/branch-tracking-on-clone"),
+ Rebase: "interactive",
}
actual, err := cfg.Marshal()
@@ -64,6 +66,7 @@ func (b *BranchSuite) TestUnmarshall(c *C) {
[branch "branch-tracking-on-clone"]
remote = fork
merge = refs/heads/branch-tracking-on-clone
+ rebase = interactive
`)
cfg := NewConfig()
@@ -73,4 +76,5 @@ func (b *BranchSuite) TestUnmarshall(c *C) {
c.Assert(branch.Name, Equals, "branch-tracking-on-clone")
c.Assert(branch.Remote, Equals, "fork")
c.Assert(branch.Merge, Equals, plumbing.ReferenceName("refs/heads/branch-tracking-on-clone"))
+ c.Assert(branch.Rebase, Equals, "interactive")
}
diff --git a/config/config.go b/config/config.go
index 2c3b8b9..ea614e9 100644
--- a/config/config.go
+++ b/config/config.go
@@ -120,6 +120,7 @@ const (
commentCharKey = "commentChar"
windowKey = "window"
mergeKey = "merge"
+ rebaseKey = "rebase"
// DefaultPackWindow holds the number of previous objects used to
// generate deltas. The value 10 is the same used by git command.