drewdeponte / git-ps-rs

Official git-ps Rust implementation - the future of git-ps
https://git-ps.sh
MIT License
78 stars 8 forks source link

Add gps import command #272

Open drewdeponte opened 10 months ago

drewdeponte commented 10 months ago

The idea with the gps import command is that you would be able to gps import -n <branch-name> and it would cherry pick the commits from that branch onto the top of your patch stack. Effectively, conceptually importing the patches from a branch into your patch stack. Duplicates would naturally collapse a way.

I think this should almost be a proxy command as I want to execute the external git cherry-pick command in range made. That way the conflict resolution, etc. is all standard to Git.

It won't actually be just a proxy as it has to do some analysis of the Git tree and figure out where the range of patches should start and where it should end so that we can pass those shas onto the git cherry-pick <start-exclusive-sha>..<end-sha-inclusive> or git cherry-pick <start-inclusive-sha>^..<end-sha-inclusive>.

This could be useful for the scenario where you have requested review of a patch and a co-worker has pushed up an additional commit to your rr branch. You likely would want to import the patches from that remote branch. This would import your own patch which would go away as a duplicate, but then it would also import the patch from your co-worker. This would then allow you to iterate on the patch to get a new version and ready and re-request review.

drewdeponte commented 10 months ago

Given the use case presented above, gps import <patch-index> might be a nice usage at least for the scenario where a branch is already associated with a patch. That way the user doesn't have think about the branch name.

We would also need to support gps import <ref-name> though so that we can import patches from other references.

drewdeponte commented 10 months ago

For reference, https://www.tollmanz.com/git-cherry-pick-range/ and https://stackoverflow.com/questions/35437253/how-to-git-cherrypick-all-changes-introduced-in-specific-branch

drewdeponte commented 10 months ago

Thinking about this some more. I think what this should do is actually find the common ancestor between the specified branch name (or associated branch when patch index is provided) and the currently checked out patch stack. Then it should present the list of patch that will be cherry picked if the user decides to continue by enterying y/yes when prompted. Any other value will abort the import.

The reason I think this is important is because if the user specifies a branch that wasn't directly based on the currently checked out patch stack, they wouldn't have any idea and it would import possible a large number of patches into the stack. So, I just think it is better to prompt the user to make sure they want to import the patches.