Support the creation of a new branch before cherry-picking.
Added an option to create a new branch before cherry-picking.
This is quite a common operation, for instance whenever starting from a clean release, in order not to loose the original clean from-CMSSW_... branch. The -c flag was chosen to replicate what git switch -c <branch> does. On top, AFAICT from the git cherry-pick documentation, the -c flag has no meaning for git cherry-pick.
The code contains logic to delete the new branch in case any later operation fails.
Tested manually under CMSSW_15_1_0_pre5. Validating it with a random non-existing commit activates the trap, and works as expected:
bfontana@sess-mi300x:/shared/PF_Validation/src (PF_Sim_Validation) $ /afs/cern.ch/user/b/bfontana/cms-git-tools/git-cms-cherry-pick -C NEW_BRANCH 111111111
Switched to a new branch 'NEW_BRANCH'
fatal: ambiguous argument '111111111': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
fatal: bad revision '111111111'
Switched to branch 'PF_Sim_Validation'
Deleted branch NEW_BRANCH (was 337299c6945).
A new Pull Request was created by @bfonta for branch master.
@akritkbehera, @cmsbuild, @iarspider, @smuzaffar can you please review it and eventually sign? Thanks. @ftenchini, @mandrenguyen, @sextonkennedy you are the release manager for this. cms-bot commands are listed here
cms-bot internal usage
type ngt
How about using -b and -B like git checkout ?
Pull request #131 was updated.
@fwyzard The -c choice was intentional: git currently favours the use of git switch and git restore over git checkout, and -c is the flag used in git switch to create a new branch.
On the other hand, I had not included the git switch -C option (equivalent to git checkout -B), which was now added.
man git switch
...
THIS COMMAND IS EXPERIMENTAL. THE BEHAVIOR MAY CHANGE.
@fwyzard I saw it, but it was already introduced in 2.23 (the latest is 2.51.0), and I feel the command is there to stay. Ultimately, it's a matter of preference, and I'm open to change it if needed.
No need to change it - I'm anyway not the target audience of this and most other cms-git tools, since I prefer to use the underlying git tools, since I know what they actually do :-)
@smuzaffar Could you please open a cmsdist for tests?