{"thread":{"id":"55957","subject":"subtree split includes unrelated commits","startedAt":"2021-06-18T08:54:30Z","lastAt":"2021-06-18T08:54:30Z","messageCount":1,"participants":["Daniel Pauli"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"427815","messageId":"bda757e3-1dfa-3541-177c-f3f21baa12b3@indel.ch","threadId":"55957","inReplyTo":null,"subject":"subtree split includes unrelated commits","fromName":"Daniel Pauli","fromEmail":"pauli@indel.ch","sentAt":"2021-06-18T08:47:44Z","receivedAt":"2021-06-18T08:54:30Z","isPatch":false,"sender":{"key":"pauli@indel.ch","avatar":null},"body":"Hi there\n\nFirst time I post to the mailing list here, I hope I get it right...\n\nI came across an issue where pushing a subtree resulted in unexpected \ncommits in the remote repository: These commits included files that are \nnot part of the subtree's directory. There's a related question on \nstackoverflow: \nhttps://stackoverflow.com/questions/61150709/git-subtree-push-seems-to-push-commits-that-dont-apply-to-the-subtree\n\nIn my case, the excess commits were introduced by a merge commit of a \nbranch that forked off the main branch *before* the subtree was added. \nThis merge commit was the result of updating my fork from the upstream \nrepository (which is not aware of the subtree, it just lives in my fork \nso far).\n\nI found the issue to be related with the following change in git-subtree.sh:\n\n> Revision: 933cfeb90b5d03b4096db6d60494a6eedea25d03\n> Author: Dave Ware <davidw@realtimegenomics.com>\n> Date: 15.01.2016 01:41:43\n> Message:\n> contrib/subtree: fix \"subtree split\" skipped-merge bug\n>\n> 'git subtree split' can incorrectly skip a merge even when both parents\n> act on the subtree, provided the merge results in a tree identical to\n> one of the parents. Fix by copying the merge if at least one parent is\n> non-identical, and the non-identical parent is not an ancestor of the\n> identical parent.\n>\n> Also, add a test case which checks that a descendant remains a\n> descendent on the subtree in this case.\n>\n> Signed-off-by: Dave Ware <davidw@realtimegenomics.com>\n> Reviewed-by: David A. Greene <greened@obbligato.org>\n> Signed-off-by: Junio C Hamano <gitster@pobox.com>\n> ----\n> Modified: contrib/subtree/git-subtree.sh\n> Modified: contrib/subtree/t/t7900-subtree.sh\n\n>     copycommit=\n>     if [ -n \"$identical\" ] && [ -n \"$nonidentical\" ]; then\n>         extras=$(git rev-list --count $identical..$nonidentical)\n>         if [ \"$extras\" -ne 0 ]; then\n>             # we need to preserve history along the other branch\n>  copycommit=1 // <---------------------\n>         fi\n>     fi\n>     if [ -n \"$identical\" ] && [ -z \"$copycommit\" ]; then\n>         echo $identical\n>     else\n>         copy_commit $rev $tree \"$p\" || exit $?\n>     fi\n\nAs a workaround, removing the copycommit=1 line here results in a split \nas I would expect for my case.\n\nI attached a sample repository and log that reproduces the issue:\n- From the main branch, do a \"git subtree split --prefix my_subtree -b \nsplitted -d\". This is how the branches listed below were created.\n- branch \"splitted_bad\" shows the unexpected merge commit f7fd955 that \nincludes files that are not part of the subtree (9eeff05)\n- branch \"splitted_good\" shows the result as I would expect it, without \nmerge commit f7fd955. It was done by commenting out the copycommit=1\n\nNow I wonder, is this expected behavior, or could it be a regression? I \ndo not really understand the inner workings of git-subtree.sh, but I \nfeel that where it included \"too few\" commits before the mentioned \npatch, it might now include \"too many\".\n\nRegards\nDaniel\n\n\n\ncommand: {split}\nquiet: {}\ndir: {my_subtree}\nopts: {}\n\nSplitting my_subtree...\nUsing cachedir: C:/projects/indel/inos-goes-git/subtree-issue/reproduce2/.git/subtree-cache/26\nLooking for prior splits...\n  Main is: '9eeff050a096a3c26e11ca4a4c5fab36aac5a122'\n    Prior: 9eeff050a096a3c26e11ca4a4c5fab36aac5a122 -> 10222c693436810690ae56560a7bd188c9d476f2\nprogress: 1/12 (0) [0]\nProcessing commit: 9eeff050a096a3c26e11ca4a4c5fab36aac5a122\n  prior: 10222c693436810690ae56560a7bd188c9d476f2\nprogress: 2/12 (0) [0]\nProcessing commit: 10222c693436810690ae56560a7bd188c9d476f2\n  prior: 10222c693436810690ae56560a7bd188c9d476f2\nprogress: 3/12 (0) [0]\nProcessing commit: bbdc6c08bae4787ad7cdae930706cf133e14ece0\n  parents: 9eeff050a096a3c26e11ca4a4c5fab36aac5a122 10222c693436810690ae56560a7bd188c9d476f2\n    incorrect order: 9eeff050a096a3c26e11ca4a4c5fab36aac5a122\nprogress: 3/12 (1) [1]\n    Processing commit: 9eeff050a096a3c26e11ca4a4c5fab36aac5a122\n      prior: 10222c693436810690ae56560a7bd188c9d476f2\n    incorrect order: 10222c693436810690ae56560a7bd188c9d476f2\nprogress: 3/12 (1) [2]\n    Processing commit: 10222c693436810690ae56560a7bd188c9d476f2\n      prior: 10222c693436810690ae56560a7bd188c9d476f2\n  newparents: 10222c693436810690ae56560a7bd188c9d476f2\n10222c693436810690ae56560a7bd188c9d476f2\n  tree is: dcbf87dcfeb8d5781492fad086f834d90a159402\n  newrev is: 10222c693436810690ae56560a7bd188c9d476f2\nprogress: 4/12 (1) [2]\nProcessing commit: 07804dbc6f40ea3d4ecd2c37efa1ba01d8264ef3\n  parents: bbdc6c08bae4787ad7cdae930706cf133e14ece0\n  newparents: 10222c693436810690ae56560a7bd188c9d476f2\n  tree is: dcbf87dcfeb8d5781492fad086f834d90a159402\n  newrev is: 10222c693436810690ae56560a7bd188c9d476f2\nprogress: 5/12 (2) [2]\nProcessing commit: d63e478df890d9907d11fd006a53ca735b4e8a99\n  parents: 07804dbc6f40ea3d4ecd2c37efa1ba01d8264ef3\n  newparents: 10222c693436810690ae56560a7bd188c9d476f2\n  tree is: 861359eb2c24ca3597c71701ae5050484000018a\n  copy_commit {d63e478df890d9907d11fd006a53ca735b4e8a99} {861359eb2c24ca3597c71701ae5050484000018a} { -p 10222c693436810690ae56560a7bd188c9d476f2}\n  newrev is: 123b70309419425b1a769037ee8109df9cc9dcb8\nprogress: 6/12 (3) [2]\nProcessing commit: 909c2643aadd556960f35a7c5f1bff708029a886\n  parents: 10222c693436810690ae56560a7bd188c9d476f2\n  newparents: 10222c693436810690ae56560a7bd188c9d476f2\n  tree is: \nprogress: 7/12 (4) [2]\nProcessing commit: 21446bae6f64507c5e8986336ecfe96b1ac917dd\n  parents: d63e478df890d9907d11fd006a53ca735b4e8a99 909c2643aadd556960f35a7c5f1bff708029a886\n    incorrect order: d63e478df890d9907d11fd006a53ca735b4e8a99\nprogress: 7/12 (5) [3]\n    Processing commit: d63e478df890d9907d11fd006a53ca735b4e8a99\n      prior: 123b70309419425b1a769037ee8109df9cc9dcb8\n  newparents: 123b70309419425b1a769037ee8109df9cc9dcb8\n909c2643aadd556960f35a7c5f1bff708029a886\n  tree is: 2b670b8b80ff0e7439c2e52381d38cf734140f03\n  copy_commit {21446bae6f64507c5e8986336ecfe96b1ac917dd} {2b670b8b80ff0e7439c2e52381d38cf734140f03} { -p 123b70309419425b1a769037ee8109df9cc9dcb8 -p 909c2643aadd556960f35a7c5f1bff708029a886}\n  newrev is: cb93d85c317b4edcecb1f3537240f0d15ccec236\nprogress: 8/12 (5) [3]\nProcessing commit: 50508755f2116f6077ccb4a1d5ad96501bce9bdb\n  parents: 9eeff050a096a3c26e11ca4a4c5fab36aac5a122\n  newparents: 10222c693436810690ae56560a7bd188c9d476f2\n  tree is: \nprogress: 9/12 (6) [3]\nProcessing commit: 4d89a44efd33c16730fc7b621f86b8b83bc322be\n  parents: 21446bae6f64507c5e8986336ecfe96b1ac917dd 50508755f2116f6077ccb4a1d5ad96501bce9bdb\n    incorrect order: 21446bae6f64507c5e8986336ecfe96b1ac917dd\nprogress: 9/12 (7) [4]\n    Processing commit: 21446bae6f64507c5e8986336ecfe96b1ac917dd\n      prior: cb93d85c317b4edcecb1f3537240f0d15ccec236\n  newparents: cb93d85c317b4edcecb1f3537240f0d15ccec236\n50508755f2116f6077ccb4a1d5ad96501bce9bdb\n  tree is: 2b670b8b80ff0e7439c2e52381d38cf734140f03\n  copy_commit {4d89a44efd33c16730fc7b621f86b8b83bc322be} {2b670b8b80ff0e7439c2e52381d38cf734140f03} { -p cb93d85c317b4edcecb1f3537240f0d15ccec236 -p 50508755f2116f6077ccb4a1d5ad96501bce9bdb}\n  newrev is: f7fd955503d5a43ff6410e7d9971a9995c1cfcf4\nprogress: 10/12 (7) [4]\nProcessing commit: 95dab064b04801a57fb2b740bafa0d9f47dd4d66\n  parents: 07804dbc6f40ea3d4ecd2c37efa1ba01d8264ef3\n  newparents: 10222c693436810690ae56560a7bd188c9d476f2\n  tree is: dcbf87dcfeb8d5781492fad086f834d90a159402\n  newrev is: 10222c693436810690ae56560a7bd188c9d476f2\nprogress: 11/12 (8) [4]\nProcessing commit: 70e56ea7b4f76b2c2a3c9f580b914551d2c753f7\n  parents: 95dab064b04801a57fb2b740bafa0d9f47dd4d66\n  newparents: 10222c693436810690ae56560a7bd188c9d476f2\n  tree is: 708b8e696c72bb5a1481e766cb0aedeed900266f\n  copy_commit {70e56ea7b4f76b2c2a3c9f580b914551d2c753f7} {708b8e696c72bb5a1481e766cb0aedeed900266f} { -p 10222c693436810690ae56560a7bd188c9d476f2}\n  newrev is: c5abf4f38a63d0a0c12e3827ec744602f2046eca\nprogress: 12/12 (9) [4]\nProcessing commit: 1b4a51ffd795ef3ce61f633042f4773095e0548c\n  parents: 4d89a44efd33c16730fc7b621f86b8b83bc322be 70e56ea7b4f76b2c2a3c9f580b914551d2c753f7\n    incorrect order: 4d89a44efd33c16730fc7b621f86b8b83bc322be\nprogress: 12/12 (10) [5]\n    Processing commit: 4d89a44efd33c16730fc7b621f86b8b83bc322be\n      prior: f7fd955503d5a43ff6410e7d9971a9995c1cfcf4\n    incorrect order: 70e56ea7b4f76b2c2a3c9f580b914551d2c753f7\nprogress: 12/12 (10) [6]\n    Processing commit: 70e56ea7b4f76b2c2a3c9f580b914551d2c753f7\n      prior: c5abf4f38a63d0a0c12e3827ec744602f2046eca\n  newparents: f7fd955503d5a43ff6410e7d9971a9995c1cfcf4\nc5abf4f38a63d0a0c12e3827ec744602f2046eca\n  tree is: acc21543759a45fdfff8dd66c231cb37321f9255\n  copy_commit {1b4a51ffd795ef3ce61f633042f4773095e0548c} {acc21543759a45fdfff8dd66c231cb37321f9255} { -p f7fd955503d5a43ff6410e7d9971a9995c1cfcf4 -p c5abf4f38a63d0a0c12e3827ec744602f2046eca}\n  newrev is: 2c045f7700e241fb6cd73fd71e12af5499844eb8\nUpdated branch 'splitted'\n"}]}