On Wed, Oct 27, 2010 at 11:07, Johannes Sixt <j.sixt@xxxxxxxxxxxxx> wrote: > Am 10/27/2010 3:49, schrieb Klas Lindberg: >> Is there any way to record a new commit based on contents in a patch >> without going through a worktree? > > This script may be a starter. It takes a commit on the command line > instead of a patch, but it processes that commit as a patch ("diff-tree -p"), > so the script should be easy to adapt. > > -- Hannes > > -- 8< -- > #!/bin/sh > > OPTIONS_SPEC="\ > git post to-ref [from-rev] > -- > " > . git-sh-setup > > while test $# != 0 > do > Â Â Â Âcase "$1" in > Â Â Â Â--) Â Â shift; break;; > Â Â Â Â-*) Â Â usage;; > Â Â Â Â*) Â Â Âbreak;; > Â Â Â Âesac > Â Â Â Âshift > done > > FROM=$(git rev-parse --verify --symbolic-full-name "$1") || exit > shift > if test $# = 0; then > Â Â Â Âset -- HEAD > fi > test $# = 1 || usage > > # populate a temporary index > tmpidx=$GIT_DIR/index-post-$$ I think you should honor GIT_INDEX_FILE here, so that you can guarantee that tmpidx is on the same device as the index file used by git read-tree. Bert > git read-tree --index-output="$tmpidx" "$FROM" || exit > GIT_INDEX_FILE=$tmpidx > export GIT_INDEX_FILE > trap 'rm -f "$tmpidx"' 0 1 2 15 > > git diff-tree -p -M -C "$@" | git apply --cached || exit > > newtree=$(git write-tree) && > newrev=$( > Â Â Â Âeval "$(get_author_ident_from_commit "$1")" > Â Â Â Âgit-cat-file commit "$1" | sed -e '1,/^$/d' | > Â Â Â Âgit commit-tree $newtree -p "$FROM" > ) || exit > > if git check-ref-format "$FROM" > then > Â Â Â Âset_reflog_action post > Â Â Â Âsubject=$(git log --no-walk --pretty=%s "$newrev") && > Â Â Â Âgit update-ref -m "$GIT_REFLOG_ACTION: $subject" "$FROM" $newrev || exit > fi > if test -z "$GIT_QUIET" > then > Â Â Â Âgit rev-list -1 --oneline $newrev > fi > -- > To unsubscribe from this list: send the line "unsubscribe git" in > the body of a message to majordomo@xxxxxxxxxxxxxxx > More majordomo info at Âhttp://vger.kernel.org/majordomo-info.html > -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html