Skip to content
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

Correctly request force-pushing in a triangular workflow #3528

Merged
merged 6 commits into from May 19, 2024

Conversation

stefanhaller
Copy link
Collaborator

@stefanhaller stefanhaller commented Apr 26, 2024

  • PR Description

Some people push to a different branch (or even remote) than they pull from. One example is described in #3437. Our logic of when to request a force push is not appropriate for these workflows: we check the configured upstream branch for divergence, but that's the one you pull from. We should instead check the push-to branch for divergence.

Fixes #3437.

Copy link

codacy-production bot commented Apr 26, 2024

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
Report missing for 9fc7a511 86.70%
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (9fc7a51) Report Missing Report Missing Report Missing
Head commit (c5cf1b2) 51185 43107 84.22%

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#3528) 218 189 86.70%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

Codacy will stop sending the deprecated coverage status from June 5th, 2024. Learn more

Footnotes

  1. Codacy didn't receive coverage data for the commit, or there was an error processing the received data. Check your integration for errors and validate that your coverage setup is correct.

@stefanhaller stefanhaller mentioned this pull request May 15, 2024
@stefanhaller stefanhaller added the bug Something isn't working label May 17, 2024
@stefanhaller stefanhaller marked this pull request as ready for review May 17, 2024 19:49
@stefanhaller stefanhaller added this to the v0.42 milestone May 18, 2024
Copy link
Owner

@jesseduffield jesseduffield left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fantastic work. Approved, but with a comment on documentation

@@ -20,8 +21,16 @@ func NewSessionStateLoader(c *helpers.HelperCommon, refsHelper *helpers.RefsHelp
}
}

type Commit struct {
Hash string
// We create shims for all the model classes in order to get a more stable API
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great stuff. We should also update docs/Custom_Command_Keybindings.md which currently says

To see what fields are available on e.g. the SelectedFile, see here

We should update this to just point to this file now

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a tricky one. In some cases the original model struct has documentation for its fields (e.g. models.Branch), which I didn't copy over to the shims. So pointing users to the shims gives them less information.

Or should I copy the comments over? Seemed so redundant.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, interesting. I say point the users to this file but don't copy the comments. Most fields are self-explanatory and the ones that aren't are likely not the ones the user needs

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, works for me. To make this easier for users, I decided to move the struct definitions to a separate file (7ab7fae), and to remove the "Shim" from the names again (416106a). Documentation is adapted here: 91132a7.

I noticed that the documentation already says that we don't guarantee backwards compatibility. Do we now, and should remove this sentence? Also, it says we are planning to expose a tighter API in the future; do we want to change anything about that sentence? Feel free to push a fixup if you want to tweak that documentation further.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose we now do support backwards compatibility so indeed we can lose that line. We can also remove the part about the tighter API: I have no plans for changing things anytime soon.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, removed in 283cf3a.

Going to squash now, and then merge (will take a moment as the fixups conflict).

@stefanhaller stefanhaller force-pushed the support-triangular-workflow branch 2 times, most recently from 91132a7 to 283cf3a Compare May 19, 2024 07:33
This guards against accidentally renaming a model field and thereby breaking
user's custom commands. With this change we'll get a build failure when we do
that.
It is unexpected that a function called PushBranch also sets the upstream
branch; also, we want to add a PushBranch function in the next commit that
doesn't.
… workflow

Our code doesn't realize that we need to prompt the user to force push, when the
branch is up-to-date with its upstream but not with the branch that we're
pushing to.
In preparation for adding AheadForPush/BehindForPush in the next commit.
In a triangular workflow the branch that you're pulling from is not the same as
the one that you are pushing to. For example, some people find it useful to set
the upstream branch to origin/master so that pulling effectively rebases onto
master, and set the push.default git config to "current" so that "feature"
pushes to origin/feature.

Another example is a fork-based workflow where "feature" has upstream set to
upstream/main, and the repo has remote.pushDefault set to "origin", so pushing
on "feature" pushes to origin/feature.

This commit adds new fields to models.Branch that store the ahead/behind
information against the push branch; for the "normal" workflow where you pull
and push from/to the upstream branch, AheadForPush/BehindForPush will be the
same as AheadForPull/BehindForPull.
To determine whether we need to ask for force pushing, we need to query the push
branch rather than the upstream branch, in case they are not the same.
@stefanhaller stefanhaller merged commit 6fcb7eb into master May 19, 2024
14 checks passed
@stefanhaller stefanhaller deleted the support-triangular-workflow branch May 19, 2024 08:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can I re-enable force pushing, or should I change my workflow?
2 participants