Repository: JanDeDobbeleer/oh-my-posh
Pull request #1251 (2021-11-18 17:55:46)

Git branch truncate symbol
### Prerequisites

- [X] I have read and understood the `CONTRIBUTING` guide
- [X] The commit message follows the [conventional commits][cc] guidelines
- [X] Tests for the changes have been added (for bug fixes/features)
- [X] Docs have been added / updated (for bug fixes/features)

### Description

Added a new settings that allows you to set an icon to the end of the string when a branch name is truncated



Patch:
diff --git a/docs/docs/segment-git.mdx b/docs/docs/segment-git.mdx
index 8a5b5b30..79cded01 100644
--- a/docs/docs/segment-git.mdx
+++ b/docs/docs/segment-git.mdx
@@ -76,6 +76,7 @@ You can set the following properties to `true` to enable fetching additional inf
 - branch_behind_icon: `string` - the icon to display when the local branch is behind its remote - defaults to `\u2193`
 - branch_gone_icon: `string` - the icon to display when there's no remote branch - defaults to `\u2262`
 - branch_max_length: `int` - the max length for the displayed branch name where `0` implies full length - defaults to `0`
+- truncate_symbol: `string` - the icon to display when a branch name is truncated - defaults to empty
 
 #### HEAD
 
diff --git a/src/segment_git.go b/src/segment_git.go
index b312c9dc..7fc6d460 100644
--- a/src/segment_git.go
+++ b/src/segment_git.go
@@ -95,6 +95,8 @@ const (
 
 	// BranchMaxLength truncates the length of the branch name
 	BranchMaxLength Property = "branch_max_length"
+	// TruncateSymbol appends the set symbol to a truncated branch name
+	TruncateSymbol Property = "truncate_symbol"
 	// BranchIcon the icon to use as branch indicator
 	BranchIcon Property = "branch_icon"
 	// BranchIdenticalIcon the icon to display when the remote and local branch are identical
@@ -384,7 +386,8 @@ func (g *git) truncateBranch(branch string) string {
 	if maxLength == 0 || len(branch) < maxLength {
 		return branch
 	}
-	return branch[0:maxLength]
+	symbol := g.props.getString(TruncateSymbol, "")
+	return branch[0:maxLength] + symbol
 }
 
 func (g *git) hasGitFile(file string) bool {


Test patch:
diff --git a/src/segment_git_test.go b/src/segment_git_test.go
index 4fde6b30..e941247d 100644
--- a/src/segment_git_test.go
+++ b/src/segment_git_test.go
@@ -667,6 +667,34 @@ func TestTruncateBranch(t *testing.T) {
 	}
 }
 
+func TestTruncateBranchWithSymbol(t *testing.T) {
+	cases := []struct {
+		Case           string
+		Expected       string
+		Branch         string
+		MaxLength      interface{}
+		TruncateSymbol interface{}
+	}{
+		{Case: "No limit", Expected: "all-your-base-are-belong-to-us", Branch: "all-your-base-are-belong-to-us", TruncateSymbol: "..."},
+		{Case: "No limit - larger", Expected: "all-your-base...", Branch: "all-your-base-are-belong-to-us", MaxLength: 13.0, TruncateSymbol: "..."},
+		{Case: "No limit - smaller", Expected: "all-your-base", Branch: "all-your-base", MaxLength: 16.0, TruncateSymbol: "..."},
+		{Case: "Invalid setting", Expected: "all-your-base", Branch: "all-your-base", MaxLength: "burp", TruncateSymbol: "..."},
+		{Case: "Lower than limit", Expected: "all-your-base", Branch: "all-your-base", MaxLength: 20.0, TruncateSymbol: "..."},
+	}
+
+	for _, tc := range cases {
+		g := &git{
+			props: &properties{
+				values: map[Property]interface{}{
+					BranchMaxLength: tc.MaxLength,
+					TruncateSymbol:  tc.TruncateSymbol,
+				},
+			},
+		}
+		assert.Equal(t, tc.Expected, g.truncateBranch(tc.Branch), tc.Case)
+	}
+}
+
 func TestGetGitCommand(t *testing.T) {
 	cases := []struct {
 		Case     string