* Create a new commit from patches without using any worktree?
@ 2010-10-27 1:49 Klas Lindberg
2010-10-27 2:58 ` Jonathan Nieder
2010-10-27 9:07 ` Johannes Sixt
0 siblings, 2 replies; 5+ messages in thread
From: Klas Lindberg @ 2010-10-27 1:49 UTC (permalink / raw)
To: git
Hello
Is there any way to record a new commit based on contents in a patch
without going through a worktree? Of course the operation would have
to fail if the patch does not apply cleanly. The problem is I find
myself doing things like this:
put away current work on some branch A
checkout some branch B that is only used for patching
run git patch --check to see if patches apply cleanly. *reject* if
not. apply otherwise.
return to branch A.
I.e. the checkout of B is redundant because I'm anyway not going to
try to resolve any conflicts.
I know I can do something similar to what I need with "git-fetch
src:dst", except it's rather awkward if what you have is patches. I
suspect there must be some way to mimic that fetch behaviour manually,
and in a way that lets me choose exactly what to apply?
BR / Klas
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Create a new commit from patches without using any worktree?
2010-10-27 1:49 Create a new commit from patches without using any worktree? Klas Lindberg
@ 2010-10-27 2:58 ` Jonathan Nieder
2010-10-27 9:07 ` Johannes Sixt
1 sibling, 0 replies; 5+ messages in thread
From: Jonathan Nieder @ 2010-10-27 2:58 UTC (permalink / raw)
To: Klas Lindberg; +Cc: git
Hi Klas,
Klas Lindberg wrote:
> Is there any way to record a new commit based on contents in a patch
> without going through a worktree?
Not sure if there a user-friendly way to do this, but if you are
scripting, I'd suggest looking into "git read-tree", "git apply
--cached", "git write-tree", "git commit-tree", and GIT_INDEX_FILE.
Hope that helps,
Jonathan
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Create a new commit from patches without using any worktree?
2010-10-27 1:49 Create a new commit from patches without using any worktree? Klas Lindberg
2010-10-27 2:58 ` Jonathan Nieder
@ 2010-10-27 9:07 ` Johannes Sixt
2010-10-27 10:28 ` Bert Wesarg
2010-10-27 15:20 ` Klas Lindberg
1 sibling, 2 replies; 5+ messages in thread
From: Johannes Sixt @ 2010-10-27 9:07 UTC (permalink / raw)
To: Klas Lindberg; +Cc: git
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-$$
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Create a new commit from patches without using any worktree?
2010-10-27 9:07 ` Johannes Sixt
@ 2010-10-27 10:28 ` Bert Wesarg
2010-10-27 15:20 ` Klas Lindberg
1 sibling, 0 replies; 5+ messages in thread
From: Bert Wesarg @ 2010-10-27 10:28 UTC (permalink / raw)
To: Johannes Sixt; +Cc: Klas Lindberg, git
On Wed, Oct 27, 2010 at 11:07, Johannes Sixt <j.sixt@viscovery.net> 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@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Create a new commit from patches without using any worktree?
2010-10-27 9:07 ` Johannes Sixt
2010-10-27 10:28 ` Bert Wesarg
@ 2010-10-27 15:20 ` Klas Lindberg
1 sibling, 0 replies; 5+ messages in thread
From: Klas Lindberg @ 2010-10-27 15:20 UTC (permalink / raw)
To: Johannes Sixt; +Cc: git
Ha! It works! Thank you so very very much. I've been trying to figure
this out on my own for a while.
BR / Klas
On Wed, Oct 27, 2010 at 11:07 AM, Johannes Sixt <j.sixt@viscovery.net> 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-$$
> 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
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2010-10-27 15:20 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-10-27 1:49 Create a new commit from patches without using any worktree? Klas Lindberg
2010-10-27 2:58 ` Jonathan Nieder
2010-10-27 9:07 ` Johannes Sixt
2010-10-27 10:28 ` Bert Wesarg
2010-10-27 15:20 ` Klas Lindberg
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.