{"thread":{"id":"47571","subject":"cherry-picking fails after making a directory a submodule","startedAt":"2018-01-08T21:08:57Z","lastAt":"2018-01-08T22:15:10Z","messageCount":3,"participants":["Per Cederqvist","Stefan Beller"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"336200","messageId":"CAP=KgsSQOG=mmUDfSFDw0HJYvJWVPFU7M5T+k4VhfuRC_v9dww@mail.gmail.com","threadId":"47571","inReplyTo":null,"subject":"cherry-picking fails after making a directory a submodule","fromName":"Per Cederqvist","fromEmail":"cederp@opera.com","sentAt":"2018-01-08T21:08:46Z","receivedAt":"2018-01-08T21:08:57Z","isPatch":false,"sender":{"key":"cederp@opera.com","avatar":"https://gravatar.com/avatar/008fe28caedea0ba34042cd5157705267934f4ba7a9b29fb248ae18ec5b3055e?d=mp&s=160"},"body":"I have a situation where I have switched a directory from being a\nsubdirectory to being a submodule.  I then try to cherry-pick a commit\nfrom a taskbranch that was made before the switch to the master\nbranch.  The commit touches a file outside the subdirectory/submodule.\nYet \"git cherry-pick\" fails with this error message:\n\n> error: could not apply 78c403e... Add a project feature\n> hint: after resolving the conflicts, mark the corrected paths\n> hint: with 'git add <paths>' or 'git rm <paths>'\n> hint: and commit the result with 'git commit'\n\nI can resolve the situation by running \"git add libfoo && git\ncherry-pick --continue\".  The generated commit contains no changes to\n\"libfoo\".\n\nI don't understand why I need to manually add libfoo, as the commit\nI'm cherry-picking doesn't touch anything in libfoo.\n\nThe script below can reproduce the issue.  Tested with git 2.15.1,\n2.14.0 and 2.8.0, all with the same result.\n\nIs this a bug in \"git cherry-pick\"?\n\n-- cut here for cherry-across-submodule --\n#!/bin/sh\n#\n# This script creates a simple repo, where the \"libfoo\" directory\n# initially is a normal directory, but later becomes a git submodule.\n# It then tries to cherry-pick a commit (that doesn't touch libfoo)\n# that was created before the conversion to master (after the\n# conversion).  This fails for unclear reasons.\n\n# I've tested this with the following git versions:\n#  - 2.8.0\n#  - 2.14.0\n#  - 2.15.1\n#\n# They all behave the same\n\n# export PATH=/usr/local/git-2.15.1/bin:$PATH\n\nset -e -x\n\ngit --version\n\n# Refuse to run if this directory already exists, to prevent data loss.\nmkdir cherry-across-submodule-root\ncd cherry-across-submodule-root\n\nmkdir root\n(cd root && git init --bare libfoo.git)\n(cd root && git init --bare project.git)\n\nmkdir workspace\n(cd workspace && git clone ../root/libfoo)\n(cd workspace && git clone ../root/project)\n\nproj_commit ()\n{\n    (cd workspace/project &&\nprintf \"$1\\n\" >> $2 &&\ngit add $2 &&\ngit commit -m\"$3\")\n}\n\nfoo_commit ()\n{\n    (cd workspace/libfoo &&\nprintf \"$1\\n\" >> $2 &&\ngit add $2 &&\ngit commit -m\"$3\")\n}\n\nboth_commit ()\n{\n    foo_commit \"$1\" $2 \"$3\"\n    proj_commit \"$1\" libfoo/$2 \"Imported libfoo: $3\"\n}\n\nproj_commit \"This is a project\" README \"Started the project\"\nmkdir workspace/project/libfoo\nboth_commit \"This is a library\" README \"Started the library\"\nboth_commit \"all:\\n\\ttouch libfoo.a\" Makefile \"Build something\"\nproj_commit \"all:\\n\\tmake -C libfoo\" Makefile \"Build libfoo\"\nproj_commit \"ceder\" AUTHORS \"I made this\"\nboth_commit \"GPL\" \"COPYING\" \"Add license info\"\n(cd workspace/libfoo && git push)\n(cd workspace/project && git push)\n(cd workspace/project && git checkout -b task-1)\nproj_commit \"int feature() { return 17; }\" feature.c \"Add a project feature\"\n(cd workspace/project && git push -u origin task-1)\n\nassert_clean()\n{\n    (cd workspace/project &&\n[ -z \"`git status --porcelain`\" ] )\n}\n\n# Cherrypicking task-1 to task-2 works fine.\n(cd workspace/project && git checkout -b task-2 master && git\ncherry-pick task-1)\nassert_clean\n\n(cd workspace/project &&\n     git checkout master &&\n     git rm -r libfoo &&\n     git submodule add -b master ../libfoo.git libfoo &&\n     git commit -m\"Made libfoo a submodule\")\nassert_clean\n\n\n# Now suddenly cherrypicking fails?  I get this message from the\n# cherry-pick command:\n\n# error: could not apply 78c403e... Add a project feature\n# hint: after resolving the conflicts, mark the corrected paths\n# hint: with 'git add <paths>' or 'git rm <paths>'\n# hint: and commit the result with 'git commit'\n\n(cd workspace/project && git checkout -b task-3 master && git\ncherry-pick task-1)\n\n# At this point, \"git status --porcelain\" prints two lines:\n# A  feature.c\n# AU libfoo\n\nassert_clean\n-- cut here for cherry-across-submodule --\n\n    /ceder\n"},{"id":"336202","messageId":"CAGZ79katKiRwXLJscxbO-+JWLedgKmZ7Un-65i4CqefX9Fedqg@mail.gmail.com","threadId":"47571","inReplyTo":"CAP=KgsSQOG=mmUDfSFDw0HJYvJWVPFU7M5T+k4VhfuRC_v9dww@mail.gmail.com","subject":"Re: cherry-picking fails after making a directory a submodule","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-01-08T21:46:26Z","receivedAt":"2018-01-08T21:46:36Z","isPatch":false,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Mon, Jan 8, 2018 at 1:08 PM, Per Cederqvist <cederp@opera.com> wrote:\n> I have a situation where I have switched a directory from being a\n> subdirectory to being a submodule.  I then try to cherry-pick a commit\n> from a taskbranch that was made before the switch to the master\n> branch.  The commit touches a file outside the subdirectory/submodule.\n> Yet \"git cherry-pick\" fails with this error message:\n>\n>> error: could not apply 78c403e... Add a project feature\n>> hint: after resolving the conflicts, mark the corrected paths\n>> hint: with 'git add <paths>' or 'git rm <paths>'\n>> hint: and commit the result with 'git commit'\n>\n> I can resolve the situation by running \"git add libfoo && git\n> cherry-pick --continue\".  The generated commit contains no changes to\n> \"libfoo\".\n>\n> I don't understand why I need to manually add libfoo, as the commit\n> I'm cherry-picking doesn't touch anything in libfoo.\n>\n> The script below can reproduce the issue.  Tested with git 2.15.1,\n> 2.14.0 and 2.8.0, all with the same result.\n>\n> Is this a bug in \"git cherry-pick\"?\n\nCould you please test with\ngithub.com/git/git/commit/c641ca67072946f95f87e7b21f13f3d4e73701e3\nincluded? (See its parent commit, for the test)\n\nFrom my cursory read that commit is the issue addressed in that commit.\n"},{"id":"336208","messageId":"CAP=KgsRR1b8t=qBASf+8EnJyCmpLYPaJQMVHy6VfNxHruJ3--A@mail.gmail.com","threadId":"47571","inReplyTo":"CAGZ79katKiRwXLJscxbO-+JWLedgKmZ7Un-65i4CqefX9Fedqg@mail.gmail.com","subject":"Re: cherry-picking fails after making a directory a submodule","fromName":"Per Cederqvist","fromEmail":"cederp@opera.com","sentAt":"2018-01-08T22:15:04Z","receivedAt":"2018-01-08T22:15:10Z","isPatch":false,"sender":{"key":"cederp@opera.com","avatar":"https://gravatar.com/avatar/008fe28caedea0ba34042cd5157705267934f4ba7a9b29fb248ae18ec5b3055e?d=mp&s=160"},"body":"On Mon, Jan 8, 2018 at 10:46 PM, Stefan Beller <sbeller@google.com> wrote:\n> On Mon, Jan 8, 2018 at 1:08 PM, Per Cederqvist <cederp@opera.com> wrote:\n>> I have a situation where I have switched a directory from being a\n>> subdirectory to being a submodule.  I then try to cherry-pick a commit\n>> from a taskbranch that was made before the switch to the master\n>> branch.  The commit touches a file outside the subdirectory/submodule.\n>> Yet \"git cherry-pick\" fails with this error message:\n>>\n>>> error: could not apply 78c403e... Add a project feature\n>>> hint: after resolving the conflicts, mark the corrected paths\n>>> hint: with 'git add <paths>' or 'git rm <paths>'\n>>> hint: and commit the result with 'git commit'\n>>\n>> I can resolve the situation by running \"git add libfoo && git\n>> cherry-pick --continue\".  The generated commit contains no changes to\n>> \"libfoo\".\n>>\n>> I don't understand why I need to manually add libfoo, as the commit\n>> I'm cherry-picking doesn't touch anything in libfoo.\n>>\n>> The script below can reproduce the issue.  Tested with git 2.15.1,\n>> 2.14.0 and 2.8.0, all with the same result.\n>>\n>> Is this a bug in \"git cherry-pick\"?\n>\n> Could you please test with\n> github.com/git/git/commit/c641ca67072946f95f87e7b21f13f3d4e73701e3\n> included? (See its parent commit, for the test)\n>\n> From my cursory read that commit is the issue addressed in that commit.\n\nThanks!  I can confirm that applying the changes to merge-recursive.c from\nthat commit fixes the issue in 2.15.1.\n\n    /ceder\n"}]}