Skip to content

Commit e588ab1

Browse files
committed
add tests and rename option
Signed-off-by: marcoSven <[email protected]>
1 parent 2f3dbab commit e588ab1

File tree

4 files changed

+94
-12
lines changed

4 files changed

+94
-12
lines changed

.gitmux.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,4 @@ tmux:
8383
hide_clean: false
8484
# Swaps order of behind & ahead upstream counts - "↓·1↑·1" -> "↑·1↓·1"
8585
swap_divergence: false
86-
space_between_divergence: false
86+
divergence_space: false

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ tmux:
133133
ellipsis:
134134
hide_clean: false
135135
swap_divergence: false
136-
space_between_divergence: false
136+
divergence_space: false
137137
```
138138
139139
First, save the default configuration to a new file:
@@ -272,7 +272,7 @@ This is the list of additional configuration `options`:
272272
| `ellipsis` | Character to show branch name has been truncated | `…` |
273273
| `hide_clean` | Hides the clean flag entirely | `false` |
274274
| `swap_divergence` | Swaps order of behind & ahead upstream counts | `false` |
275-
| `space_between_divergence`| Add space between behind & ahead upstream counts | `false` |
275+
| `divergence_space` | Add space between behind & ahead upstream counts | `false` |
276276

277277

278278
## Troubleshooting

tmux/formater.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,12 @@ func (d *direction) UnmarshalYAML(value *yaml.Node) error {
8585
}
8686

8787
type options struct {
88-
BranchMaxLen int `yaml:"branch_max_len"`
89-
BranchTrim direction `yaml:"branch_trim"`
90-
Ellipsis string `yaml:"ellipsis"`
91-
HideClean bool `yaml:"hide_clean"`
92-
SpaceBetweenDivergence bool `yaml:"space_between_divergence"`
93-
SwapDivergence bool `yaml:"swap_divergence"`
88+
BranchMaxLen int `yaml:"branch_max_len"`
89+
BranchTrim direction `yaml:"branch_trim"`
90+
Ellipsis string `yaml:"ellipsis"`
91+
HideClean bool `yaml:"hide_clean"`
92+
DivergenceSpace bool `yaml:"divergence_space"`
93+
SwapDivergence bool `yaml:"swap_divergence"`
9494
}
9595

9696
// A Formater formats git status to a tmux style string.
@@ -246,12 +246,12 @@ func (f *Formater) divergence() string {
246246

247247
behind := ""
248248
ahead := ""
249-
space := ""
249+
space := ""
250250

251251
s := f.Styles.Clear + f.Styles.Divergence
252252
if f.st.BehindCount != 0 {
253-
if f.Options.SpaceBetweenDivergence {
254-
space = " "
253+
if f.Options.DivergenceSpace {
254+
space = " "
255255
}
256256
behind = fmt.Sprintf("%s%d", f.Symbols.Behind, f.st.BehindCount)
257257
}

tmux/formater_test.go

+82
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,88 @@ func TestDivergence(t *testing.T) {
181181
},
182182
want: "StyleClear" + "↑·128↓·41",
183183
},
184+
{
185+
name: "space between behind only",
186+
styles: styles{
187+
Clear: "StyleClear",
188+
},
189+
symbols: symbols{
190+
Ahead: "↓·",
191+
Behind: "↑·",
192+
},
193+
options: options{
194+
DivergenceSpace: true,
195+
},
196+
st: &gitstatus.Status{
197+
Porcelain: gitstatus.Porcelain{
198+
AheadCount: 0,
199+
BehindCount: 12,
200+
},
201+
},
202+
want: "StyleClear" + "↑·12",
203+
},
204+
{
205+
name: "space between diverged both way",
206+
styles: styles{
207+
Clear: "StyleClear",
208+
},
209+
symbols: symbols{
210+
Ahead: "↓·",
211+
Behind: "↑·",
212+
},
213+
options: options{
214+
DivergenceSpace: true,
215+
SwapDivergence: false
216+
},
217+
st: &gitstatus.Status{
218+
Porcelain: gitstatus.Porcelain{
219+
AheadCount: 41,
220+
BehindCount: 128,
221+
},
222+
},
223+
want: "StyleClear" + "↑·128 ↓·41",
224+
},
225+
{
226+
name: "space between swap divergence both ways",
227+
styles: styles{
228+
Clear: "StyleClear",
229+
},
230+
symbols: symbols{
231+
Ahead: "↓·",
232+
Behind: "↑·",
233+
},
234+
options: options{
235+
DivergenceSpace: true,
236+
SwapDivergence: true,
237+
},
238+
st: &gitstatus.Status{
239+
Porcelain: gitstatus.Porcelain{
240+
AheadCount: 41,
241+
BehindCount: 128,
242+
},
243+
},
244+
want: "StyleClear" + "↓·41 ↑·128",
245+
}
246+
{
247+
name: "no space between diverged both way",
248+
styles: styles{
249+
Clear: "StyleClear",
250+
},
251+
symbols: symbols{
252+
Ahead: "↓·",
253+
Behind: "↑·",
254+
},
255+
options: options{
256+
DivergenceSpace: false,
257+
},
258+
st: &gitstatus.Status{
259+
Porcelain: gitstatus.Porcelain{
260+
AheadCount: 41,
261+
BehindCount: 128,
262+
},
263+
},
264+
want: "StyleClear" + "↑·128↓·41",
265+
},
184266
{
185267
name: "swap divergence ahead only",
186268
styles: styles{

0 commit comments

Comments
 (0)