Skip to Content.
Sympa Menu

sm-discuss - Re: [SM-Discuss] git: cherry-pick whole directories

sm-discuss AT lists.ibiblio.org

Subject: Public SourceMage Discussion List

List archive

Chronological Thread  
  • From: Jeremy Blosser <jblosser-smgl AT firinn.org>
  • To: sm-discuss AT lists.ibiblio.org
  • Subject: Re: [SM-Discuss] git: cherry-pick whole directories
  • Date: Sun, 21 Jan 2007 18:02:32 -0600

On Jan 22, Jaka Kranjc [lynx AT mages.ath.cx] wrote:
> Today I needed this p4 integration functionality too (and someone was
> bickering again), so after many git resets, here it is, a wrapper script
> that
> does just that in git. It takes a path argument and optionally an
> "upstream"
> branch. It is not interactive, but there is a slightly more powerful
> interactive version cat at the end, double commented.
>
> I'll add it to the wiki tommorow. Comments?

Hey, funny, I was thinking about this again this morning in the car after
the init.d integration I did yesterday. That wasn't a full integrate but
used pretty much the same approach so I was expecting this was the better
way to do it. Glad you saw the same conclusion.

There actually are potentially ways to have git do the diffing for you but
your approach is probably better since it's readable by bash gurus (instead
of just git gurus) and it's very clear what it is doing.

One thing I am not sure about is if it will work well enough when it runs
into the common HISTORY file conflicts. Your second one addresses that
explicitly; you might want to make the first check the return code of each
cherry-pick as well and stop when it hits a problem, or the results might
get ugly.

When I was thinking about it I was pondering going so far as to make it
read its own output for conflicts and automatically dump the user into
$EDITOR to fix things and then continue on (using update-index, etc.).
This is probably not _too_ hard to do if one of us wants to get time for
it.

Anyway thanks for being the one to write this up finally. Why not add it
to guru-tools as 'git-smgl-integrate' or something? A more advanced
version could probably even get accepted upstream.

> #START
> # cd yourself to your git repo
> # and checkout the target branch
>
> path=$1
> master=${2:-master}
> [[ -e $path ]] || { echo bad path: $path; exit 1; }
>
> cur_commits=$(git log --pretty=one-line -- $path | cut -d" " -f1)
> git log --pretty=one-line $master -- $path |
> cut -d" " -f1 |
> tac |
> while read commit; do
> if ! grep -q $commit <<< "$cur_commits"; then
> echo $commit
> fi
> done |
> while read commit; do
> git-cherry-pick $commit
> done
> #END
>
> # # # cd yourself to your git repo
> # # # and checkout the target branch
> # #
> # # path=$1
> # # master=${2:-master}
> # # [[ -e $path ]] || { echo bad path; exit 1; }
> # #
> # # git log $path
> # # # get the starting commit id with
> # # while [[ -z $starting_commit ]]; do
> # # git log $master -- $path
> # # echo
> # # read -p "Which is the starting commit of the pick? " starting_commit
> # # done
> # #
> # # git log --pretty=one-line $master -- $path |
> # # sed -n "1,/$starting_commit/ s,^\(\S*\).*$,\1,p" |
> # # tac |
> # # while read commit; do
> # # git-cherry-pick $commit || {
> # # echo
> # # echo fix the conflict, then restart me with the next commit after
> $commit
> # # exit 123; }
> # # done
>
> EXAMPLE:
> navaden@lynxlynx git $ ../dir-cherry-pick x11-libs/wine
> First trying simple merge strategy to cherry-pick.
> Finished one cherry-pick.
> First trying simple merge strategy to cherry-pick.
> Finished one cherry-pick.
> First trying simple merge strategy to cherry-pick.
> Finished one cherry-pick.
> First trying simple merge strategy to cherry-pick.
> Finished one cherry-pick.
> First trying simple merge strategy to cherry-pick.
> Finished one cherry-pick.
> First trying simple merge strategy to cherry-pick.
> Finished one cherry-pick.
> First trying simple merge strategy to cherry-pick.
> Finished one cherry-pick.
> First trying simple merge strategy to cherry-pick.
> Finished one cherry-pick.
> navaden@lynxlynx git $
>
> --
> We cannot command nature except by obeying her. --Sir Francis Bacon
> Have a sourcerous day! www.sourcemage.org



> _______________________________________________
> SM-Discuss mailing list
> SM-Discuss AT lists.ibiblio.org
> http://lists.ibiblio.org/mailman/listinfo/sm-discuss

Attachment: pgpJXuUqvV2uZ.pgp
Description: PGP signature




Archive powered by MHonArc 2.6.24.

Top of Page