mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-12-29 20:43:37 +03:00
Update of series name disallowed after push
This commit is contained in:
parent
89960f6bfc
commit
c94e8d121f
@ -235,6 +235,13 @@ impl Stack for Branch {
|
||||
.iter_mut()
|
||||
.find(|h: &&mut PatchReference| h.name == branch_name);
|
||||
if let Some(head) = head {
|
||||
// ensure that the head has not been pushed to a remote yet
|
||||
let default_target = branch_state(ctx).get_default_target()?;
|
||||
if let Some(remote) = default_target.push_remote_name {
|
||||
if reference_exists(ctx, &head.remote_reference(remote)?)? {
|
||||
bail!("Cannot update the name of a head that has been pushed to a remote");
|
||||
}
|
||||
}
|
||||
head.name = name;
|
||||
validate_name(head, ctx, &state)?;
|
||||
}
|
||||
|
@ -620,6 +620,35 @@ fn push_series_success() -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn update_name_after_push() -> Result<()> {
|
||||
let (ctx, _temp_dir) = command_ctx("multiple-commits")?;
|
||||
let mut test_ctx = test_ctx(&ctx)?;
|
||||
test_ctx.branch.initialize(&ctx)?;
|
||||
|
||||
let state = VirtualBranchesHandle::new(ctx.project().gb_dir());
|
||||
let mut target = state.get_default_target()?;
|
||||
target.push_remote_name = Some("origin".into());
|
||||
state.set_default_target(target)?;
|
||||
|
||||
let result = test_ctx.branch.push_series(&ctx, "virtual".into(), false);
|
||||
assert!(result.is_ok());
|
||||
let result = test_ctx.branch.update_series(
|
||||
&ctx,
|
||||
"virtual".into(),
|
||||
&PatchReferenceUpdate {
|
||||
name: Some("new-name".into()),
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
assert!(result.is_err());
|
||||
assert_eq!(
|
||||
result.err().unwrap().to_string(),
|
||||
"Cannot update the name of a head that has been pushed to a remote"
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn list_series_uninitialized() -> Result<()> {
|
||||
let (ctx, _temp_dir) = command_ctx("multiple-commits")?;
|
||||
|
Loading…
Reference in New Issue
Block a user