-
Notifications
You must be signed in to change notification settings - Fork 492
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Base branch: Safely handle divergence #4899
base: master
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
ba3329e
to
901e225
Compare
b72085e
to
2a4bbef
Compare
2a4bbef
to
624e5c3
Compare
1ef2625
to
5de527d
Compare
7755dfd
to
e08fdd2
Compare
e08fdd2
to
b3da0b7
Compare
Determine whether the local target has diverged from the remote, and return some information about that
If the local target has diverged from the remote target, display that to the user as a warning
In order to make it a bit clearer what the divergence state of the base branch is. reuse the line graphs to display it
If needed, the base branch can be pushed or force pushed
Only display the warnings and confirmation modals when actual changes can get lost (resting to local or remote). Otherwise, display less scary notifications and let the user push if needed
b3da0b7
to
72d0050
Compare
72d0050
to
bb09576
Compare
Lets separate out the update of base branch (because we can in the future show exactly what is gonna happen to branches) |
bd6393e
to
935dd4a
Compare
If the base branch has diverged from the upstream, reset the local base branch to the fork-point. This clears the way for merging the upstream changes later on.
The two available options to resolve base branch divergence are now: - Push (with force if needed) your local changes to the upstream - Reset your local base branch to the fork-point That way, the user is able to update their workspace as usual
935dd4a
to
b20637d
Compare
b20637d
to
a20da2f
Compare
pub(crate) fn realign_base_branch( | ||
ctx: &CommandContext, | ||
perm: &mut WorktreeWritePermission, | ||
) -> anyhow::Result<Vec<ReferenceName>> { | ||
ctx.assure_resolved()?; | ||
|
||
let target = default_target(&ctx.project().gb_dir())?; | ||
let base = target_to_base_branch(ctx, &target)?; | ||
|
||
if !base.diverged { | ||
return Ok(Vec::new()); | ||
} | ||
|
||
let target_commit = ctx | ||
.repository() | ||
.find_commit( | ||
base.diverged_fork_point | ||
.context("failed to find fork point")?, | ||
) | ||
.context("failed to find target commit")?; | ||
|
||
set_base_branch_to_commit(ctx, target_commit, perm) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the difference between update_base_branch and realign_base_branch? Can they be made the same function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
update_base_branch
:
This resets the local base branch to whatever the tip of its upstream is.
realign_base_branch
:
This resets the local base branch to the fork-point it has to its upstream.
This drops any ahead changes in the local base branch.
So it's "aligned" in the sense that it no longer diverts from upstream.
async realignBaseBranch(): Promise<string | undefined> { | ||
this.loading.set(true); | ||
try { | ||
const stashedConflicting = await invoke<string[]>('realign_base_branch', { | ||
projectId: this.projectId | ||
}); | ||
await this.fetchFromRemotes(); | ||
return getStashedConflictingMessage(stashedConflicting); | ||
} catch (err: any) { | ||
showError('Failed to realign base branch', err); | ||
console.error(err); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we even call this from the frontend? Doing a quick text search I'm not seeing it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's a large diff that wasn't rendered. At least for me
|
||
async function realignBaseBranch() { | ||
baseBranchIsUpdating = true; | ||
const infoText = await baseBranchService.realignBaseBranch(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Caleb-T-Owens here :)
FYI: This PR needs some rework around the way that we want the resolution to work. |
☕️ Reasoning
The application doesn't display any kind of information related to base branch divergence.
It should detect this, raise this to the user and present alternative actions to address this.
Scenario
Expected behavior would be to have some information about this and the ability to restore the application to the latest version of the target upstream.
🧢 Changes
Visuals
Local is ahead of upstream
In this state, gitbutler/workspace is ahead of the target upstream.
The information is presented to the user as a heads-up only, as they might want to push the changes,
If they want to reset their local target branch to the current state of the target upstream, they will be prompted with a confirmation modal.
Local has changes ahead and behind upstream
Similar to the previous state, there are some local commits that are not in the remote, but also some remote changes that are not in the local branch.
The information is displayed as a warning.
The options are to hard reset to the fork-point, or force-push.
Both buttons trigger confirmation dialogues.
Confirmation dialogue when resetting to the fork-point
Confirmation dialogue when force-pushing the local changes to the remote