Skip to content

Commit

Permalink
git: port s/bookmark/branch/ renames to config migration rules
Browse files Browse the repository at this point in the history
These two are easy. "fix.tool-command" will be processed by a custom migration
rule of Box<dyn Fn(&mut ConfigLayer) -> ..> type.
  • Loading branch information
yuja committed Jan 8, 2025
1 parent 1fc1851 commit 83f52ba
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 33 deletions.
1 change: 1 addition & 0 deletions cli/src/commands/fix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ fn get_tools_config(ui: &mut Ui, settings: &UserSettings) -> Result<ToolsConfig,
matcher: Box::new(EverythingMatcher),
});

// TODO: Reimplement as a ConfigMigrationRule
writeln!(
ui.warning_default(),
r"The `fix.tool-command` config option is deprecated and will be removed in a future version."
Expand Down
19 changes: 1 addition & 18 deletions cli/src/commands/git/push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ pub fn cmd_git_push(
let mut seen_bookmarks: HashSet<&str> = HashSet::new();

// Process --change bookmarks first because matching bookmarks can be moved.
let bookmark_prefix = get_change_bookmark_prefix(ui, tx.settings())?;
let bookmark_prefix = tx.settings().get_string("git.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| {
Expand Down Expand Up @@ -505,23 +505,6 @@ fn get_default_push_remote(
}
}

fn get_change_bookmark_prefix(ui: &Ui, settings: &UserSettings) -> Result<String, CommandError> {
// TODO: Drop support support for git.push-branch-prefix in 0.28.0+ and move
// the default value to config/*.toml
if let Some(prefix) = settings.get_string("git.push-branch-prefix").optional()? {
writeln!(
ui.warning_default(),
"Config git.push-branch-prefix is deprecated. Please switch to \
git.push-bookmark-prefix",
)?;
Ok(prefix)
} else if let Some(prefix) = settings.get_string("git.push-bookmark-prefix").optional()? {
Ok(prefix)
} else {
Ok("push-".to_owned())
}
}

#[derive(Clone, Debug)]
struct RejectedBookmarkUpdateReason {
message: String,
Expand Down
7 changes: 6 additions & 1 deletion cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,12 @@ fn parse_config_arg_item(item_str: &str) -> Result<(ConfigNamePathBuf, ConfigVal

/// List of rules to migrate deprecated config variables.
pub fn default_config_migrations() -> Vec<ConfigMigrationRule> {
vec![] // TODO
vec![
// TODO: Delete in jj 0.32+
ConfigMigrationRule::rename_value("git.auto-local-branch", "git.auto-local-bookmark"),
// TODO: Delete in jj 0.28+
ConfigMigrationRule::rename_value("git.push-branch-prefix", "git.push-bookmark-prefix"),
]
}

/// Command name and arguments specified by config.
Expand Down
3 changes: 3 additions & 0 deletions cli/src/config/misc.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ context = 3
[diff.git]
context = 3

[git]
push-bookmark-prefix = "push-"

[ui]
# TODO: delete ui.allow-filesets in jj 0.26+
allow-filesets = true
Expand Down
6 changes: 3 additions & 3 deletions cli/tests/test_git_push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -710,12 +710,12 @@ fn test_git_push_changes() {
],
);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @r#"
Warning: Config git.push-branch-prefix is deprecated. Please switch to git.push-bookmark-prefix
insta::assert_snapshot!(stderr, @r"
Warning: Deprecated config: git.push-branch-prefix is renamed to git.push-bookmark-prefix
Creating bookmark branch-yostqsxwqrlt for revision yostqsxwqrlt
Changes to push to origin:
Add bookmark branch-yostqsxwqrlt to 38cb417ce3a6
"#);
");
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion lib/src/config/misc.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ register_snapshot_trigger = false

[git]
abandon-unreachable-commits = true
# auto-local-bookmark = false
auto-local-bookmark = false

[operation]
hostname = ""
Expand Down
12 changes: 2 additions & 10 deletions lib/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,9 @@ pub struct GitSettings {

impl GitSettings {
pub fn from_settings(settings: &UserSettings) -> Result<Self, ConfigGetError> {
let auto_local_bookmark = {
// TODO: Drop support for git.auto-local-branch and move the default
// value to config/*.toml
let opt1 = settings.get_bool("git.auto-local-bookmark").optional()?;
let opt2 = settings.get_bool("git.auto-local-branch").optional()?;
opt1.or(opt2).unwrap_or(false)
};
let abandon_unreachable_commits = settings.get_bool("git.abandon-unreachable-commits")?;
Ok(GitSettings {
auto_local_bookmark,
abandon_unreachable_commits,
auto_local_bookmark: settings.get_bool("git.auto-local-bookmark")?,
abandon_unreachable_commits: settings.get_bool("git.abandon-unreachable-commits")?,
})
}
}
Expand Down

0 comments on commit 83f52ba

Please sign in to comment.