From 5902577c6d4c2694e197615b6fd5afc32440bd82 Mon Sep 17 00:00:00 2001 From: marcoSven Date: Tue, 16 Apr 2024 13:26:53 -0700 Subject: [PATCH] add tests and rename option Signed-off-by: marcoSven --- .gitmux.yml | 2 +- README.md | 4 +-- tmux/formater.go | 18 +++++----- tmux/formater_test.go | 82 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 94 insertions(+), 12 deletions(-) diff --git a/.gitmux.yml b/.gitmux.yml index 3f40e75..59aec0c 100644 --- a/.gitmux.yml +++ b/.gitmux.yml @@ -83,4 +83,4 @@ tmux: hide_clean: false # Swaps order of behind & ahead upstream counts - "↓·1↑·1" -> "↑·1↓·1" swap_divergence: false - space_between_divergence: false + divergence_space: false diff --git a/README.md b/README.md index b544718..3cbc840 100644 --- a/README.md +++ b/README.md @@ -133,7 +133,7 @@ tmux: ellipsis: … hide_clean: false swap_divergence: false - space_between_divergence: false + divergence_space: false ``` First, save the default configuration to a new file: @@ -272,7 +272,7 @@ This is the list of additional configuration `options`: | `ellipsis` | Character to show branch name has been truncated | `…` | | `hide_clean` | Hides the clean flag entirely | `false` | | `swap_divergence` | Swaps order of behind & ahead upstream counts | `false` | -| `space_between_divergence`| Add space between behind & ahead upstream counts | `false` | +| `divergence_space` | Add space between behind & ahead upstream counts | `false` | ## Troubleshooting diff --git a/tmux/formater.go b/tmux/formater.go index 6f2eec2..0708e19 100644 --- a/tmux/formater.go +++ b/tmux/formater.go @@ -85,12 +85,12 @@ func (d *direction) UnmarshalYAML(value *yaml.Node) error { } type options struct { - BranchMaxLen int `yaml:"branch_max_len"` - BranchTrim direction `yaml:"branch_trim"` - Ellipsis string `yaml:"ellipsis"` - HideClean bool `yaml:"hide_clean"` - SpaceBetweenDivergence bool `yaml:"space_between_divergence"` - SwapDivergence bool `yaml:"swap_divergence"` + BranchMaxLen int `yaml:"branch_max_len"` + BranchTrim direction `yaml:"branch_trim"` + Ellipsis string `yaml:"ellipsis"` + HideClean bool `yaml:"hide_clean"` + DivergenceSpace bool `yaml:"divergence_space"` + SwapDivergence bool `yaml:"swap_divergence"` } // A Formater formats git status to a tmux style string. @@ -246,12 +246,12 @@ func (f *Formater) divergence() string { behind := "" ahead := "" - space := "" + space := "" s := f.Styles.Clear + f.Styles.Divergence if f.st.BehindCount != 0 { - if f.Options.SpaceBetweenDivergence { - space = " " + if f.Options.DivergenceSpace { + space = " " } behind = fmt.Sprintf("%s%d", f.Symbols.Behind, f.st.BehindCount) } diff --git a/tmux/formater_test.go b/tmux/formater_test.go index b4dcc8d..dfaf475 100644 --- a/tmux/formater_test.go +++ b/tmux/formater_test.go @@ -181,6 +181,88 @@ func TestDivergence(t *testing.T) { }, want: "StyleClear" + "↑·128↓·41", }, + { + name: "space between behind only", + styles: styles{ + Clear: "StyleClear", + }, + symbols: symbols{ + Ahead: "↓·", + Behind: "↑·", + }, + options: options{ + DivergenceSpace: true, + }, + st: &gitstatus.Status{ + Porcelain: gitstatus.Porcelain{ + AheadCount: 0, + BehindCount: 12, + }, + }, + want: "StyleClear" + "↑·12", + }, + { + name: "space between diverged both way", + styles: styles{ + Clear: "StyleClear", + }, + symbols: symbols{ + Ahead: "↓·", + Behind: "↑·", + }, + options: options{ + DivergenceSpace: true, + SwapDivergence: false + }, + st: &gitstatus.Status{ + Porcelain: gitstatus.Porcelain{ + AheadCount: 41, + BehindCount: 128, + }, + }, + want: "StyleClear" + "↑·128 ↓·41", + }, + { + name: "space between swap divergence both ways", + styles: styles{ + Clear: "StyleClear", + }, + symbols: symbols{ + Ahead: "↓·", + Behind: "↑·", + }, + options: options{ + DivergenceSpace: true, + SwapDivergence: true, + }, + st: &gitstatus.Status{ + Porcelain: gitstatus.Porcelain{ + AheadCount: 41, + BehindCount: 128, + }, + }, + want: "StyleClear" + "↓·41 ↑·128", + }, + { + name: "no space between diverged both way", + styles: styles{ + Clear: "StyleClear", + }, + symbols: symbols{ + Ahead: "↓·", + Behind: "↑·", + }, + options: options{ + DivergenceSpace: false, + }, + st: &gitstatus.Status{ + Porcelain: gitstatus.Porcelain{ + AheadCount: 41, + BehindCount: 128, + }, + }, + want: "StyleClear" + "↑·128↓·41", + }, { name: "swap divergence ahead only", styles: styles{