From 06654727b553085b77987919e24ea8990bf8cba7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Rainone?= <476650+arl@users.noreply.github.com> Date: Wed, 2 Sep 2020 02:37:38 +0200 Subject: [PATCH] Issue 32/branch format (#38) * format/tmux: add failing test for issue 32 As exposed in the added failing test, reproducing the issue 32, the branch style only affect the branch symbol whereas it should affect both affect the symbol and the branch name. * format/tmux: branch style now affects both branch symbol+name Fixes #32 * Fix tests and adapt for new behavior --- format/tmux/formater.go | 4 ++-- format/tmux/formater_test.go | 23 ++++++++++++++++++++--- testdata/default.output.golden | 2 +- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/format/tmux/formater.go b/format/tmux/formater.go index a01eb98..ac92b50 100644 --- a/format/tmux/formater.go +++ b/format/tmux/formater.go @@ -240,12 +240,12 @@ func (f *Formater) currentRef() { f.clear() if f.st.IsDetached { - fmt.Fprintf(&f.b, "%s%s", f.Symbols.HashPrefix, f.st.HEAD) + fmt.Fprintf(&f.b, "%s%s%s", f.Styles.Branch, f.Symbols.HashPrefix, f.st.HEAD) return } - fmt.Fprintf(&f.b, "%s", + fmt.Fprintf(&f.b, "%s%s", f.Styles.Branch, truncateBranchName(f.st.LocalBranch, f.Options.BranchMaxLen, false)) } diff --git a/format/tmux/formater_test.go b/format/tmux/formater_test.go index 3a7308f..82fc5bb 100644 --- a/format/tmux/formater_test.go +++ b/format/tmux/formater_test.go @@ -256,7 +256,7 @@ func TestFormat(t *testing.T) { }, }, want: clear + "StyleBranchSymbolBranch" + - clear + "Local" + ".." + + clear + "StyleBranch" + "Local" + ".." + clear + "StyleRemoteRemote" + clear + " - " + clear + "StyleModSymbolMod2", @@ -283,7 +283,7 @@ func TestFormat(t *testing.T) { }, }, want: clear + "StyleBranchSymbolBranch" + - clear + "Local" + " ~~ " + + clear + "StyleBranch" + "Local" + " ~~ " + clear + "StyleModSymbolMod2", }, { @@ -346,10 +346,27 @@ func TestFormat(t *testing.T) { }, }, want: clear + "StyleBranch" + "SymbolBranch" + - clear + "branch..." + " " + + clear + "StyleBranch" + "branch..." + " " + clear + "StyleRemote" + "remote/branch..." + clear, }, + { + name: "issue-32", + styles: styles{ + Branch: "StyleBranch", + }, + symbols: symbols{ + Branch: "SymbolBranch", + }, + layout: []string{"branch"}, + st: &gitstatus.Status{ + Porcelain: gitstatus.Porcelain{ + LocalBranch: "branchName", + }, + }, + want: clear + "StyleBranch" + "SymbolBranch" + + clear + "StyleBranch" + "branchName", + }, } for _, tc := range tests { tc := tc diff --git a/testdata/default.output.golden b/testdata/default.output.golden index b05b1d2..42cb900 100755 --- a/testdata/default.output.golden +++ b/testdata/default.output.golden @@ -1 +1 @@ -#[fg=default]#[fg=default]#[fg=white,bold]⎇ #[fg=default]master..#[fg=default]#[fg=cyan]origin/master#[fg=default] ↑·1 - #[fg=default]#[fg=green,bold]● 1 #[fg=red,bold]✚ 1 #[fg=cyan,bold]⚑ 1 #[fg=magenta,bold]… 1 \ No newline at end of file +#[fg=default]#[fg=default]#[fg=white,bold]⎇ #[fg=default]#[fg=white,bold]master..#[fg=default]#[fg=cyan]origin/master#[fg=default] ↑·1 - #[fg=default]#[fg=green,bold]● 1 #[fg=red,bold]✚ 1 #[fg=cyan,bold]⚑ 1 #[fg=magenta,bold]… 1 \ No newline at end of file