cms-sw / cms-git-tools

CMS Git Helpers
34 stars 26 forks source link

Add cms-checkout-topic tool #79

Closed kpedro88 closed 7 years ago

kpedro88 commented 7 years ago

This adds cms-checkout-topic as a wrapper for a new --no-merge option in cms-merge-topic. This option is primarily intended to help with rebasing PRs, by allowing users to set up the modified packages and source code for a topic branch in a release area without doing a merge (which can cause 100s of duplicate commits).

Most of the functionality is duplicated from cms-merge-topic, so the new option is added there rather than making an entirely separate script. The cms-checkout-topic wrapper is added to have a more self-explanatory description of the command (however git-esque cms-merge-topic --no-merge might be...).

cmsbuild commented 7 years ago

A new Pull Request was created by @kpedro88 (Kevin Pedro) for branch master.

@cmsbuild, @smuzaffar, @iahmad-khan, @davidlange6 can you please review it and eventually sign? Thanks. You can sign-off by replying to this message having '+1' in the first line of your reply. You can reject by replying to this message having '-1' in the first line of your reply.

external issue cms-sw/cmsdist#2955

fwyzard commented 7 years ago

@kpedro88 some time ago I wrote an attempt to automatically backport a PR from one branch to another:

#! /bin/bash -e
OAUTH_TOKEN="869cfb0477e0cae72fb233be5e1f02bd97905bad"
REMOTE="git@github.com:cms-sw/cmssw.git"

PR=$1

# backport onto the given branch, or the current HEAD
if [ "$2" ] ; then
  BRANCH="$2"
else
  BRANCH=`git rev-parse --abbrev-ref HEAD`
fi

# remove any stale backport-attempt branch
git branch -D backport-attempt >& /dev/null || true

# identify what branch the original PR was meant for
MASTER=`curl -s -S -H "Authorization: token $OAUTH_TOKEN" "https://api.github.com/repos/cms-sw/cmssw/pulls/$PR" | python -c 'import sys, json; data = json.load(sys.stdin); print data["base"]["ref"]'`

# fetch the original branch
git fetch -n $REMOTE refs/heads/$MASTER:backport-from-$MASTER

# fetch the PR
git fetch -n $REMOTE refs/pull/$PR/head:backport-attempt

git rebase backport-from-$MASTER backport-attempt --onto $BRANCH 
git checkout $BRANCH
git reset --hard backport-attempt

I never had time to polish it and test it properly, but maybe you could use it a a starting point for something fancier.

cmsbuild commented 7 years ago

Pull request #79 was updated.

external issue cms-sw/cmsdist#2955

kpedro88 commented 7 years ago

@fwyzard thanks for the comments, I implemented most of them.

Your point about the -n option is well-taken. I tried to take a different approach now, so cms-merge-topic can automatically detect if it is being called by the no-merge wrapper cms-checkout-topic. I'm not sure if this is sufficiently portable, though...

kpedro88 commented 7 years ago

Also, I noticed that git-cms-sparse-checkout has a !/bin/sh shebang instead of !/bin/bash; should that be fixed?

smuzaffar commented 7 years ago

Now that cms-checkout-topic just calls cms-merge-topic, isn't it easier to just have it as a symlink. With symlink basename $0 | sed -e's/^git-//' should return the correct name.

kpedro88 commented 7 years ago

@smuzaffar good idea

cmsbuild commented 7 years ago

Pull request #79 was updated.

external issue cms-sw/cmsdist#2955

kpedro88 commented 7 years ago

@smuzaffar does this need to be tested somehow?

smuzaffar commented 7 years ago

yes, I will include it in DEVEL IBs after some local testing. Once tested in devel IBs, then I will include this for normal IBs

smuzaffar commented 7 years ago

@kpedro88 , can you please also add man page entry for new tools in https://github.com/cms-sw/cms-git-tools/tree/master/docs/man And may be update this tool recognize -h|--help option e.g. something like -h|--help) usage $COMMAND_NAME;; currently --help option fails with Unknown option --help

kpedro88 commented 7 years ago

@smuzaffar done

cmsbuild commented 7 years ago

Pull request #79 was updated.

external issue cms-sw/cmsdist#2955

cmsbuild commented 7 years ago

Pull request #79 was updated.

external issue cms-sw/cmsdist#2955