Skip to content

Commit

Permalink
branch: ignore git tracking branches for rename warning
Browse files Browse the repository at this point in the history
Prevents a warning from being printed when renaming branches in a
colocated repo, since git tracking branches were being considered as
remote tracking branches.
  • Loading branch information
scott2000 committed Jul 18, 2024
1 parent 94f5a20 commit d5c526f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
* Windows binaries no longer require `vcruntime140.dll` to be installed
(normally through Visual Studio.)

* `jj branch rename` no longer shows a warning in colocated repos.

## [0.19.0] - 2024-07-03

### Breaking changes
Expand Down
2 changes: 2 additions & 0 deletions cli/src/commands/branch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ mod untrack;

use itertools::Itertools as _;
use jj_lib::backend::CommitId;
use jj_lib::git;
use jj_lib::op_store::{RefTarget, RemoteRef};
use jj_lib::repo::Repo;
use jj_lib::str_util::StringPattern;
Expand Down Expand Up @@ -163,6 +164,7 @@ fn find_remote_branches<'a>(
/// local branch.)
fn has_tracked_remote_branches(view: &View, branch: &str) -> bool {
view.remote_branches_matching(&StringPattern::exact(branch), &StringPattern::everything())
.filter(|&((_, remote_name), _)| remote_name != git::REMOTE_NAME_FOR_LOCAL_GIT_REPO)
.any(|(_, remote_ref)| remote_ref.is_tracking())
}

Expand Down
15 changes: 15 additions & 0 deletions cli/tests/test_branch_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,21 @@ fn test_branch_rename() {
"###);
}

#[test]
fn test_branch_rename_colocated() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "repo", "--colocate"]);
let repo_path = test_env.env_root().join("repo");

test_env.jj_cmd_ok(&repo_path, &["describe", "-m=commit-0"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "blocal"]);

// Make sure that git tracking branches don't cause a warning
let (_stdout, stderr) =
test_env.jj_cmd_ok(&repo_path, &["branch", "rename", "blocal", "blocal1"]);
insta::assert_snapshot!(stderr, @"");
}

#[test]
fn test_branch_forget_glob() {
let test_env = TestEnvironment::default();
Expand Down

0 comments on commit d5c526f

Please sign in to comment.