Skip to content

Commit 74da3c9

Browse files
committed
Remove a legacy way of updating the stack branch head
This was used only in tests anyways
1 parent e47ff22 commit 74da3c9

File tree

2 files changed

+1
-142
lines changed

2 files changed

+1
-142
lines changed

crates/gitbutler-stack/src/stack.rs

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -512,54 +512,8 @@ impl Stack {
512512
}
513513

514514
let state = branch_state(ctx);
515-
let patches = self.stack_patches(&ctx.to_stack_context()?, true)?;
516515
let mut updated_heads = self.heads.clone();
517516

518-
// Handle target updates
519-
if let Some(target_update) = &update.target_update {
520-
let mut new_head = updated_heads
521-
.clone()
522-
.into_iter()
523-
.find(|h| *h.name() == branch_name)
524-
.ok_or_else(|| anyhow!("Series with name {} not found", branch_name))?;
525-
let gix_repo = ctx.gix_repository()?;
526-
new_head.set_head(target_update.target.clone(), &gix_repo)?;
527-
validate_target(
528-
new_head.head_oid(&gix_repo)?,
529-
ctx.repo(),
530-
self.head(&gix_repo)?,
531-
&state,
532-
)?;
533-
let preceding_head = if let Some(preceding_head_name) = update
534-
.target_update
535-
.clone()
536-
.and_then(|update| update.preceding_head_name)
537-
{
538-
let (_, preceding_head) = get_head(&self.heads, &preceding_head_name)
539-
.context("The specified preceding_head could not be found")?;
540-
Some(preceding_head)
541-
} else {
542-
None
543-
};
544-
545-
// drop the old head and add the new one
546-
let (idx, _) = get_head(&updated_heads, &branch_name)?;
547-
updated_heads.remove(idx);
548-
let last_updated_head: Option<CommitOrChangeId> = updated_heads
549-
.last()
550-
.and_then(|h| h.head_oid(&gix_repo).ok().map(|h| h.into()));
551-
if patches.last() != last_updated_head.as_ref() {
552-
bail!("This update would cause orphaned patches, which is disallowed");
553-
}
554-
updated_heads = add_head(
555-
updated_heads,
556-
new_head.clone(),
557-
preceding_head,
558-
patches.clone(),
559-
&gix_repo,
560-
)?;
561-
}
562-
563517
// Handle name updates
564518
if let Some(name) = update.name.clone() {
565519
let head = updated_heads
@@ -863,7 +817,6 @@ impl Stack {
863817
/// Request to update a PatchReference.
864818
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, Default)]
865819
pub struct PatchReferenceUpdate {
866-
pub target_update: Option<TargetUpdate>,
867820
pub name: Option<String>,
868821
/// If present, this sets the value of the description field.
869822
/// It is possible to set this to Some(None) which will remove an existing description.

crates/gitbutler-stack/tests/mod.rs

Lines changed: 1 addition & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use gitbutler_command_context::CommandContext;
77
use gitbutler_repo::logging::{LogUntil, RepositoryExt as _};
88
use gitbutler_repo_actions::RepoActionsExt;
99
use gitbutler_stack::stack_context::CommandContextExt;
10+
use gitbutler_stack::PatchReferenceUpdate;
1011
use gitbutler_stack::{CommitOrChangeId, StackBranch, VirtualBranchesHandle};
11-
use gitbutler_stack::{PatchReferenceUpdate, TargetUpdate};
1212
use itertools::Itertools;
1313
use tempfile::TempDir;
1414

@@ -381,7 +381,6 @@ fn update_branch_name_fails_validation() -> Result<()> {
381381
let mut test_ctx = test_ctx(&ctx)?;
382382
let update = PatchReferenceUpdate {
383383
name: Some("invalid name".into()),
384-
target_update: None,
385384
description: None,
386385
};
387386
let result = test_ctx
@@ -397,7 +396,6 @@ fn update_branch_name_success() -> Result<()> {
397396
let mut test_ctx = test_ctx(&ctx)?;
398397
let update = PatchReferenceUpdate {
399398
name: Some("new-name".into()),
400-
target_update: None,
401399
description: None,
402400
};
403401
let result = test_ctx
@@ -424,7 +422,6 @@ fn update_branch_name_resets_pr_number() -> Result<()> {
424422
assert_eq!(test_ctx.stack.heads[0].pr_number, Some(pr_number));
425423
let update = PatchReferenceUpdate {
426424
name: Some("new-name".into()),
427-
target_update: None,
428425
description: None,
429426
};
430427
test_ctx
@@ -444,7 +441,6 @@ fn update_series_set_description() -> Result<()> {
444441
let mut test_ctx = test_ctx(&ctx)?;
445442
let update = PatchReferenceUpdate {
446443
name: None,
447-
target_update: None,
448444
description: Some(Some("my description".into())),
449445
};
450446
let result = test_ctx
@@ -463,96 +459,6 @@ fn update_series_set_description() -> Result<()> {
463459
Ok(())
464460
}
465461

466-
#[test]
467-
fn update_series_target_fails_commit_not_in_stack() -> Result<()> {
468-
let (ctx, _temp_dir) = command_ctx("multiple-commits")?;
469-
let mut test_ctx = test_ctx(&ctx)?;
470-
let other_commit_id = test_ctx.other_commits.last().unwrap().id().to_string();
471-
let update = PatchReferenceUpdate {
472-
name: None,
473-
target_update: Some(TargetUpdate {
474-
target: CommitOrChangeId::CommitId(other_commit_id.clone()),
475-
preceding_head_name: None,
476-
}),
477-
description: None,
478-
};
479-
let result = test_ctx
480-
.stack
481-
.update_branch(&ctx, "a-branch-2".into(), &update);
482-
assert_eq!(
483-
result.err().unwrap().to_string(),
484-
format!(
485-
"The commit {} is not between the stack head and the stack base",
486-
other_commit_id
487-
)
488-
);
489-
Ok(())
490-
}
491-
492-
#[test]
493-
fn update_series_target_orphan_commit_fails() -> Result<()> {
494-
let (ctx, _temp_dir) = command_ctx("multiple-commits")?;
495-
let mut test_ctx = test_ctx(&ctx)?;
496-
let initial_state = test_ctx.stack.heads.clone();
497-
let first_commit_id = test_ctx.commits.first().unwrap().id().to_string();
498-
let update = PatchReferenceUpdate {
499-
name: Some("new-lol".into()),
500-
target_update: Some(TargetUpdate {
501-
target: CommitOrChangeId::CommitId(first_commit_id.clone()),
502-
preceding_head_name: None,
503-
}),
504-
description: None,
505-
};
506-
let result = test_ctx
507-
.stack
508-
.update_branch(&ctx, "a-branch-2".into(), &update);
509-
510-
assert_eq!(
511-
result.err().unwrap().to_string(),
512-
"This update would cause orphaned patches, which is disallowed"
513-
);
514-
assert_eq!(initial_state, test_ctx.stack.heads); // no change due to failure
515-
Ok(())
516-
}
517-
518-
#[test]
519-
fn update_series_target_success() -> Result<()> {
520-
let (ctx, _temp_dir) = command_ctx("multiple-commits")?;
521-
let mut test_ctx = test_ctx(&ctx)?;
522-
let commit_0_change_id = CommitOrChangeId::CommitId(test_ctx.commits[0].id().to_string());
523-
let repo = &ctx.gix_repository()?;
524-
let series_1 = StackBranch::new(commit_0_change_id.clone(), "series_1".into(), None, repo)?;
525-
let result = test_ctx.stack.add_series(&ctx, series_1, None);
526-
assert!(result.is_ok());
527-
assert_eq!(
528-
commit_0_change_id,
529-
test_ctx.stack.heads[0].head_oid(repo)?.into()
530-
);
531-
let commit_1_change_id = CommitOrChangeId::CommitId(test_ctx.commits[1].id().to_string());
532-
let update = PatchReferenceUpdate {
533-
name: None,
534-
target_update: Some(TargetUpdate {
535-
target: commit_1_change_id.clone(),
536-
preceding_head_name: None,
537-
}),
538-
description: None,
539-
};
540-
let result = test_ctx
541-
.stack
542-
.update_branch(&ctx, "series_1".into(), &update);
543-
assert!(result.is_ok());
544-
assert_eq!(
545-
commit_1_change_id,
546-
test_ctx.stack.heads[0].head_oid(repo)?.into()
547-
);
548-
// Assert persisted
549-
assert_eq!(
550-
test_ctx.stack,
551-
test_ctx.handle.get_stack(test_ctx.stack.id)?
552-
);
553-
Ok(())
554-
}
555-
556462
#[test]
557463
fn push_series_success() -> Result<()> {
558464
let (ctx, _temp_dir) = command_ctx("multiple-commits")?;

0 commit comments

Comments
 (0)