mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-18 18:27:38 +00:00
cli: don't use stale index to look up snapshotted working copy
This commit is contained in:
parent
be15d167c6
commit
c2c32ba0dc
2 changed files with 24 additions and 6 deletions
|
@ -5082,14 +5082,15 @@ fn cmd_git_push(
|
|||
args: &GitPushArgs,
|
||||
) -> Result<(), CommandError> {
|
||||
let mut workspace_command = command.workspace_helper(ui)?;
|
||||
let repo = workspace_command.repo().clone();
|
||||
|
||||
let mut tx;
|
||||
let mut branch_updates = vec![];
|
||||
if let Some(branch_name) = &args.branch {
|
||||
if let Some(update) =
|
||||
branch_updates_for_push(repo.as_repo_ref(), &args.remote, branch_name)?
|
||||
{
|
||||
if let Some(update) = branch_updates_for_push(
|
||||
workspace_command.repo().as_repo_ref(),
|
||||
&args.remote,
|
||||
branch_name,
|
||||
)? {
|
||||
branch_updates.push((branch_name.clone(), update));
|
||||
} else {
|
||||
writeln!(
|
||||
|
@ -5109,7 +5110,12 @@ fn cmd_git_push(
|
|||
ui.settings().push_branch_prefix(),
|
||||
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!(
|
||||
ui,
|
||||
"Creating branch {} for revision {}",
|
||||
|
@ -5136,7 +5142,7 @@ fn cmd_git_push(
|
|||
}
|
||||
} else {
|
||||
// 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);
|
||||
match push_action {
|
||||
BranchPushAction::AlreadyMatches => {}
|
||||
|
@ -5156,6 +5162,8 @@ fn cmd_git_push(
|
|||
return Ok(());
|
||||
}
|
||||
|
||||
let repo = workspace_command.repo();
|
||||
|
||||
let mut ref_updates = vec![];
|
||||
let mut new_heads = vec![];
|
||||
for (branch_name, update) in &branch_updates {
|
||||
|
|
|
@ -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]
|
||||
fn test_git_push_conflict() {
|
||||
let (test_env, workspace_root) = set_up();
|
||||
|
|
Loading…
Reference in a new issue