Skip to content

Commit

Permalink
fix(refresh): handle edited message and patch name
Browse files Browse the repository at this point in the history
When using `stg refresh --edit` and both the patch name and commit
message were modified, the updated message was being discarded.

This was due to the stack transaction not properly accounting for
the possibility of a patch rename happening after an update.

Fixes: #470
  • Loading branch information
jpgrayson committed Jul 21, 2024
1 parent 549bafc commit fada9e7
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/stack/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -830,10 +830,16 @@ impl<'repo> StackTransaction<'repo> {
panic!("old `{old_patchname}` not found in applied, unapplied, or hidden");
}

let patch = self.stack.get_patch(old_patchname).clone();
self.updated_patches.insert(old_patchname.clone(), None);
self.updated_patches
.insert(new_patchname.clone(), Some(patch));
if let Some(Some(patch_state)) = self.updated_patches.remove(old_patchname) {
// The renamed patch may have been previously updated in this transaction.
// This can happen, for example, for `stg refresh`.
self.updated_patches.insert(old_patchname.clone(), None);
self.updated_patches.insert(new_patchname.clone(), Some(patch_state));
} else {
let patch_state = self.stack.get_patch(old_patchname).clone();
self.updated_patches.insert(old_patchname.clone(), None);
self.updated_patches.insert(new_patchname.clone(), Some(patch_state));
}

self.ui.print_rename(old_patchname, new_patchname)
}
Expand Down

0 comments on commit fada9e7

Please sign in to comment.