Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Commit 6a813e8

Browse files
committed
Support the 'rebase' config key for branches
Signed-off-by: Mike Riley <[email protected]>
1 parent 52fcf7d commit 6a813e8

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

config/branch.go

+21-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ import (
88
)
99

1010
var (
11-
errBranchEmptyName = errors.New("branch config: empty name")
12-
errBranchInvalidMerge = errors.New("branch config: invalid merge")
11+
errBranchEmptyName = errors.New("branch config: empty name")
12+
errBranchInvalidMerge = errors.New("branch config: invalid merge")
13+
errBranchInvalidRebase = errors.New("branch config: rebase must be one of 'true' or 'interactive'")
1314
)
1415

1516
// Branch contains information on the
@@ -21,6 +22,10 @@ type Branch struct {
2122
Remote string
2223
// Merge is the local refspec for the branch
2324
Merge plumbing.ReferenceName
25+
// Rebase instead of merge when pulling. Valid values are
26+
// "true" and "interactive". "false" is undocumented and
27+
// typically represented by the non-existence of this field
28+
Rebase string
2429

2530
raw *format.Subsection
2631
}
@@ -35,6 +40,13 @@ func (b *Branch) Validate() error {
3540
return errBranchInvalidMerge
3641
}
3742

43+
if b.Rebase != "" &&
44+
b.Rebase != "true" &&
45+
b.Rebase != "interactive" &&
46+
b.Rebase != "false" {
47+
return errBranchInvalidRebase
48+
}
49+
3850
return nil
3951
}
4052

@@ -57,6 +69,12 @@ func (b *Branch) marshal() *format.Subsection {
5769
b.raw.SetOption(mergeKey, string(b.Merge))
5870
}
5971

72+
if b.Rebase == "" {
73+
b.raw.RemoveOption(rebaseKey)
74+
} else {
75+
b.raw.SetOption(rebaseKey, string(b.Rebase))
76+
}
77+
6078
return b.raw
6179
}
6280

@@ -66,6 +84,7 @@ func (b *Branch) unmarshal(s *format.Subsection) error {
6684
b.Name = b.raw.Name
6785
b.Remote = b.raw.Options.Get(remoteSection)
6886
b.Merge = plumbing.ReferenceName(b.raw.Options.Get(mergeKey))
87+
b.Rebase = b.raw.Options.Get(rebaseKey)
6988

7089
return b.Validate()
7190
}

config/branch_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,15 @@ func (b *BranchSuite) TestMarshall(c *C) {
4444
[branch "branch-tracking-on-clone"]
4545
remote = fork
4646
merge = refs/heads/branch-tracking-on-clone
47+
rebase = interactive
4748
`)
4849

4950
cfg := NewConfig()
5051
cfg.Branches["branch-tracking-on-clone"] = &Branch{
5152
Name: "branch-tracking-on-clone",
5253
Remote: "fork",
5354
Merge: plumbing.ReferenceName("refs/heads/branch-tracking-on-clone"),
55+
Rebase: "interactive",
5456
}
5557

5658
actual, err := cfg.Marshal()

config/config.go

+1
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ const (
120120
commentCharKey = "commentChar"
121121
windowKey = "window"
122122
mergeKey = "merge"
123+
rebaseKey = "rebase"
123124

124125
// DefaultPackWindow holds the number of previous objects used to
125126
// generate deltas. The value 10 is the same used by git command.

0 commit comments

Comments
 (0)