cms-git-tools icon indicating copy to clipboard operation
cms-git-tools copied to clipboard

Support the creation of a new branch before cherry-picking.

Open bfonta opened this issue 4 months ago • 10 comments

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).

bfonta avatar Sep 23 '25 16:09 bfonta

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

cmsbuild avatar Sep 23 '25 16:09 cmsbuild

cms-bot internal usage

cmsbuild avatar Sep 23 '25 16:09 cmsbuild

type ngt

bfonta avatar Sep 23 '25 16:09 bfonta

How about using -b and -B like git checkout ?

fwyzard avatar Sep 23 '25 22:09 fwyzard

Pull request #131 was updated.

cmsbuild avatar Sep 24 '25 08:09 cmsbuild

@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.

bfonta avatar Sep 24 '25 08:09 bfonta

man git switch
...
THIS COMMAND IS EXPERIMENTAL. THE BEHAVIOR MAY CHANGE.

fwyzard avatar Sep 24 '25 08:09 fwyzard

@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.

bfonta avatar Sep 24 '25 08:09 bfonta

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 :-)

fwyzard avatar Sep 24 '25 08:09 fwyzard

@smuzaffar Could you please open a cmsdist for tests?

bfonta avatar Oct 01 '25 10:10 bfonta