Skip to content

Commit

Permalink
Merge pull request #29 from serokell/lierdakil/#10-cherry-pick-human-…
Browse files Browse the repository at this point in the history
…commits

[#10] Reset to default branch if update branch is behind
  • Loading branch information
lierdakil authored Jul 26, 2023
2 parents a026f72 + eaac4d4 commit 1a03068
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 1a03068

Please sign in to comment.