{"thread":{"id":"33302","subject":"Segfault with merge-tree on multiple Git versions","startedAt":"2013-03-27T15:29:29Z","lastAt":"2013-03-27T21:10:59Z","messageCount":15,"participants":["Charlie Smurthwaite","thomas","John Keeping","Thomas Rast","Junio C Hamano","Jed Brown","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"212384","messageId":"51531059.8000407@atechmedia.com","threadId":"33302","inReplyTo":null,"subject":"Segfault with merge-tree on multiple Git versions","fromName":"Charlie Smurthwaite","fromEmail":"charlie@atechmedia.com","sentAt":"2013-03-27T15:29:29Z","receivedAt":"2013-03-27T15:29:29Z","isPatch":false,"sender":{"key":"charlie@atechmedia.com","avatar":"https://gravatar.com/avatar/83817814225845900269596c70e728635467a6a1b79e7979172415eada51d124?d=mp&s=160"},"body":"I am experiencing a segmentation fault in various versions of Git using\ndifferent repositories. Specifically, I have reproduced it using a\npublic repo and the latest stable Git version. Other repos trigger the\nerror on different versions.\n\nFull info can be found below. Thanks,\n\nCharlie\n\n\nTest repository:\nhttps://github.com/atech/mail\n\nTest Command\ngit merge-tree 26bb22a052fef9f74063afd4fc6fc11fe200b19f\n8d6bdf012941d876b2279994e02f1bb0d5c26e7d\nd5ef97ac407d945f231cd7c8fb1cfe48b3a12083\n\nEnvironment:\nLinux codebase-staging 2.6.32-41-server #91-Ubuntu SMP Wed Jun 13\n11:58:56 UTC 2012 x86_64 GNU/Linux\n\nGit:\ngit version 1.8.2\n\nOutput:\ncharlie@codebase-staging:~/mail$ git merge-tree\n26bb22a052fef9f74063afd4fc6fc11fe200b19f\n8d6bdf012941d876b2279994e02f1bb0d5c26e7d\nd5ef97ac407d945f231cd7c8fb1cfe48b3a12083\nSegmentation fault\n\n\n\nCharlie Smurthwaite aTech Media\n\ntel. 01202 901 222 (ext. 603) email. charlie@atechmedia.com<mailto:charlie@atechmedia.com> web. atechmedia.com<http://atechmedia.com>\n\naTech Media Limited is a registered company in England and Wales. Registration Number 5523199. Registered Office: Unit 9 Winchester Place, North Street, Poole, Dorset, BH15 1NX. VAT Registration Number: GB 868 861 560. This e-mail is confidential and for the intended recipient only. If you are not the intended recipient, be advised that you have received this e-mail in error and that any use, dissemination, forwarding, printing, or copying of this e-mail is prohibited. If you have received this e-mail in error, please notify the sender.\n"},{"id":"212387","messageId":"87boa47saw.fsf@linux-k42r.v.cablecom.net","threadId":"33302","inReplyTo":"51531059.8000407@atechmedia.com","subject":"Re: Segfault with merge-tree on multiple Git versions","fromName":"thomas","fromEmail":"trast@student.ethz.ch","sentAt":"2013-03-27T15:53:27Z","receivedAt":"2013-03-27T15:53:27Z","isPatch":false,"sender":{"key":"tr@thomasrast.ch","avatar":"https://avatars.githubusercontent.com/u/153510?v=4"},"body":"Charlie Smurthwaite <charlie@atechmedia.com> writes:\n\n> I am experiencing a segmentation fault in various versions of Git using\n> different repositories. Specifically, I have reproduced it using a\n> public repo and the latest stable Git version. Other repos trigger the\n> error on different versions.\n>\n> Full info can be found below. Thanks,\n>\n> Charlie\n>\n>\n> Test repository:\n> https://github.com/atech/mail\n>\n> Test Command\n> git merge-tree 26bb22a052fef9f74063afd4fc6fc11fe200b19f\n> 8d6bdf012941d876b2279994e02f1bb0d5c26e7d\n> d5ef97ac407d945f231cd7c8fb1cfe48b3a12083\n\nI happened to walk past on IRC and found I could easily reproduce it, so\nI bisected:\n\n  35ffe7583108ab236dcf81226690388491d9962f is the first bad commit\n  commit 35ffe7583108ab236dcf81226690388491d9962f\n  Author: Junio C Hamano <gitster@pobox.com>\n  Date:   Thu Dec 13 15:51:29 2012 -0800\n\n      merge-tree: fix d/f conflicts\n      \n      The previous commit documented two known breakages revolving around\n      a case where one side flips a tree into a blob (or vice versa),\n      where the original code simply gets confused and feeds a mixture of\n      trees and blobs into either the recursive merge-tree (and recursing\n      into the blob will fail) or three-way merge (and merging tree contents\n      together with blobs will fail).\n      \n      Fix it by feeding trees (and only trees) into the recursive\n      merge-tree machinery and blobs (and only blobs) into the three-way\n      content level merge machinery separately; when this happens, the\n      entire merge has to be marked as conflicting at the structure level.\n      \n      Signed-off-by: Junio C Hamano <gitster@pobox.com>\n\nIt seems to be a vanilla null dereference:\n\n  Program received signal SIGSEGV, Segmentation fault.\n  0x0000000000453bf9 in add_merge_entry (entry=0x0) at builtin/merge-tree.c:24\n  24              *merge_result_end = entry;\n  (gdb) bt\n  #0  0x0000000000453bf9 in add_merge_entry (entry=0x0) at builtin/merge-tree.c:24\n  #1  0x00000000004545f4 in unresolved (info=0x7fffffffce90, n=0x7ff7f0) at builtin/merge-tree.c:265\n  #2  0x0000000000454741 in threeway_callback (n=3, mask=7, dirmask=7, entry=0x7ff7f0, \n      info=0x7fffffffce90) at builtin/merge-tree.c:330\n  #3  0x00000000005233f3 in traverse_trees (n=3, t=0x7fffffffcf10, info=0x7fffffffce90)\n      at tree-walk.c:407\n  #4  0x0000000000454792 in merge_trees_recursive (t=0x7fffffffcf10, base=0x800530 \"lib/mail\", \n      df_conflict=1) at builtin/merge-tree.c:341\n  #5  0x0000000000454382 in unresolved_directory (info=0x7fffffffd120, n=0x800420, df_conflict=1)\n      at builtin/merge-tree.c:216\n  #6  0x0000000000454507 in unresolved (info=0x7fffffffd120, n=0x800420) at builtin/merge-tree.c:253\n  #7  0x0000000000454741 in threeway_callback (n=3, mask=7, dirmask=7, entry=0x800420, \n      info=0x7fffffffd120) at builtin/merge-tree.c:330\n  #8  0x00000000005233f3 in traverse_trees (n=3, t=0x7fffffffd1a0, info=0x7fffffffd120)\n      at tree-walk.c:407\n  #9  0x0000000000454792 in merge_trees_recursive (t=0x7fffffffd1a0, base=0x7fd170 \"lib\", df_conflict=1)\n      at builtin/merge-tree.c:341\n  #10 0x0000000000454382 in unresolved_directory (info=0x7fffffffd3b0, n=0x8069f0, df_conflict=1)\n      at builtin/merge-tree.c:216\n  #11 0x0000000000454507 in unresolved (info=0x7fffffffd3b0, n=0x8069f0) at builtin/merge-tree.c:253\n  #12 0x0000000000454741 in threeway_callback (n=3, mask=7, dirmask=7, entry=0x8069f0, \n      info=0x7fffffffd3b0) at builtin/merge-tree.c:330\n  #13 0x00000000005233f3 in traverse_trees (n=3, t=0x7fffffffd450, info=0x7fffffffd3b0)\n      at tree-walk.c:407\n  #14 0x0000000000454792 in merge_trees_recursive (t=0x7fffffffd450, base=0x5510fc \"\", df_conflict=0)\n      at builtin/merge-tree.c:341\n  #15 0x00000000004547bc in merge_trees (t=0x7fffffffd450, base=0x5510fc \"\") at builtin/merge-tree.c:346\n  #16 0x00000000004548ef in cmd_merge_tree (argc=4, argv=0x7fffffffd728, prefix=0x0)\n      at builtin/merge-tree.c:373\n  #17 0x00000000004056ec in run_builtin (p=0x7a1c88 <commands.20888+1416>, argc=4, argv=0x7fffffffd728)\n      at git.c:273\n  #18 0x000000000040587f in handle_internal_command (argc=4, argv=0x7fffffffd728) at git.c:434\n  #19 0x0000000000405a4b in main (argc=4, argv=0x7fffffffd728) at git.c:523\n\nUnfortunately I'm not familiar with the merge code, but if you can't\nreproduce at your end let me know.\n\n-- \nThomas Rast\ntrast@{inf,student}.ethz.ch\n"},{"id":"212388","messageId":"20130327155850.GN2286@serenity.lan","threadId":"33302","inReplyTo":"87boa47saw.fsf@linux-k42r.v.cablecom.net","subject":"Re: Segfault with merge-tree on multiple Git versions","fromName":"John Keeping","fromEmail":"john@keeping.me.uk","sentAt":"2013-03-27T15:58:50Z","receivedAt":"2013-03-27T15:58:50Z","isPatch":false,"sender":{"key":"john@keeping.me.uk","avatar":"https://avatars.githubusercontent.com/u/1702081?v=4"},"body":"On Wed, Mar 27, 2013 at 04:53:27PM +0100, thomas wrote:\n> Charlie Smurthwaite <charlie@atechmedia.com> writes:\n> \n> > I am experiencing a segmentation fault in various versions of Git using\n> > different repositories. Specifically, I have reproduced it using a\n> > public repo and the latest stable Git version. Other repos trigger the\n> > error on different versions.\n> >\n> > Full info can be found below. Thanks,\n> >\n> > Charlie\n> >\n> >\n> > Test repository:\n> > https://github.com/atech/mail\n> >\n> > Test Command\n> > git merge-tree 26bb22a052fef9f74063afd4fc6fc11fe200b19f\n> > 8d6bdf012941d876b2279994e02f1bb0d5c26e7d\n> > d5ef97ac407d945f231cd7c8fb1cfe48b3a12083\n> \n> I happened to walk past on IRC and found I could easily reproduce it, so\n> I bisected:\n> \n>   35ffe7583108ab236dcf81226690388491d9962f is the first bad commit\n>   commit 35ffe7583108ab236dcf81226690388491d9962f\n>   Author: Junio C Hamano <gitster@pobox.com>\n>   Date:   Thu Dec 13 15:51:29 2012 -0800\n> \n>       merge-tree: fix d/f conflicts\n>       \n>       The previous commit documented two known breakages revolving around\n>       a case where one side flips a tree into a blob (or vice versa),\n>       where the original code simply gets confused and feeds a mixture of\n>       trees and blobs into either the recursive merge-tree (and recursing\n>       into the blob will fail) or three-way merge (and merging tree contents\n>       together with blobs will fail).\n>       \n>       Fix it by feeding trees (and only trees) into the recursive\n>       merge-tree machinery and blobs (and only blobs) into the three-way\n>       content level merge machinery separately; when this happens, the\n>       entire merge has to be marked as conflicting at the structure level.\n>       \n>       Signed-off-by: Junio C Hamano <gitster@pobox.com>\n\nLooks like a simple typo in merge-tree.c::unresolved:\n\n-- >8 --\nmerge-tree: fix typo in merge-tree.c::unresolved\n\nWhen calculating whether there is a d/f conflict, the calculation of\nwhether both sides are directories generates an incorrect references\nmask because it does not use the loop index to set the correct bit.\nFix this typo.\n\nSigned-off-by: John Keeping <john@keeping.me.uk>\n\ndiff --git a/builtin/merge-tree.c b/builtin/merge-tree.c\nindex e0d0b7d..bc912e3 100644\n--- a/builtin/merge-tree.c\n+++ b/builtin/merge-tree.c\n@@ -245,7 +245,7 @@ static void unresolved(const struct traverse_info *info, struct name_entry n[3])\n \tunsigned dirmask = 0, mask = 0;\n \n \tfor (i = 0; i < 3; i++) {\n-\t\tmask |= (1 << 1);\n+\t\tmask |= (1 << i);\n \t\tif (n[i].mode && S_ISDIR(n[i].mode))\n \t\t\tdirmask |= (1 << i);\n \t}\n"},{"id":"212390","messageId":"874nfw7rrm.fsf@linux-k42r.v.cablecom.net","threadId":"33302","inReplyTo":"20130327155850.GN2286@serenity.lan","subject":"Re: Segfault with merge-tree on multiple Git versions","fromName":"Thomas Rast","fromEmail":"trast@inf.ethz.ch","sentAt":"2013-03-27T16:05:01Z","receivedAt":"2013-03-27T16:05:01Z","isPatch":false,"sender":{"key":"tr@thomasrast.ch","avatar":"https://avatars.githubusercontent.com/u/153510?v=4"},"body":"John Keeping <john@keeping.me.uk> writes:\n\n> merge-tree: fix typo in merge-tree.c::unresolved\n>\n> When calculating whether there is a d/f conflict, the calculation of\n> whether both sides are directories generates an incorrect references\n> mask because it does not use the loop index to set the correct bit.\n> Fix this typo.\n>\n> Signed-off-by: John Keeping <john@keeping.me.uk>\n>\n> diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c\n> index e0d0b7d..bc912e3 100644\n> --- a/builtin/merge-tree.c\n> +++ b/builtin/merge-tree.c\n> @@ -245,7 +245,7 @@ static void unresolved(const struct traverse_info *info, struct name_entry n[3])\n>  \tunsigned dirmask = 0, mask = 0;\n>  \n>  \tfor (i = 0; i < 3; i++) {\n> -\t\tmask |= (1 << 1);\n> +\t\tmask |= (1 << i);\n>  \t\tif (n[i].mode && S_ISDIR(n[i].mode))\n>  \t\t\tdirmask |= (1 << i);\n>  \t}\n\nIndeed, that fixes it.\n\n-- \nThomas Rast\ntrast@{inf,student}.ethz.ch\n"},{"id":"212399","messageId":"7v1ub0ol91.fsf@alter.siamese.dyndns.org","threadId":"33302","inReplyTo":"20130327155850.GN2286@serenity.lan","subject":"Re: Segfault with merge-tree on multiple Git versions","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-03-27T16:33:46Z","receivedAt":"2013-03-27T16:33:46Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"John Keeping <john@keeping.me.uk> writes:\n\n> Looks like a simple typo in merge-tree.c::unresolved:\n\nThanks.\n\n>\n> -- >8 --\n> merge-tree: fix typo in merge-tree.c::unresolved\n>\n> When calculating whether there is a d/f conflict, the calculation of\n> whether both sides are directories generates an incorrect references\n> mask because it does not use the loop index to set the correct bit.\n> Fix this typo.\n>\n> Signed-off-by: John Keeping <john@keeping.me.uk>\n>\n> diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c\n> index e0d0b7d..bc912e3 100644\n> --- a/builtin/merge-tree.c\n> +++ b/builtin/merge-tree.c\n> @@ -245,7 +245,7 @@ static void unresolved(const struct traverse_info *info, struct name_entry n[3])\n>  \tunsigned dirmask = 0, mask = 0;\n>  \n>  \tfor (i = 0; i < 3; i++) {\n> -\t\tmask |= (1 << 1);\n> +\t\tmask |= (1 << i);\n>  \t\tif (n[i].mode && S_ISDIR(n[i].mode))\n>  \t\t\tdirmask |= (1 << i);\n>  \t}\n"},{"id":"212407","messageId":"7vsj3gn55b.fsf@alter.siamese.dyndns.org","threadId":"33302","inReplyTo":"51531059.8000407@atechmedia.com","subject":"Re: Segfault with merge-tree on multiple Git versions","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-03-27T17:06:56Z","receivedAt":"2013-03-27T17:06:56Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Charlie Smurthwaite <charlie@atechmedia.com> writes:\n\n> I am experiencing a segmentation fault in various versions of Git using\n> different repositories.\n> ...\n> Test Command\n> git merge-tree 26bb22a052fef9f74063afd4fc6fc11fe200b19f\n> 8d6bdf012941d876b2279994e02f1bb0d5c26e7d\n> d5ef97ac407d945f231cd7c8fb1cfe48b3a12083\n\nThanks for a report (and thanks to John and Thomas for finding the\ntypo).\n\nNobody I know uses merge-tree; the last real change we did was back\nfrom July 2010, and the only reason I was looking at it recently was\nbecause I was planning to write a new merge strategy using it.\n\nMind if I ask what you are using it for?\n"},{"id":"212410","messageId":"5153298C.8020107@atechmedia.com","threadId":"33302","inReplyTo":"7vsj3gn55b.fsf@alter.siamese.dyndns.org","subject":"Re: Segfault with merge-tree on multiple Git versions","fromName":"Charlie Smurthwaite","fromEmail":"charlie@atechmedia.com","sentAt":"2013-03-27T17:17:00Z","receivedAt":"2013-03-27T17:17:00Z","isPatch":false,"sender":{"key":"charlie@atechmedia.com","avatar":"https://gravatar.com/avatar/83817814225845900269596c70e728635467a6a1b79e7979172415eada51d124?d=mp&s=160"},"body":"On 27/03/13 17:06, Junio C Hamano wrote:\n> Charlie Smurthwaite <charlie@atechmedia.com> writes:\n>\n>> I am experiencing a segmentation fault in various versions of Git using\n>> different repositories.\n>> ...\n>> Test Command\n>> git merge-tree 26bb22a052fef9f74063afd4fc6fc11fe200b19f\n>> 8d6bdf012941d876b2279994e02f1bb0d5c26e7d\n>> d5ef97ac407d945f231cd7c8fb1cfe48b3a12083\n> Thanks for a report (and thanks to John and Thomas for finding the\n> typo).\n>\n> Nobody I know uses merge-tree; the last real change we did was back\n> from July 2010, and the only reason I was looking at it recently was\n> because I was planning to write a new merge strategy using it.\n>\n> Mind if I ask what you are using it for?\nThank you everybody for investigating this and creating a patch. Can I \nassume that this fix will reach somebody who can apply it to master?\n\nWith regard our use, we run an SCM hosting service http://codebasehq.com \nand are in the process of deploying a merge-request feature. We use \ngit-merge-tree to determine whether a Git merge can be completed \nautomatically (without manual conflict resolution), and if so offer the \nuser a button to execute an actual merge. If there is a better way to do \nthis, I'd be happy to consider it.\n\nCharlie\n"},{"id":"212418","messageId":"515331F2.3060703@atechmedia.com","threadId":"33302","inReplyTo":"7vsj3gn55b.fsf@alter.siamese.dyndns.org","subject":"Re: Segfault with merge-tree on multiple Git versions","fromName":"Charlie Smurthwaite","fromEmail":"charlie@atechmedia.com","sentAt":"2013-03-27T17:52:50Z","receivedAt":"2013-03-27T17:52:50Z","isPatch":false,"sender":{"key":"charlie@atechmedia.com","avatar":"https://gravatar.com/avatar/83817814225845900269596c70e728635467a6a1b79e7979172415eada51d124?d=mp&s=160"},"body":"On 27/03/13 17:06, Junio C Hamano wrote:\n> Charlie Smurthwaite <charlie@atechmedia.com> writes:\n>\n>> I am experiencing a segmentation fault in various versions of Git using\n>> different repositories.\n>> ...\n>> Test Command\n>> git merge-tree 26bb22a052fef9f74063afd4fc6fc11fe200b19f\n>> 8d6bdf012941d876b2279994e02f1bb0d5c26e7d\n>> d5ef97ac407d945f231cd7c8fb1cfe48b3a12083\n> Thanks for a report (and thanks to John and Thomas for finding the\n> typo).\n>\n> Nobody I know uses merge-tree; the last real change we did was back\n> from July 2010, and the only reason I was looking at it recently was\n> because I was planning to write a new merge strategy using it.\n>\n> Mind if I ask what you are using it for?\n\nI am also using this to obtain a diff that would be applied if a merge \nwere to be run. Is there a better way to obtain this information that is \nmore commonly used?\n"},{"id":"212420","messageId":"874nfw4t0r.fsf@59A2.org","threadId":"33302","inReplyTo":"515331F2.3060703@atechmedia.com","subject":"Re: Segfault with merge-tree on multiple Git versions","fromName":"Jed Brown","fromEmail":"jed@59a2.org","sentAt":"2013-03-27T18:06:12Z","receivedAt":"2013-03-27T18:06:12Z","isPatch":false,"sender":{"key":"jed@59a2.org","avatar":"https://gravatar.com/avatar/1391d04d82555f9058a9fdf5eead233e909a48e40480db31fc554e7afeb301da?d=mp&s=160"},"body":"Charlie Smurthwaite <charlie@atechmedia.com> writes:\n\n> I am also using this to obtain a diff that would be applied if a merge \n> were to be run. Is there a better way to obtain this information that is \n> more commonly used?\n\nYou can do an actual merge using detached HEAD:\n\n  $ git checkout --detach upstream-branch\n  $ git merge topic-branch\n\nThis has the benefit that if there are conflicts, you can resolve them\nhere and commit the result so that rerere can auto-resolve them later.\n\nAre you looking for something that can be run in a bare repo?\n"},{"id":"212426","messageId":"51533E8D.5050206@atechmedia.com","threadId":"33302","inReplyTo":"874nfw4t0r.fsf@59A2.org","subject":"Re: Segfault with merge-tree on multiple Git versions","fromName":"Charlie Smurthwaite","fromEmail":"charlie@atechmedia.com","sentAt":"2013-03-27T18:46:37Z","receivedAt":"2013-03-27T18:46:37Z","isPatch":false,"sender":{"key":"charlie@atechmedia.com","avatar":"https://gravatar.com/avatar/83817814225845900269596c70e728635467a6a1b79e7979172415eada51d124?d=mp&s=160"},"body":"On 27/03/13 18:06, Jed Brown wrote:\n> Charlie Smurthwaite <charlie@atechmedia.com> writes:\n>\n>> I am also using this to obtain a diff that would be applied if a merge\n>> were to be run. Is there a better way to obtain this information that is\n>> more commonly used?\n> You can do an actual merge using detached HEAD:\n>\n>    $ git checkout --detach upstream-branch\n>    $ git merge topic-branch\n>\n> This has the benefit that if there are conflicts, you can resolve them\n> here and commit the result so that rerere can auto-resolve them later.\n>\n> Are you looking for something that can be run in a bare repo?\n\nYes, I would need to be able to do this on a bare repo for my use case. \nThanks!\n"},{"id":"212434","messageId":"87zjxo3b7b.fsf@59A2.org","threadId":"33302","inReplyTo":"51533E8D.5050206@atechmedia.com","subject":"Re: Segfault with merge-tree on multiple Git versions","fromName":"Jed Brown","fromEmail":"jed@59a2.org","sentAt":"2013-03-27T19:16:24Z","receivedAt":"2013-03-27T19:16:24Z","isPatch":false,"sender":{"key":"jed@59a2.org","avatar":"https://gravatar.com/avatar/1391d04d82555f9058a9fdf5eead233e909a48e40480db31fc554e7afeb301da?d=mp&s=160"},"body":"Charlie Smurthwaite <charlie@atechmedia.com> writes:\n\n> Yes, I would need to be able to do this on a bare repo for my use case. \n\nAnd if it's on the server, you don't want this to be observable, so\nyou don't want HEAD to move around. I don't know a better way than:\n\n  $ git clone --shared -b upstream-branch bare-repo.git /tmp/merge-repo\n  $ cd /tmp/merge-repo\n  $ git pull URL incoming-branch\n\nCloning with --shared just writes a path into .git/objects/info/alternatives\nand it doesn't need to be on the same file system (unlike --local).\n\nSince 'git merge-tree' just works with trees, it has less information\nthan 'git merge'.\n"},{"id":"212438","messageId":"20130327194521.GQ2286@serenity.lan","threadId":"33302","inReplyTo":"87zjxo3b7b.fsf@59A2.org","subject":"Re: Segfault with merge-tree on multiple Git versions","fromName":"John Keeping","fromEmail":"john@keeping.me.uk","sentAt":"2013-03-27T19:45:21Z","receivedAt":"2013-03-27T19:45:21Z","isPatch":false,"sender":{"key":"john@keeping.me.uk","avatar":"https://avatars.githubusercontent.com/u/1702081?v=4"},"body":"On Wed, Mar 27, 2013 at 02:16:24PM -0500, Jed Brown wrote:\n> Charlie Smurthwaite <charlie@atechmedia.com> writes:\n> \n> > Yes, I would need to be able to do this on a bare repo for my use case. \n> \n> And if it's on the server, you don't want this to be observable, so\n> you don't want HEAD to move around. I don't know a better way than:\n> \n>   $ git clone --shared -b upstream-branch bare-repo.git /tmp/merge-repo\n>   $ cd /tmp/merge-repo\n>   $ git pull URL incoming-branch\n> \n> Cloning with --shared just writes a path into .git/objects/info/alternatives\n> and it doesn't need to be on the same file system (unlike --local).\n> \n> Since 'git merge-tree' just works with trees, it has less information\n> than 'git merge'.\n\nYou could use a temporary index and do something like:\n\n\trm -f TMP_INDEX\n\tGIT_INDEX_FILE=TMP_INDEX\n\texport GIT_INDEX_FILE\n\tgit read-tree -m $base $ours $theirs &&\n\tgit merge-index git-merge-one-file -a\n\nthen inspect that with \"git diff-index --cached $ours\".\n\nNote that this will fail if there are conflicts and I don't know what\ngit-merge-tree will do in that case.\n"},{"id":"212441","messageId":"20130327200113.GC26380@sigill.intra.peff.net","threadId":"33302","inReplyTo":"20130327194521.GQ2286@serenity.lan","subject":"Re: Segfault with merge-tree on multiple Git versions","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2013-03-27T20:01:13Z","receivedAt":"2013-03-27T20:01:13Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, Mar 27, 2013 at 07:45:21PM +0000, John Keeping wrote:\n\n> On Wed, Mar 27, 2013 at 02:16:24PM -0500, Jed Brown wrote:\n> > Charlie Smurthwaite <charlie@atechmedia.com> writes:\n> > \n> > > Yes, I would need to be able to do this on a bare repo for my use case. \n> > \n> > And if it's on the server, you don't want this to be observable, so\n> > you don't want HEAD to move around. I don't know a better way than:\n> > \n> >   $ git clone --shared -b upstream-branch bare-repo.git /tmp/merge-repo\n> >   $ cd /tmp/merge-repo\n> >   $ git pull URL incoming-branch\n> > \n> > Cloning with --shared just writes a path into .git/objects/info/alternatives\n> > and it doesn't need to be on the same file system (unlike --local).\n> > \n> > Since 'git merge-tree' just works with trees, it has less information\n> > than 'git merge'.\n> \n> You could use a temporary index and do something like:\n> \n> \trm -f TMP_INDEX\n> \tGIT_INDEX_FILE=TMP_INDEX\n> \texport GIT_INDEX_FILE\n> \tgit read-tree -m $base $ours $theirs &&\n> \tgit merge-index git-merge-one-file -a\n> \n> then inspect that with \"git diff-index --cached $ours\".\n\nThat is precisely how we do it at GitHub. You probably want to add in\n\"--aggressive\" to your read-tree to cover a few more simple cases. If\nthere are conflicts, we just bail and say \"this can't be merged\", and\nexpect the user to do it themselves using git.\n\n-Peff\n"},{"id":"212445","messageId":"7vtxnwlidq.fsf@alter.siamese.dyndns.org","threadId":"33302","inReplyTo":"20130327194521.GQ2286@serenity.lan","subject":"Re: Segfault with merge-tree on multiple Git versions","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-03-27T20:04:01Z","receivedAt":"2013-03-27T20:04:01Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"John Keeping <john@keeping.me.uk> writes:\n\n> You could use a temporary index and do something like:\n>\n> \trm -f TMP_INDEX\n> \tGIT_INDEX_FILE=TMP_INDEX\n> \texport GIT_INDEX_FILE\n> \tgit read-tree -m $base $ours $theirs &&\n> \tgit merge-index git-merge-one-file -a\n>\n> then inspect that with \"git diff-index --cached $ours\".\n\nGood.\n\n> Note that this will fail if there are conflicts and I don't know what\n> git-merge-tree will do in that case.\n\nI _think_ Charlies's use case is to detect trivial merges to tell\nthe requestee that a merge request can be done on site, so failing\nis fine when there are conflicts.  merge-tree should report\nconflicts as well.\n"},{"id":"212458","messageId":"51536063.50405@atechmedia.com","threadId":"33302","inReplyTo":"20130327200113.GC26380@sigill.intra.peff.net","subject":"Re: Segfault with merge-tree on multiple Git versions","fromName":"Charlie Smurthwaite","fromEmail":"charlie@atechmedia.com","sentAt":"2013-03-27T21:10:59Z","receivedAt":"2013-03-27T21:10:59Z","isPatch":false,"sender":{"key":"charlie@atechmedia.com","avatar":"https://gravatar.com/avatar/83817814225845900269596c70e728635467a6a1b79e7979172415eada51d124?d=mp&s=160"},"body":"On 27/03/13 20:01, Jeff King wrote:\n> On Wed, Mar 27, 2013 at 07:45:21PM +0000, John Keeping wrote:\n>\n>> On Wed, Mar 27, 2013 at 02:16:24PM -0500, Jed Brown wrote:\n>>> Charlie Smurthwaite <charlie@atechmedia.com> writes:\n>>>\n>>>> Yes, I would need to be able to do this on a bare repo for my use case.\n>>> And if it's on the server, you don't want this to be observable, so\n>>> you don't want HEAD to move around. I don't know a better way than:\n>>>\n>>>    $ git clone --shared -b upstream-branch bare-repo.git /tmp/merge-repo\n>>>    $ cd /tmp/merge-repo\n>>>    $ git pull URL incoming-branch\n>>>\n>>> Cloning with --shared just writes a path into .git/objects/info/alternatives\n>>> and it doesn't need to be on the same file system (unlike --local).\n>>>\n>>> Since 'git merge-tree' just works with trees, it has less information\n>>> than 'git merge'.\n>> You could use a temporary index and do something like:\n>>\n>> \trm -f TMP_INDEX\n>> \tGIT_INDEX_FILE=TMP_INDEX\n>> \texport GIT_INDEX_FILE\n>> \tgit read-tree -m $base $ours $theirs &&\n>> \tgit merge-index git-merge-one-file -a\n>>\n>> then inspect that with \"git diff-index --cached $ours\".\n> That is precisely how we do it at GitHub. You probably want to add in\n> \"--aggressive\" to your read-tree to cover a few more simple cases. If\n> there are conflicts, we just bail and say \"this can't be merged\", and\n> expect the user to do it themselves using git.\n>\n> -Peff\n\nThis may be ideal. I will compare it with merge-tree to see which will \nsuit best. Thank you everyone for your help here.\n\nCharlie\n"}]}