mirror of
https://github.com/martinvonz/jj.git
synced 2025-05-14 11:44:27 +00:00
cli: when auto-importing from git, rebase descendants
This commit is contained in:
parent
726b29978d
commit
305adf05cc
@ -269,7 +269,7 @@ jj init --git-repo=.";
|
|||||||
|
|
||||||
fn for_loaded_repo(
|
fn for_loaded_repo(
|
||||||
&self,
|
&self,
|
||||||
ui: &Ui,
|
ui: &mut Ui,
|
||||||
workspace: Workspace,
|
workspace: Workspace,
|
||||||
repo: Arc<ReadonlyRepo>,
|
repo: Arc<ReadonlyRepo>,
|
||||||
) -> Result<WorkspaceCommandHelper, CommandError> {
|
) -> Result<WorkspaceCommandHelper, CommandError> {
|
||||||
@ -298,7 +298,7 @@ struct WorkspaceCommandHelper {
|
|||||||
|
|
||||||
impl WorkspaceCommandHelper {
|
impl WorkspaceCommandHelper {
|
||||||
fn for_loaded_repo(
|
fn for_loaded_repo(
|
||||||
ui: &Ui,
|
ui: &mut Ui,
|
||||||
workspace: Workspace,
|
workspace: Workspace,
|
||||||
string_args: Vec<String>,
|
string_args: Vec<String>,
|
||||||
root_args: &Args,
|
root_args: &Args,
|
||||||
@ -326,12 +326,16 @@ impl WorkspaceCommandHelper {
|
|||||||
working_copy_committed: false,
|
working_copy_committed: false,
|
||||||
};
|
};
|
||||||
if working_copy_shared_with_git && may_update_working_copy {
|
if working_copy_shared_with_git && may_update_working_copy {
|
||||||
helper.import_git_refs_and_head(maybe_git_repo.as_ref().unwrap())?;
|
helper.import_git_refs_and_head(ui, maybe_git_repo.as_ref().unwrap())?;
|
||||||
}
|
}
|
||||||
Ok(helper)
|
Ok(helper)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn import_git_refs_and_head(&mut self, git_repo: &Repository) -> Result<(), CommandError> {
|
fn import_git_refs_and_head(
|
||||||
|
&mut self,
|
||||||
|
ui: &mut Ui,
|
||||||
|
git_repo: &Repository,
|
||||||
|
) -> Result<(), CommandError> {
|
||||||
let mut tx = self.start_transaction("import git refs");
|
let mut tx = self.start_transaction("import git refs");
|
||||||
git::import_refs(tx.mut_repo(), git_repo)?;
|
git::import_refs(tx.mut_repo(), git_repo)?;
|
||||||
if tx.mut_repo().has_changes() {
|
if tx.mut_repo().has_changes() {
|
||||||
@ -359,7 +363,15 @@ impl WorkspaceCommandHelper {
|
|||||||
self.repo = tx.commit();
|
self.repo = tx.commit();
|
||||||
locked_working_copy.finish(self.repo.op_id().clone());
|
locked_working_copy.finish(self.repo.op_id().clone());
|
||||||
} else {
|
} else {
|
||||||
self.repo = tx.commit();
|
let num_rebased = tx.mut_repo().rebase_descendants(ui.settings());
|
||||||
|
if num_rebased > 0 {
|
||||||
|
writeln!(
|
||||||
|
ui,
|
||||||
|
"Rebased {} descendant commits off of commits rewritten from git",
|
||||||
|
num_rebased
|
||||||
|
)?;
|
||||||
|
}
|
||||||
|
self.finish_transaction(ui, tx)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -53,6 +53,9 @@ fn test_git_colocated_rebase_on_import() {
|
|||||||
std::fs::write(workspace_root.join("file"), "modified").unwrap();
|
std::fs::write(workspace_root.join("file"), "modified").unwrap();
|
||||||
test_env.jj_cmd_success(&workspace_root, &["branch", "master"]);
|
test_env.jj_cmd_success(&workspace_root, &["branch", "master"]);
|
||||||
test_env.jj_cmd_success(&workspace_root, &["close", "-m", "modify a file"]);
|
test_env.jj_cmd_success(&workspace_root, &["close", "-m", "modify a file"]);
|
||||||
|
// TODO: We shouldn't need this command here to trigger an import of the
|
||||||
|
// refs/heads/master we just exported
|
||||||
|
test_env.jj_cmd_success(&workspace_root, &["st"]);
|
||||||
|
|
||||||
// Move `master` backwards, which should cause the working copy to be rebased
|
// Move `master` backwards, which should cause the working copy to be rebased
|
||||||
// off of the old position.
|
// off of the old position.
|
||||||
@ -65,6 +68,14 @@ fn test_git_colocated_rebase_on_import() {
|
|||||||
let commit2 = git_repo.find_commit(commit2_oid).unwrap();
|
let commit2 = git_repo.find_commit(commit2_oid).unwrap();
|
||||||
let commit1 = commit2.parents().next().unwrap();
|
let commit1 = commit2.parents().next().unwrap();
|
||||||
git_repo.branch("master", &commit1, true).unwrap();
|
git_repo.branch("master", &commit1, true).unwrap();
|
||||||
// TODO: This shouldn't fail
|
let stdout =
|
||||||
test_env.jj_cmd_failure(&workspace_root, &["log", "-T", "commit_id \" \" branches"]);
|
test_env.jj_cmd_success(&workspace_root, &["log", "-T", "commit_id \" \" branches"]);
|
||||||
|
insta::assert_snapshot!(stdout, @r###"
|
||||||
|
Rebased 1 descendant commits off of commits rewritten from git
|
||||||
|
Working copy now at: a64f325e0516
|
||||||
|
Added 0 files, modified 1 files, removed 0 files
|
||||||
|
@ a64f325e05167129f3488f85a570f22a8940634f
|
||||||
|
o f0f3ab56bfa927e3a65c2ac9a513693d438e271b master
|
||||||
|
o 0000000000000000000000000000000000000000
|
||||||
|
"###);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user