cli: don't use stale index to look up snapshotted working copy

This commit is contained in:
Martin von Zweigbergk 2022-07-04 23:14:39 -07:00 committed by Martin von Zweigbergk
parent be15d167c6
commit c2c32ba0dc
2 changed files with 24 additions and 6 deletions

View file

@ -5082,14 +5082,15 @@ fn cmd_git_push(
args: &GitPushArgs, args: &GitPushArgs,
) -> Result<(), CommandError> { ) -> Result<(), CommandError> {
let mut workspace_command = command.workspace_helper(ui)?; let mut workspace_command = command.workspace_helper(ui)?;
let repo = workspace_command.repo().clone();
let mut tx; let mut tx;
let mut branch_updates = vec![]; let mut branch_updates = vec![];
if let Some(branch_name) = &args.branch { if let Some(branch_name) = &args.branch {
if let Some(update) = if let Some(update) = branch_updates_for_push(
branch_updates_for_push(repo.as_repo_ref(), &args.remote, branch_name)? workspace_command.repo().as_repo_ref(),
{ &args.remote,
branch_name,
)? {
branch_updates.push((branch_name.clone(), update)); branch_updates.push((branch_name.clone(), update));
} else { } else {
writeln!( writeln!(
@ -5109,7 +5110,12 @@ fn cmd_git_push(
ui.settings().push_branch_prefix(), ui.settings().push_branch_prefix(),
commit.change_id().hex() commit.change_id().hex()
); );
if repo.view().get_local_branch(&branch_name).is_none() { if workspace_command
.repo()
.view()
.get_local_branch(&branch_name)
.is_none()
{
writeln!( writeln!(
ui, ui,
"Creating branch {} for revision {}", "Creating branch {} for revision {}",
@ -5136,7 +5142,7 @@ fn cmd_git_push(
} }
} else { } else {
// TODO: Is it useful to warn about conflicted branches? // TODO: Is it useful to warn about conflicted branches?
for (branch_name, branch_target) in repo.view().branches() { for (branch_name, branch_target) in workspace_command.repo().view().branches() {
let push_action = classify_branch_push_action(branch_target, &args.remote); let push_action = classify_branch_push_action(branch_target, &args.remote);
match push_action { match push_action {
BranchPushAction::AlreadyMatches => {} BranchPushAction::AlreadyMatches => {}
@ -5156,6 +5162,8 @@ fn cmd_git_push(
return Ok(()); return Ok(());
} }
let repo = workspace_command.repo();
let mut ref_updates = vec![]; let mut ref_updates = vec![];
let mut new_heads = vec![]; let mut new_heads = vec![];
for (branch_name, update) in &branch_updates { for (branch_name, update) in &branch_updates {

View file

@ -112,6 +112,16 @@ fn test_git_push_success() {
"###); "###);
} }
#[test]
fn test_git_push_unsnapshotted_change() {
let (test_env, workspace_root) = set_up();
test_env.jj_cmd_success(&workspace_root, &["describe", "-m", "foo"]);
std::fs::write(workspace_root.join("file"), "contents").unwrap();
test_env.jj_cmd_success(&workspace_root, &["git", "push", "--change", "@"]);
std::fs::write(workspace_root.join("file"), "modified").unwrap();
test_env.jj_cmd_success(&workspace_root, &["git", "push", "--change", "@"]);
}
#[test] #[test]
fn test_git_push_conflict() { fn test_git_push_conflict() {
let (test_env, workspace_root) = set_up(); let (test_env, workspace_root) = set_up();