Skip to content

Commit

Permalink
[#10] Reset to default branch if update branch is behind
Browse files Browse the repository at this point in the history
Problem: if the default branch is updated while an update branch exists,
the update branch won't be automatically rebased.

Solution: in lieu of a proper rebase, which is hard, reset the update
branch to the default, as we'll have to force-push anyway, and there's
not much to rebase if there are no human commits to begin with.
  • Loading branch information
lierdakil committed Jul 21, 2023
1 parent a026f72 commit eaac4d4
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ pub enum SetupUpdateBranchError {
HumanCommitsInUpdateBranch,
#[error("Failed to force-checkout update branch: {0}")]
ForceCheckoutUpdateBranch(#[from] ForceCheckoutBranchError),
#[error("Failed to count ahead/behind for the update branch: {0}")]
GraphAheadBehind(git2::Error),
}

pub fn setup_update_branch(
Expand Down Expand Up @@ -224,7 +226,16 @@ pub fn setup_update_branch(
{
return Err(SetupUpdateBranchError::HumanCommitsInUpdateBranch);
}
b
let (_ahead, behind) = repo
.graph_ahead_behind(update_branch_commit.id(), default_branch_commit.id())
.map_err(SetupUpdateBranchError::GraphAheadBehind)?;
if behind > 0 {
// update branch is outdated, reset to default, as we'll have to force-push anyway
default_branch
} else {
// update branch isn't outdated, so use it
b
}
} else {
default_branch
};
Expand Down

0 comments on commit eaac4d4

Please sign in to comment.