summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Knaack <davidkna@users.noreply.github.com>2022-04-26 20:02:01 +0200
committerGitHub <noreply@github.com>2022-04-26 20:02:01 +0200
commitbd7957f01c7fa2b14f068e4130f1aedea61f4a76 (patch)
treec78c4fdaf6e5706efafe1d0c4d05a6eeac4993d8
parentd4d84a592c2be43a9c8fa398884066ecc98a9f80 (diff)
fix(git_branch): correct variable name for remote branch (#3897)
-rw-r--r--.github/config-schema.json4
-rw-r--r--docs/config/README.md22
-rw-r--r--src/configs/git_branch.rs2
-rw-r--r--src/modules/git_branch.rs36
4 files changed, 50 insertions, 14 deletions
diff --git a/.github/config-schema.json b/.github/config-schema.json
index 1ac60a995..8884f8172 100644
--- a/.github/config-schema.json
+++ b/.github/config-schema.json
@@ -461,7 +461,7 @@
"default": {
"always_show_remote": false,
"disabled": false,
- "format": "on [$symbol$branch]($style)(:[$remote]($style)) ",
+ "format": "on [$symbol$branch(:$remote_branch)]($style) ",
"ignore_branches": [],
"only_attached": false,
"style": "bold purple",
@@ -2543,7 +2543,7 @@
"type": "object",
"properties": {
"format": {
- "default": "on [$symbol$branch]($style)(:[$remote]($style)) ",
+ "default": "on [$symbol$branch(:$remote_branch)]($style) ",
"type": "string"
},
"symbol": {
diff --git a/docs/config/README.md b/docs/config/README.md
index 3b69f6e3a..a3251cbe1 100644
--- a/docs/config/README.md
+++ b/docs/config/README.md
@@ -1419,17 +1419,17 @@ The `git_branch` module shows the active branch of the repo in your current dire
### Options
-| Option | Default | Description |
-| -------------------- | -------------------------------- | ---------------------------------------------------------------------------------------- |
-| `always_show_remote` | `false` | Shows the remote tracking branch name, even if it is equal to the local branch name. |
-| `format` | `"on [$symbol$branch]($style) "` | The format for the module. Use `"$branch"` to refer to the current branch name. |
-| `symbol` | `" "` | A format string representing the symbol of git branch. |
-| `style` | `"bold purple"` | The style for the module. |
-| `truncation_length` | `2^63 - 1` | Truncates a git branch to `N` graphemes. |
-| `truncation_symbol` | `"…"` | The symbol used to indicate a branch name was truncated. You can use `""` for no symbol. |
-| `only_attached` | `false` | Only show the branch name when not in a detached `HEAD` state. |
-| `ignore_branches` | `[]` | A list of names to avoid displaying. Useful for "master" or "main". |
-| `disabled` | `false` | Disables the `git_branch` module. |
+| Option | Default | Description |
+| -------------------- | ------------------------------------------------- | ---------------------------------------------------------------------------------------- |
+| `always_show_remote` | `false` | Shows the remote tracking branch name, even if it is equal to the local branch name. |
+| `format` | `"on [$symbol$branch(:$remote_branch)]($style) "` | The format for the module. Use `"$branch"` to refer to the current branch name. |
+| `symbol` | `" "` | A format string representing the symbol of git branch. |
+| `style` | `"bold purple"` | The style for the module. |
+| `truncation_length` | `2^63 - 1` | Truncates a git branch to `N` graphemes. |
+| `truncation_symbol` | `"…"` | The symbol used to indicate a branch name was truncated. You can use `""` for no symbol. |
+| `only_attached` | `false` | Only show the branch name when not in a detached `HEAD` state. |
+| `ignore_branches` | `[]` | A list of names to avoid displaying. Useful for "master" or "main". |
+| `disabled` | `false` | Disables the `git_branch` module. |
### Variables
diff --git a/src/configs/git_branch.rs b/src/configs/git_branch.rs
index a0843fa02..2f12a54d8 100644
--- a/src/configs/git_branch.rs
+++ b/src/configs/git_branch.rs
@@ -18,7 +18,7 @@ pub struct GitBranchConfig<'a> {
impl<'a> Default for GitBranchConfig<'a> {
fn default() -> Self {
GitBranchConfig {
- format: "on [$symbol$branch]($style)(:[$remote]($style)) ",
+ format: "on [$symbol$branch(:$remote_branch)]($style) ",
symbol: " ",
style: "bold purple",
truncation_length: std::i64::MAX,
diff --git a/src/modules/git_branch.rs b/src/modules/git_branch.rs
index a1b91ea1d..8d96a8bb4 100644
--- a/src/modules/git_branch.rs
+++ b/src/modules/git_branch.rs
@@ -396,6 +396,42 @@ mod tests {
repo_dir.close()
}
+ #[test]
+ fn test_remote() -> io::Result<()> {
+ let remote_dir = fixture_repo(FixtureProvider::Git)?;
+ let repo_dir = fixture_repo(FixtureProvider::Git)?;
+
+ create_command("git")?
+ .args(&["checkout", "-b", "test_branch"])
+ .current_dir(repo_dir.path())
+ .output()?;
+
+ create_command("git")?
+ .args(&["remote", "add", "--fetch", "remote_repo"])
+ .arg(remote_dir.path())
+ .current_dir(repo_dir.path())
+ .output()?;
+
+ create_command("git")?
+ .args(&["branch", "--set-upstream-to", "remote_repo/master"])
+ .current_dir(repo_dir.path())
+ .output()?;
+
+ let actual = ModuleRenderer::new("git_branch")
+ .path(&repo_dir.path())
+ .config(toml::toml! {
+ [git_branch]
+ format = "$branch(:$remote_name/$remote_branch)"
+ })
+ .collect();
+
+ let expected = Some("test_branch:remote_repo/master");
+
+ assert_eq!(expected, actual.as_deref());
+ repo_dir.close()?;
+ remote_dir.close()
+ }
+
// This test is not possible until we switch to `git status --porcelain`
// where we can mock the env for the specific git process. This is because
// git2 does not care about our mocking and when we set the real `GIT_DIR`