From 63e616c8012613971a3449127b00da570d8456c5 Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Thu, 12 Sep 2024 21:45:12 -0700 Subject: [PATCH] git: restore support for `git.push-branch-prefix` config but deprecate it --- CHANGELOG.md | 3 +++ cli/src/commands/git/push.rs | 19 +++++++++++++------ cli/tests/test_git_push.rs | 19 +++++++++++++++++++ lib/src/settings.rs | 4 ++++ 4 files changed, 39 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a668858a..12acfe08b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,9 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). that describes them better, and they also behave similar to Mercurial's bookmarks. +* The `git.push-branch-prefix` config has been deprecated in favor of + `git.push-bookmark-prefix`. + ### New features * The new config option `snapshot.auto-track` lets you automatically track only diff --git a/cli/src/commands/git/push.rs b/cli/src/commands/git/push.rs index 834f0dc7f..079f8b683 100644 --- a/cli/src/commands/git/push.rs +++ b/cli/src/commands/git/push.rs @@ -193,12 +193,19 @@ pub fn cmd_git_push( let mut seen_bookmarks: HashSet<&str> = HashSet::new(); // Process --change bookmarks first because matching bookmarks can be moved. - let change_bookmark_names = update_change_bookmarks( - ui, - &mut tx, - &args.change, - &command.settings().push_bookmark_prefix(), - )?; + // TODO: Drop support support for git.push-branch-prefix in 0.28.0+ + let bookmark_prefix = if let Some(prefix) = command.settings().push_branch_prefix() { + writeln!( + ui.warning_default(), + "Config git.push-branch-prefix is deprecated. Please switch to \ + git.push-bookmark-prefix", + )?; + prefix + } else { + command.settings().push_bookmark_prefix() + }; + let change_bookmark_names = + update_change_bookmarks(ui, &mut tx, &args.change, &bookmark_prefix)?; let change_bookmarks = change_bookmark_names.iter().map(|bookmark_name| { let targets = LocalAndRemoteRef { local_target: tx.repo().view().get_local_bookmark(bookmark_name), diff --git a/cli/tests/test_git_push.rs b/cli/tests/test_git_push.rs index 9259278ff..0d66d7a47 100644 --- a/cli/tests/test_git_push.rs +++ b/cli/tests/test_git_push.rs @@ -679,6 +679,25 @@ fn test_git_push_changes() { Bookmark changes to push to origin: Add bookmark test-yostqsxwqrlt to 38cb417ce3a6 "###); + + // Test deprecation warning for `git.push-branch-prefix` + let (stdout, stderr) = test_env.jj_cmd_ok( + &workspace_root, + &[ + "git", + "push", + "--config-toml", + r"git.push-branch-prefix='branch-'", + "--change=@", + ], + ); + insta::assert_snapshot!(stdout, @""); + insta::assert_snapshot!(stderr, @r###" + Warning: Config git.push-branch-prefix is deprecated. Please switch to git.push-bookmark-prefix + Creating bookmark branch-yostqsxwqrlt for revision yostqsxwqrlt + Bookmark changes to push to origin: + Add bookmark branch-yostqsxwqrlt to 38cb417ce3a6 + "###); } #[test] diff --git a/lib/src/settings.rs b/lib/src/settings.rs index 5f03c5f3d..e3cffb5f1 100644 --- a/lib/src/settings.rs +++ b/lib/src/settings.rs @@ -196,6 +196,10 @@ impl UserSettings { .unwrap_or_else(|_| "push-".to_string()) } + pub fn push_branch_prefix(&self) -> Option { + self.config.get_string("git.push-branch-prefix").ok() + } + pub fn default_description(&self) -> String { self.config() .get_string("ui.default-description")