{"thread":{"id":"18407","subject":"git am from scratch","startedAt":"2009-03-19T15:09:24Z","lastAt":"2009-03-20T04:39:22Z","messageCount":8,"participants":["Andreas Gruenbacher","Eric Raible","Jeff King","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"108532","messageId":"200903191609.24812.agruen@suse.de","threadId":"18407","inReplyTo":null,"subject":"git am from scratch","fromName":"Andreas Gruenbacher","fromEmail":"agruen@suse.de","sentAt":"2009-03-19T15:09:24Z","receivedAt":"2009-03-19T15:09:24Z","isPatch":false,"sender":{"key":"agruen@suse.de","avatar":null},"body":"Hello,\n\nlates git (e986ceb0): there is a bug in git am when trying to recreate the \nentire history of a repository:\n\n\t$ git format-patch --stdout rcs-history \\\n\t\t| ( rm -rf fOo && mkdir fOo && cd fOo && git init && git am )\n\tInitialized empty Git repository in /home/agruen/git/patch/foo/.git/\n\tfatal: HEAD: not a valid SHA1\n\tfatal: bad revision 'HEAD'\n\nWhen the first commit is added by hand instead, git am will import the rest of \nthe mbox without problems. This is annoying because it's at least not \nimmediately obvious how to recreate the initial commit with all the metadata.\n\nIs this easily fixed?\n\nThanks,\nAndreas\n"},{"id":"108545","messageId":"loom.20090319T161324-959@post.gmane.org","threadId":"18407","inReplyTo":"200903191609.24812.agruen@suse.de","subject":"Re: git am from scratch","fromName":"Eric Raible","fromEmail":"raible+git@gmail.com","sentAt":"2009-03-19T16:16:10Z","receivedAt":"2009-03-19T16:16:10Z","isPatch":false,"sender":{"key":"raible+git@gmail.com","avatar":null},"body":"Andreas Gruenbacher <agruen <at> suse.de> writes:\n\n> When the first commit is added by hand instead, git am will import the rest \n\nOr:\ngit init && git commit --allow-empty -m'initial'\n"},{"id":"108579","messageId":"20090319201817.GE17028@coredump.intra.peff.net","threadId":"18407","inReplyTo":"200903191609.24812.agruen@suse.de","subject":"Re: git am from scratch","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2009-03-19T20:18:17Z","receivedAt":"2009-03-19T20:18:17Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Mar 19, 2009 at 04:09:24PM +0100, Andreas Gruenbacher wrote:\n\n> lates git (e986ceb0): there is a bug in git am when trying to recreate the \n> entire history of a repository:\n\nI don't think this has ever worked in any version of git.\n\nIt might be nice to have, since it does come up once in a while, so I\nsuspect patches would be welcome.\n\nBut...\n\n> When the first commit is added by hand instead, git am will import the\n> rest of the mbox without problems. This is annoying because it's at\n> least not immediately obvious how to recreate the initial commit with\n> all the metadata.\n> \n> Is this easily fixed?\n\nThere are many other ways to do this. Have you tried:\n\n  - simply pulling the old repo into the new one?\n\n  - if they are not connected in real-time, creating a bundle from the\n    first and pulling it into the latter?\n\n  - if you want to tweak the commit data during the process, have you\n    tried using fast-export/fast-import rather than format-patch/am?\n\n-Peff\n"},{"id":"108582","messageId":"200903192142.49754.agruen@suse.de","threadId":"18407","inReplyTo":"20090319201817.GE17028@coredump.intra.peff.net","subject":"Re: git am from scratch","fromName":"Andreas Gruenbacher","fromEmail":"agruen@suse.de","sentAt":"2009-03-19T20:42:49Z","receivedAt":"2009-03-19T20:42:49Z","isPatch":false,"sender":{"key":"agruen@suse.de","avatar":null},"body":"On Thursday, 19 March 2009 21:18:17 Jeff King wrote:\n> I don't think this has ever worked in any version of git.\n\nI did find a way to help myself in the end. Still it was still a major, \nunnecessary annoyance.\n\nI ran into this problem when trying to reconstruct a project's history (after \ngoing RCS -> CVS -> git many things were still wrong like unrelated RCS files \nwhich ended up in the history, RCS files being moved to the Attic in the \noriginal tree to indicate deletes [which means they will happily live on from \na CVS point of view], etc.).\n\nThe easiest way I could find how to get rid of all the mess without going \ntotally insane was to git-format-patch the repository, fix up the major \nthings in the mbox, and then recreate the history.\n\nIn the end I ended up preparing the initial commit by hand followed \nby \"commit -c HASH\" to preserve the metadata. (The cvsimport branch had a \ndifferent commit at its tip, so I couldn't use commit --amend on that.) After \nthat, I git-am'ed the rest of the mbox onto that reconstructed commit. This \ncould have been significantly easier.\n\n> There are many other ways to do this.\n\nThat's really not the point. Thanks though.\n\nAndreas\n"},{"id":"108584","messageId":"20090319210214.GA17589@coredump.intra.peff.net","threadId":"18407","inReplyTo":"200903192142.49754.agruen@suse.de","subject":"Re: git am from scratch","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2009-03-19T21:02:14Z","receivedAt":"2009-03-19T21:02:14Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Mar 19, 2009 at 09:42:49PM +0100, Andreas Gruenbacher wrote:\n\n> > I don't think this has ever worked in any version of git.\n> I did find a way to help myself in the end. Still it was still a major, \n> unnecessary annoyance.\n\nSure, and that is why I suggested a patch for git-am might be welcome;\nit's not the right tool for the job, but it seems to be one that people\nnaturally think of.\n\n> I ran into this problem when trying to reconstruct a project's history (after \n> going RCS -> CVS -> git many things were still wrong like unrelated RCS files \n> which ended up in the history, RCS files being moved to the Attic in the \n> original tree to indicate deletes [which means they will happily live on from \n> a CVS point of view], etc.).\n\nYikes. Out of curiosity, what did you use to do the CVS import?\n\n\nAnyway, here is a not-very-well-tested patch to get \"git am\" to apply on\ntop of an empty repository (i.e., it worked on my utterly simplistic\ntest case and I didn't think too hard about what else might have been\nbroken). Maybe it will give a good start to somebody who wants to work\non this.\n\n---\ndiff --git a/git-am.sh b/git-am.sh\nindex d339075..bcc600d 100755\n--- a/git-am.sh\n+++ b/git-am.sh\n@@ -290,17 +290,23 @@ else\n \t\t: >\"$dotest/rebasing\"\n \telse\n \t\t: >\"$dotest/applying\"\n-\t\tgit update-ref ORIG_HEAD HEAD\n+\t\tif git rev-parse --quiet --verify HEAD; then\n+\t\t\tgit update-ref ORIG_HEAD HEAD\n+\t\telse\n+\t\t\trm -f \"$GIT_DIR/ORIG_HEAD\"\n+\t\tfi\n \tfi\n fi\n \n case \"$resolved\" in\n '')\n-\tfiles=$(git diff-index --cached --name-only HEAD --) || exit\n-\tif test \"$files\"\n-\tthen\n-\t\t: >\"$dotest/dirtyindex\"\n-\t\tdie \"Dirty index: cannot apply patches (dirty: $files)\"\n+\tif git rev-parse --quiet --verify HEAD; then\n+\t\tfiles=$(git diff-index --cached --name-only HEAD --) || exit\n+\t\tif test \"$files\"\n+\t\tthen\n+\t\t\t: >\"$dotest/dirtyindex\"\n+\t\t\tdie \"Dirty index: cannot apply patches (dirty: $files)\"\n+\t\tfi\n \tfi\n esac\n \n@@ -541,7 +547,7 @@ do\n \tfi\n \n \ttree=$(git write-tree) &&\n-\tparent=$(git rev-parse --verify HEAD) &&\n+\tparent=$(git rev-parse --quiet --verify HEAD)\n \tcommit=$(\n \t\tif test -n \"$ignore_date\"\n \t\tthen\n@@ -552,7 +558,7 @@ do\n \t\t\tGIT_COMMITTER_DATE=\"$GIT_AUTHOR_DATE\"\n \t\t\texport GIT_COMMITTER_DATE\n \t\tfi &&\n-\t\tgit commit-tree $tree -p $parent <\"$dotest/final-commit\"\n+\t\tgit commit-tree $tree ${parent:+-p $parent} <\"$dotest/final-commit\"\n \t) &&\n \tgit update-ref -m \"$GIT_REFLOG_ACTION: $FIRSTLINE\" HEAD $commit $parent ||\n \tstop_here $this\n"},{"id":"108599","messageId":"7vzlfh6uqn.fsf@gitster.siamese.dyndns.org","threadId":"18407","inReplyTo":"20090319210214.GA17589@coredump.intra.peff.net","subject":"Re: git am from scratch","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-03-19T21:57:52Z","receivedAt":"2009-03-19T21:57:52Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> Anyway, here is a not-very-well-tested patch to get \"git am\" to apply on\n> top of an empty repository (i.e., it worked on my utterly simplistic\n> test case and I didn't think too hard about what else might have been\n> broken). Maybe it will give a good start to somebody who wants to work\n> on this.\n\nThe patch gets the ball rolling in a right direction, I think.  In\naddition, you need to audit --abort and --skip codepaths carefully,\nthough.\n\n> diff --git a/git-am.sh b/git-am.sh\n> index d339075..bcc600d 100755\n> --- a/git-am.sh\n> +++ b/git-am.sh\n> @@ -290,17 +290,23 @@ else\n>  \t\t: >\"$dotest/rebasing\"\n>  \telse\n>  \t\t: >\"$dotest/applying\"\n> -\t\tgit update-ref ORIG_HEAD HEAD\n> +\t\tif git rev-parse --quiet --verify HEAD; then\n> +\t\t\tgit update-ref ORIG_HEAD HEAD\n> +\t\telse\n> +\t\t\trm -f \"$GIT_DIR/ORIG_HEAD\"\n> +\t\tfi\n>  \tfi\n>  fi\n>  \n>  case \"$resolved\" in\n>  '')\n> -\tfiles=$(git diff-index --cached --name-only HEAD --) || exit\n> -\tif test \"$files\"\n> -\tthen\n> -\t\t: >\"$dotest/dirtyindex\"\n> -\t\tdie \"Dirty index: cannot apply patches (dirty: $files)\"\n> +\tif git rev-parse --quiet --verify HEAD; then\n> +\t\tfiles=$(git diff-index --cached --name-only HEAD --) || exit\n> +\t\tif test \"$files\"\n> +\t\tthen\n> +\t\t\t: >\"$dotest/dirtyindex\"\n> +\t\t\tdie \"Dirty index: cannot apply patches (dirty: $files)\"\n> +\t\tfi\n>  \tfi\n>  esac\n>  \n> @@ -541,7 +547,7 @@ do\n>  \tfi\n>  \n>  \ttree=$(git write-tree) &&\n> -\tparent=$(git rev-parse --verify HEAD) &&\n> +\tparent=$(git rev-parse --quiet --verify HEAD)\n>  \tcommit=$(\n>  \t\tif test -n \"$ignore_date\"\n>  \t\tthen\n> @@ -552,7 +558,7 @@ do\n>  \t\t\tGIT_COMMITTER_DATE=\"$GIT_AUTHOR_DATE\"\n>  \t\t\texport GIT_COMMITTER_DATE\n>  \t\tfi &&\n> -\t\tgit commit-tree $tree -p $parent <\"$dotest/final-commit\"\n> +\t\tgit commit-tree $tree ${parent:+-p $parent} <\"$dotest/final-commit\"\n>  \t) &&\n>  \tgit update-ref -m \"$GIT_REFLOG_ACTION: $FIRSTLINE\" HEAD $commit $parent ||\n>  \tstop_here $this\n"},{"id":"108637","messageId":"200903200206.24555.agruen@suse.de","threadId":"18407","inReplyTo":"20090319210214.GA17589@coredump.intra.peff.net","subject":"Re: git am from scratch","fromName":"Andreas Gruenbacher","fromEmail":"agruen@suse.de","sentAt":"2009-03-20T01:06:24Z","receivedAt":"2009-03-20T01:06:24Z","isPatch":false,"sender":{"key":"agruen@suse.de","avatar":null},"body":"On Thursday, 19 March 2009 22:02:14 Jeff King wrote:\n> Yikes. Out of curiosity, what did you use to do the CVS import?\n\ngit-cvsimport\n\nAndreas\n"},{"id":"108649","messageId":"20090320043922.GB27160@coredump.intra.peff.net","threadId":"18407","inReplyTo":"200903200206.24555.agruen@suse.de","subject":"Re: git am from scratch","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2009-03-20T04:39:22Z","receivedAt":"2009-03-20T04:39:22Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Fri, Mar 20, 2009 at 02:06:24AM +0100, Andreas Gruenbacher wrote:\n\n> On Thursday, 19 March 2009 22:02:14 Jeff King wrote:\n> > Yikes. Out of curiosity, what did you use to do the CVS import?\n> \n> git-cvsimport\n\nAh. It sounds like you have already resolved all of your issues by\nmunging the resulting history, but you may have better success on a\ncomplex history with a different tool like cvs2git or parsecvs (even if\nyou have fixed it, you may want to investigate them to double-check your\nresult).\n\n-Peff\n"}]}