{"thread":{"id":"25555","subject":"Create a new commit from patches without using any worktree?","startedAt":"2010-10-27T01:49:12Z","lastAt":"2010-10-27T15:20:32Z","messageCount":5,"participants":["Klas Lindberg","Jonathan Nieder","Johannes Sixt","Bert Wesarg"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"154471","messageId":"AANLkTi=Xi13_0+bC-TVRP3uVDmGWVdM3a708=SSzCR88@mail.gmail.com","threadId":"25555","inReplyTo":null,"subject":"Create a new commit from patches without using any worktree?","fromName":"Klas Lindberg","fromEmail":"klas.lindberg@gmail.com","sentAt":"2010-10-27T01:49:12Z","receivedAt":"2010-10-27T01:49:12Z","isPatch":false,"sender":{"key":"klas.lindberg@gmail.com","avatar":null},"body":"Hello\n\nIs there any way to record a new commit based on contents in a patch\nwithout going through a worktree? Of course the operation would have\nto fail if the patch does not apply cleanly. The problem is I find\nmyself doing things like this:\n\nput away current work on some branch A\ncheckout some branch B that is only used for patching\nrun git patch --check to see if patches apply cleanly. *reject* if\nnot. apply otherwise.\nreturn to branch A.\n\nI.e. the checkout of B is redundant because I'm anyway not going to\ntry to resolve any conflicts.\n\nI know I can do something similar to what I need with \"git-fetch\nsrc:dst\", except it's rather awkward if what you have is patches. I\nsuspect there must be some way to mimic that fetch behaviour manually,\nand in a way that lets me choose exactly what to apply?\n\nBR / Klas\n"},{"id":"154472","messageId":"20101027025816.GA1338@burratino","threadId":"25555","inReplyTo":"AANLkTi=Xi13_0+bC-TVRP3uVDmGWVdM3a708=SSzCR88@mail.gmail.com","subject":"Re: Create a new commit from patches without using any worktree?","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2010-10-27T02:58:16Z","receivedAt":"2010-10-27T02:58:16Z","isPatch":false,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Hi Klas,\n\nKlas Lindberg wrote:\n\n> Is there any way to record a new commit based on contents in a patch\n> without going through a worktree?\n\nNot sure if there a user-friendly way to do this, but if you are\nscripting, I'd suggest looking into \"git read-tree\", \"git apply\n--cached\", \"git write-tree\", \"git commit-tree\", and GIT_INDEX_FILE.\n\nHope that helps,\nJonathan\n"},{"id":"154485","messageId":"4CC7EBEA.9070804@viscovery.net","threadId":"25555","inReplyTo":"AANLkTi=Xi13_0+bC-TVRP3uVDmGWVdM3a708=SSzCR88@mail.gmail.com","subject":"Re: Create a new commit from patches without using any worktree?","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2010-10-27T09:07:54Z","receivedAt":"2010-10-27T09:07:54Z","isPatch":false,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 10/27/2010 3:49, schrieb Klas Lindberg:\n> Is there any way to record a new commit based on contents in a patch\n> without going through a worktree?\n\nThis script may be a starter. It takes a commit on the command line\ninstead of a patch, but it processes that commit as a patch (\"diff-tree -p\"),\nso the script should be easy to adapt.\n\n-- Hannes\n\n-- 8< --\n#!/bin/sh\n\nOPTIONS_SPEC=\"\\\ngit post to-ref [from-rev]\n--\n\"\n. git-sh-setup\n\nwhile test $# != 0\ndo\n\tcase \"$1\" in\n\t--)\tshift; break;;\n\t-*)\tusage;;\n\t*)\tbreak;;\n\tesac\n\tshift\ndone\n\nFROM=$(git rev-parse --verify --symbolic-full-name \"$1\") || exit\nshift\nif test $# = 0; then\n\tset -- HEAD\nfi\ntest $# = 1 || usage\n\n# populate a temporary index\ntmpidx=$GIT_DIR/index-post-$$\ngit read-tree --index-output=\"$tmpidx\" \"$FROM\" || exit\nGIT_INDEX_FILE=$tmpidx\nexport GIT_INDEX_FILE\ntrap 'rm -f \"$tmpidx\"' 0 1 2 15\n\ngit diff-tree -p -M -C \"$@\" | git apply --cached || exit\n\nnewtree=$(git write-tree) &&\nnewrev=$(\n\teval \"$(get_author_ident_from_commit \"$1\")\"\n\tgit-cat-file commit \"$1\" | sed -e '1,/^$/d' |\n\tgit commit-tree $newtree -p \"$FROM\"\n) || exit\n\nif git check-ref-format \"$FROM\"\nthen\n\tset_reflog_action post\n\tsubject=$(git log --no-walk --pretty=%s \"$newrev\") &&\n\tgit update-ref -m \"$GIT_REFLOG_ACTION: $subject\" \"$FROM\" $newrev || exit\nfi\nif test -z \"$GIT_QUIET\"\nthen\n\tgit rev-list -1 --oneline $newrev\nfi\n"},{"id":"154486","messageId":"AANLkTimykD+2Y9WKs2gXE+1Q2SS=5DaN+Kf4sW2dhegB@mail.gmail.com","threadId":"25555","inReplyTo":"4CC7EBEA.9070804@viscovery.net","subject":"Re: Create a new commit from patches without using any worktree?","fromName":"Bert Wesarg","fromEmail":"bert.wesarg@googlemail.com","sentAt":"2010-10-27T10:28:58Z","receivedAt":"2010-10-27T10:28:58Z","isPatch":false,"sender":{"key":"bert.wesarg@googlemail.com","avatar":"https://avatars.githubusercontent.com/u/111934?v=4"},"body":"On Wed, Oct 27, 2010 at 11:07, Johannes Sixt <j.sixt@viscovery.net> wrote:\n> Am 10/27/2010 3:49, schrieb Klas Lindberg:\n>> Is there any way to record a new commit based on contents in a patch\n>> without going through a worktree?\n>\n> This script may be a starter. It takes a commit on the command line\n> instead of a patch, but it processes that commit as a patch (\"diff-tree -p\"),\n> so the script should be easy to adapt.\n>\n> -- Hannes\n>\n> -- 8< --\n> #!/bin/sh\n>\n> OPTIONS_SPEC=\"\\\n> git post to-ref [from-rev]\n> --\n> \"\n> . git-sh-setup\n>\n> while test $# != 0\n> do\n>        case \"$1\" in\n>        --)     shift; break;;\n>        -*)     usage;;\n>        *)      break;;\n>        esac\n>        shift\n> done\n>\n> FROM=$(git rev-parse --verify --symbolic-full-name \"$1\") || exit\n> shift\n> if test $# = 0; then\n>        set -- HEAD\n> fi\n> test $# = 1 || usage\n>\n> # populate a temporary index\n> tmpidx=$GIT_DIR/index-post-$$\n\nI think you should honor GIT_INDEX_FILE here, so that you can\nguarantee that tmpidx is on the same device as the index file used by\ngit read-tree.\n\nBert\n\n> git read-tree --index-output=\"$tmpidx\" \"$FROM\" || exit\n> GIT_INDEX_FILE=$tmpidx\n> export GIT_INDEX_FILE\n> trap 'rm -f \"$tmpidx\"' 0 1 2 15\n>\n> git diff-tree -p -M -C \"$@\" | git apply --cached || exit\n>\n> newtree=$(git write-tree) &&\n> newrev=$(\n>        eval \"$(get_author_ident_from_commit \"$1\")\"\n>        git-cat-file commit \"$1\" | sed -e '1,/^$/d' |\n>        git commit-tree $newtree -p \"$FROM\"\n> ) || exit\n>\n> if git check-ref-format \"$FROM\"\n> then\n>        set_reflog_action post\n>        subject=$(git log --no-walk --pretty=%s \"$newrev\") &&\n>        git update-ref -m \"$GIT_REFLOG_ACTION: $subject\" \"$FROM\" $newrev || exit\n> fi\n> if test -z \"$GIT_QUIET\"\n> then\n>        git rev-list -1 --oneline $newrev\n> fi\n> --\n> To unsubscribe from this list: send the line \"unsubscribe git\" in\n> the body of a message to majordomo@vger.kernel.org\n> More majordomo info at  http://vger.kernel.org/majordomo-info.html\n>\n"},{"id":"154542","messageId":"AANLkTimX+j=9pHGb4kN_WsPw4ZO262XSwq5TiOBct6g6@mail.gmail.com","threadId":"25555","inReplyTo":"4CC7EBEA.9070804@viscovery.net","subject":"Re: Create a new commit from patches without using any worktree?","fromName":"Klas Lindberg","fromEmail":"klas.lindberg@gmail.com","sentAt":"2010-10-27T15:20:32Z","receivedAt":"2010-10-27T15:20:32Z","isPatch":false,"sender":{"key":"klas.lindberg@gmail.com","avatar":null},"body":"Ha! It works! Thank you so very very much. I've been trying to figure\nthis out on my own for a while.\n\nBR / Klas\n\nOn Wed, Oct 27, 2010 at 11:07 AM, Johannes Sixt <j.sixt@viscovery.net> wrote:\n> Am 10/27/2010 3:49, schrieb Klas Lindberg:\n>> Is there any way to record a new commit based on contents in a patch\n>> without going through a worktree?\n>\n> This script may be a starter. It takes a commit on the command line\n> instead of a patch, but it processes that commit as a patch (\"diff-tree -p\"),\n> so the script should be easy to adapt.\n>\n> -- Hannes\n>\n> -- 8< --\n> #!/bin/sh\n>\n> OPTIONS_SPEC=\"\\\n> git post to-ref [from-rev]\n> --\n> \"\n> . git-sh-setup\n>\n> while test $# != 0\n> do\n>        case \"$1\" in\n>        --)     shift; break;;\n>        -*)     usage;;\n>        *)      break;;\n>        esac\n>        shift\n> done\n>\n> FROM=$(git rev-parse --verify --symbolic-full-name \"$1\") || exit\n> shift\n> if test $# = 0; then\n>        set -- HEAD\n> fi\n> test $# = 1 || usage\n>\n> # populate a temporary index\n> tmpidx=$GIT_DIR/index-post-$$\n> git read-tree --index-output=\"$tmpidx\" \"$FROM\" || exit\n> GIT_INDEX_FILE=$tmpidx\n> export GIT_INDEX_FILE\n> trap 'rm -f \"$tmpidx\"' 0 1 2 15\n>\n> git diff-tree -p -M -C \"$@\" | git apply --cached || exit\n>\n> newtree=$(git write-tree) &&\n> newrev=$(\n>        eval \"$(get_author_ident_from_commit \"$1\")\"\n>        git-cat-file commit \"$1\" | sed -e '1,/^$/d' |\n>        git commit-tree $newtree -p \"$FROM\"\n> ) || exit\n>\n> if git check-ref-format \"$FROM\"\n> then\n>        set_reflog_action post\n>        subject=$(git log --no-walk --pretty=%s \"$newrev\") &&\n>        git update-ref -m \"$GIT_REFLOG_ACTION: $subject\" \"$FROM\" $newrev || exit\n> fi\n> if test -z \"$GIT_QUIET\"\n> then\n>        git rev-list -1 --oneline $newrev\n> fi\n>\n"}]}