-
-
Notifications
You must be signed in to change notification settings - Fork 116
sync: support for amended branches #4586
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
Comments
Steps to reproduce the problem: # initialize repo
git init test
cd test
git commit --allow-empty -m "Initial commit"
# create branch feature1
git town hack feature1
echo "one" > file1
git add .
git commit -m "commit 1a"
# create child branch feature2
git town append feature2
echo "two" > file2
git add .
git commit -m "commit 2"
# amend the commit on branch1
git checkout feature1
echo "another one" > file1
git add .
git commit --amend -m "commit 1b"
# rebase branch feature2
git checkout feature2
git rebase feature1 This does indeed result in a merge conflict for <<<<<<< HEAD
another
one
>>>>>>> 0a250f0 (commit 1a) Here is the proposed alternative to rebasing, which avoids the merge conflict: # create a temporary branch that will become the new "feature2" branch
git checkout -b feature2-new feature1
# move the commits from the old feature2 branch over to the new feature2 branch
git cherry-pick [SHA of "commit2" on feature2]
# point the feature2 branch to the new commits on the temporary branch
git checkout feature2
git reset --hard feature2-new
# push the new commits to the tracking branch
git push --force-with-lease --force-if-includes
# delete the temporary branch
git branch -d feature2-new |
It's strange that this is necessary, given that a normal Git rebase is defined as "Reapply commits on top of another base tip", which is exactly what we do manually here. |
@kevgo Do you think Happy to contribute if you think we can add this work around into git-town.. |
We can "cherry-pick" just the commits we want with Steps reproducing the solution (diff from #4586 (comment)): # initialize repo
git init test
cd test
git commit --allow-empty -m "Initial commit"
# create branch feature1
git town hack feature1
echo "one" > file1
git add .
git commit -m "commit 1a"
# create child branch feature2
git town append feature2
echo "two" > file2
git add .
git commit -m "commit 2"
# amend the commit on branch1
+FEATURE1_OLD=$(git rev-parse feature1)
git checkout feature1
echo "another one" > file1
git add .
git commit --amend -m "commit 1b"
# rebase branch feature2
git checkout feature2
-git rebase feature1
+git rebase --onto feature1 $FEATURE1_OLD |
I tried with few more commits in feature1 and amended the commits using interactive rebase. The solution works. However I am not able to understand how will this work with |
For each branch, Git Town should track the parent's HEAD as well. That way, Git Town knows which commits are considered part of this branch, even if the parent's HEAD changes. I don't know enough about the internals to know whether this is already happening, but it should be possible. |
@kevgo do you think this can be to accommodated into I am happy to contribute if that is the case. Kindly let me know. |
This addresses the most widely requested open issue: #2223. It does so in a better way than earlier ideas, like #3179. Thanks @stephenwade for figuring out how to implement this idiomatically! 🙏 We finally have a solution good enough to add to Git Town, so let's build this. Git Town already tracks the last known SHA for each local and remote branch in its runstate file. You can see the content of the runstate file by executing All we have to do is modify the @pradeepmurugesan any help with Git Town would be greatly appreciated. Unfortunately, the sync algorithm is the most complex part of Git Town, so this ticket is the pretty much the polar opposite of a "good first issue". If you haven't already, please take a look at the developer documentation. The architecture document gives some background on the codebase. A good starting point is https://github.com/git-town/git-town/blob/main/internal/cmd/sync/sync_branch.go, which implements the logic to sync a Git branch. Please don't hesitate to reach out with any questions, no matter how big or small! |
I added an end-to-end test that documents the problematic behavior of the existing codebase: #4631 |
Thank you for the pointers. I will take a look and get back to you with questions. 👍 |
@kevgo I have a naive question regarding the tests.. I tried to run the end to end test to understand how the setup works.. I see the I added a print statement to the sync logic and tried running the test I don't see the logs I added getting printed, When I tried to debug the debug points were not hit. I tired following the Am I understanding this correctly ? If so is there anyway i can make these end to end tests execute the changes I made in the code ? Kindly clarify 🙏 |
Great questions—you're definitely on the right track! A few more details to round out the picture:
To run an end-to-end test and view your debug logs, please follow these steps:
That's the easiest way to debug. If you prefer to debug interactively in VSCode, please follow the instructions in https://github.com/git-town/git-town/blob/main/docs/DEVELOPMENT.md#debug-end-to-end-tests. And of course, if you have ideas for how we can make this process smoother or more intuitive, I’d love to hear them! |
If I have to amend an existing commit as shown in the example, I usually do manual Using the data from the runstate file and solving this automatically sounds perfect. But there is the caveat that running manual |
Hello @kevgo Thank you for responding.
Yes.. I tried uninstalling the local installation and ran
I am not sure if this is actually building the binary from the code base as I can see the tests are failing without a local installation. Am I missing something here ? I did a But I still cannot get the logs I added. I use the
I will try this.. The link says |
Interestingly when I try to run the binary manually I can see the print statements I added
But when I execute an end to end test the above logs are not present in the command output. 🤔
I tried to double check if the test is using the same binary by providing |
The error message is correct. You need to
8000
add |
Using |
Yes, the correct way to print in Go is |
The |
Thanks for all the pointers.. I tried debugging using the launch config in vs code.. I am able to get the debugging points only up until the subprocess execution starts and after the command is completed.. The debugger is gone when the actual command is invoked.. We cannot debug the binary execution in anyway is it ? I mean when the test_runner.go says |
Yes, the debugging setup is primarily intended for debugging the end-to-end tests themselves. They contain some complexity to speed up the suite. Debugging the Git Town executable that's invoked by the tests is probably a bit more involved. I haven’t really gone down that path, since I rarely use the debugger. The Git Town CLI already produces quite detailed output (especially with That said, one possible way to debug the Git Town executable as part of an end-to-end test could be:
That approach should work, but requires a fair bit of manual setup per debug session. Pradeep – thanks again for all your work on this. This ticket touches some of the most complex parts of Git Town, and will require updating around 100 end-to-end tests, which is no small task, and not a good first issue for working on this codebase. I’ve got some bandwidth now. Would it be alright with you if I took a stab at implementing this? If you're close to wrapping this up, I'm also happy to pick up something else from the backlog. Just let me know what you want to do here. Thanks! 🙂 |
ha ha. No not close at all. I am just scratching the surface :-) . Please feel free to implement this if you have bandwidth.. I will find something else to work on, may be a proper Thank you so much for being so considerate and helpful.. 🙏 |
Please keep scratching! 😃 Git Town can use some help, and the codebase is clean and fun to work on (at least that's one of the goals, haha). I have just tagged some good first issues. |
Update: This works correctly, even if the branches contain multiple commits and only the last commit gets amended. This test script works properly:
Output:
|
This also works correctly when changing a different commit than the last one in the branch, via interactive rebase. This test script works:
What this test script does is change the commit in the middle of Output:
At checkpoint 3, |
This also works correctly when squashing commits together via interactive rebase.
Output:
That's all the possible edge cases I can think of right now. This new way of syncing seems pretty robust and dependable. |
@pradeepmurugesan @stephenwade This is implemented but won't ship for a few more days. If you want, you can use this already by compiling the Git Town binary to use from source:
This would provide some real-world user testing before rolling this out to the tens of thousands of Git Town users worldwide. I don't use the rebase sync strategy, so I can't test this myself. Thanks! |
⚠️ **CAUTION: this is a major update, indicating a breaking change!**⚠️ This MR contains the following updates: | Package | Update | Change | |---|---|---| | [git-town/git-town](https://github.com/git-town/git-town) | major | `v18.3.2` -> `v20.1.0` | MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot). **Proposed changes to behavior should be submitted there as MRs.** --- ### Release Notes <details> <summary>git-town/git-town (git-town/git-town)</summary> ### [`v20.1.0`](https://github.com/git-town/git-town/releases/tag/v20.1.0) [Compare Source](git-town/git-town@v20.0.0...v20.1.0) ##### New Features - `git town compress` now has a `--no-verify` flag that disables Git's pre-commit hook ([#​4843](git-town/git-town#4843)). ##### Bug Fixes - `git town compress` now enforces that the branch to compress is in sync with its parent branch ([#​4845](git-town/git-town#4845)). - `git town sync` now doesn't remove commits of branches with deleted tracking branch if they don't have descendents ([#​4872](git-town/git-town#4872)). - Git Town no longer overrides the language of executed Git commands to US-English ([#​4861](git-town/git-town#4861)). ##### Contributors Shoutout to [@​AmitJoki](https://github.com/AmitJoki), [@​fcurella](https://github.com/fcurella), [@​haltcase](https://github.com/haltcase), [@​kevgo](https://github.com/kevgo), [@​lvlcn-t](https://github.com/lvlcn-t), [@​mw00120](https://github.com/mw00120), [@​niklastreml](https://github.com/niklastreml), [@​stephenwade](https://github.com/stephenwade) for contributing code, feedback, and ideas to 34 shipped MRs and 6 resolved issues! ### [`v20.0.0`](https://github.com/git-town/git-town/releases/tag/v20.0.0) [Compare Source](git-town/git-town@v19.0.0...v20.0.0) Git Town 2000! 🎉 ##### BREAKING CHANGES - The `push-new-branches` configuration option is now called `share-new-branches` and allows additional ways of sharing freshly created branches ([#​3912](git-town/git-town#3912)): - `no`: keep new branches local (default) - `push`: push new branches to the [development remote](https://www.git-town.com/preferences/dev-remote.html) - `propose`: automatically create proposals for new branches. This helps being maximally transparent with progress on each item worked on. - `git town propose` now always syncs the proposed branch, but always in [detached mode](https://www.git-town.com/commands/sync.html#-d--detached) mode ([#​4772](git-town/git-town#4772), [#​4781](git-town/git-town#4781)). - `git town propose` now longer has the `--detached` flag because it now always syncs in detached mode ([#​4775](git-town/git-town#4775)). ##### New Features - `git town sync` now correcly syncs branches whose commits got amended or rebased ([#​4586](git-town/git-town#4586)). - You can now propose all branches in a stack with `git town propose --stack` ([#​3840](git-town/git-town#3840)). - `git town propose` now un-parks parked branches when proposing them ([#​4780](git-town/git-town#4780)). - The [setup assistant](https://www.git-town.com/configuration.html) no longer asks for data already provided by the [Git Town configuration file](https://www.git-town.com/configuration-file.html) ([#​4710](git-town/git-town#4710)). - The setup assistant now offers to store forge API tokens globally for all repos on your machine ([#​4112](git-town/git-town#4112)). - [git town status reset](https://www.git-town.com/commands/status-reset.html) now indicates whether the runstate file existed ([#​4814](git-town/git-town#4814)). - [git town status reset](https://www.git-town.com/commands/status-reset.html) now supports the `--verbose` flag ([#​4813](git-town/git-town#4813)). ##### Bug Fixes - Git Town now correctly resolves `includeIf` directives in Git configuration ([#​4107](git-town/git-town#4107)). - `git town prepend --beam` now works correctly with prototype branches ([#​4768](git-town/git-town#4768)). - Git Town now loads the forge API token with the same precendence as other configuration data ([#​7428](git-town/git-town#4728)). - [git town undo](https://www.git-town.com/commands/undo.html) now correctly undoes situations where only the local part of a branch got renamed ([#​4794](git-town/git-town#4794)). - Git Town now works even if Git's `color.ui` setting is `always` ([#​4840](git-town/git-town#4840)). - The setup assistant now only updates the stored access token of the forge that is actually being used ([#​4819](git-town/git-town#4819)). - [git town status reset](https://www.git-town.com/commands/status-reset.html) can now be run from a subdirectory ([#​4812](git-town/git-town#4812)). ##### Contributors Git Town 2000 is a big release. Shoutout to [@​AmitJoki](https://github.com/AmitJoki), [@​Ydot19](https://github.com/Ydot19), [@​ahgraber](https://github.com/ahgraber), [@​davidolrik](https://github.com/davidolrik), [@​erik-rw](https://github.com/erik-rw), [@​haltcase](https://github.com/haltcase), [@​jmyers-figma](https://github.com/jmyers-figma), [@​judec-ps](https://github.com/judec-ps), [@​kevgo](https://github.com/kevgo), [@​lvlcn-t](https://github.com/lvlcn-t), [@​nekitk](https://github.com/nekitk), [@​niklastreml](https://github.com/niklastreml), [@​pradeepmurugesan](https://github.com/pradeepmurugesan), [@​ruudk](https://github.com/ruudk), [@​stephenwade](https://github.com/stephenwade), [@​terheyden](https://github.com/terheyden), [@​tharun208](https://github.com/tharun208) for contributing code, feedback, and ideas to 124 shipped MRs and 17 resolved issues! ### [`v19.0.0`](https://github.com/git-town/git-town/releases/tag/v19.0.0) [Compare Source](git-town/git-town@v18.3.2...v19.0.0) ##### BREAKING CHANGES - The commands `new-pull-request` and `rename-branch` are being sunset after being deprecated for a long time. Their modern replacements are `propose` and `rename` ([#​4714](git-town/git-town#4714)). - The configuration entries `contribution-branches`, `observed-branches`, `parked-branches`, and `prototype-branches` are being sunset. Their functionality is taken over by setting the type for individual branches as well as `contribution-regex`, `observed-regex`, `default-branch-type`, and `new-branch-type` ([#​4499](git-town/git-town#4499)). ##### New Features - `git town append` and `git town hack` now also have a `--beam` flag to move selected commits to the new branch. When enabled, they no longer fetch or sync, which allows you to move commits with the fewest possible distractions ([#​3338](git-town/git-town#3338)). - The "select commits to beam" dialog now displays the SHA of commits in addition to the commit message ([#​4519](git-town/git-town#4519)). - `set-parent` now allows providing the new parent as an optional positional CLI argument ([documentation](https://www.git-town.com/commands/set-parent.html#positional-argument), [#​4705](git-town/git-town#4705)). - The Git Town website now has a [how-to](https://www.git-town.com/how-tos.html) section. ##### Bug Fixes - `git town sync --no-push` no longer make the commit order appear out of order ([#​4696](git-town/git-town#4696)). ##### Contributors Shoutout to [@​erik-rw](https://github.com/erik-rw), [@​kevgo](https://github.com/kevgo), [@​legeana](https://github.com/legeana), [@​nekitk](https://github.com/nekitk), [@​pradeepmurugesan](https://github.com/pradeepmurugesan), [@​ruudk](https://github.com/ruudk), [@​stephenwade](https://github.com/stephenwade), [@​terheyden](https://github.com/terheyden) for contributing code, ideas, and feedback to 33 shipped MRs and 10 resolved issues! </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this MR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box --- This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0MC4xMS4yIiwidXBkYXRlZEluVmVyIjoiNDAuMTEuMiIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiUmVub3ZhdGUgQm90Il19-->
I have a branch
feature-1
, which has one commit.I create another branch
feature-2
on top offeature-1
usingappend
. Now my branch lineage looks like this.I do some change in
feature-1
, but instead of adding as a new commit, I amend the existing commit usingWhen I try to sync my stack it checks out
feature-2
and rebase withfeature-1
. Since I amended the commit infeature-1
, this will result in a merge conflict and I need to resolve.I usually don't change
feature-1
commits while working infeature-2
. Is it possible to add a flag to tweak this behaviour ? I mean when I sync the stack, can we remove the already existing parent commits in the child branch and perform a rebase ?In this case, when I sync the stack
Kindly let me know if you need more info.. I have created a repo to demo this.
just make sure the lineage is still present and the strategy is rebase. Perform the following
The text was updated successfully, but these errors were encountered: