{"thread":{"id":"41507","subject":"git mv messed up file mapping if folders contain identical files","startedAt":"2016-02-24T23:38:11Z","lastAt":"2016-02-26T15:48:56Z","messageCount":9,"participants":["Bill Okara","Junio C Hamano","Kevin Daudt","Stefan Beller","SZEDER Gábor"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"279229","messageId":"CADsr5c_Hk34KBN06dM9Hk5HPW9-Mt3eZLMgvyes8sSgxCA-k0w@mail.gmail.com","threadId":"41507","inReplyTo":null,"subject":"git mv messed up file mapping if folders contain identical files","fromName":"Bill Okara","fromEmail":"billokara@gmail.com","sentAt":"2016-02-24T23:38:11Z","receivedAt":"2016-02-24T23:38:11Z","isPatch":false,"sender":{"key":"billokara@gmail.com","avatar":null},"body":"Hi,\n\nI noticed the following 'git mv' issue with:\ngit version 2.6.4\n\n\nIf there are identical files in different subfolders, 'git mv' the\nroot folder (and/or each file individually) will mess up the file path\nmapping. that is, if having identical 'content.txt' file under\ngitmvtest\n    |--demo/content.txt\n    |--dev/content.txt\n    |--prod/content.txt\n\nafter doing the \"git mv gitmvtest/resources\ngitmvtest/src/main/resources\", the 'git status' will show:\n\nrenamed:    gitmvtest/resources/demo/content.txt ->\ngitmvtest/src/main/resources/demo/content.txt\nrenamed:    gitmvtest/resources/prod/content.txt ->\ngitmvtest/src/main/resources/dev/content.txt            <== NOTE:\nwrongly mapped the prod/content.txt to dev/content.txt\nrenamed:    gitmvtest/resources/dev/content.txt ->\ngitmvtest/src/main/resources/prod/content.txt            <== NOTE:\nwrongly mapped the dev/content.txt to prod/content.txt\n\nI tried running 'git mv' on each file individually, got the same problem:\n> git mv gitmvtest/resources/demo/content.txt gitmvtest/src/main/resources/demo/content.txt\n> git mv gitmvtest/resources/dev/content.txt gitmvtest/src/main/resources/dev/content.txt\n> git mv gitmvtest/resources/prod/content.txt gitmvtest/src/main/resources/prod/content.txt\n\n> git status\nrenamed:    gitmvtest/resources/demo/content.txt ->\ngitmvtest/src/main/resources/demo/content.txt\nrenamed:    gitmvtest/resources/prod/content.txt ->\ngitmvtest/src/main/resources/dev/content.txt          <== WRONG\nrenamed:    gitmvtest/resources/dev/content.txt ->\ngitmvtest/src/main/resources/prod/content.txt          <== WRONG\n\n\nNOTE:\n=======\nif modified the content.txt in the 3 folders to contain different\ndata, then repeating the above 'git mv' will produce correct result,\n\nrenamed:    gitmvtest/resources/demo/content.txt ->\ngitmvtest/src/main/resources/demo/content.txt       <== CORRECT\nrenamed:    gitmvtest/resources/dev/content.txt ->\ngitmvtest/src/main/resources/dev/content.txt             <== CORRECT\nrenamed:    gitmvtest/resources/prod/content.txt ->\ngitmvtest/src/main/resources/prod/content.txt          <== CORRECT\n\n\n\njust want to see if this is a bug, user error (on my end), or??\n\n\nThanks,\nBill\n"},{"id":"279230","messageId":"xmqqwpptr83a.fsf@gitster.mtv.corp.google.com","threadId":"41507","inReplyTo":"CADsr5c_Hk34KBN06dM9Hk5HPW9-Mt3eZLMgvyes8sSgxCA-k0w@mail.gmail.com","subject":"Re: git mv messed up file mapping if folders contain identical files","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-02-24T23:39:53Z","receivedAt":"2016-02-24T23:39:53Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Bill Okara <billokara@gmail.com> writes:\n\n> just want to see if this is a bug, user error (on my end), or??\n\nNot a bug, not a user error, just \"it does not matter\", I think.\n"},{"id":"279233","messageId":"CADsr5c8akqt7tsgptuDqCyt2JW8ie9js5eFt7oxXxDxtGMLJFA@mail.gmail.com","threadId":"41507","inReplyTo":"xmqqwpptr83a.fsf@gitster.mtv.corp.google.com","subject":"Re: git mv messed up file mapping if folders contain identical files","fromName":"Bill Okara","fromEmail":"billokara@gmail.com","sentAt":"2016-02-24T23:51:43Z","receivedAt":"2016-02-24T23:51:43Z","isPatch":false,"sender":{"key":"billokara@gmail.com","avatar":null},"body":"it actually does matter in the following scenario:\n\n1) master branch has identical content.txt files in the folder structure\n2) do the git mv in a new branch\n3) master branch updated the context.txt to contain new data (more\nrelevant to the containing folder)\n4) new branch need to merge the updates from master\n\nafter the merge, demo/content.txt in the new path would contain\nupdates from dev/content.txt from master...\n\nOn Wed, Feb 24, 2016 at 4:39 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> Bill Okara <billokara@gmail.com> writes:\n>\n>> just want to see if this is a bug, user error (on my end), or??\n>\n> Not a bug, not a user error, just \"it does not matter\", I think.\n>\n>\n"},{"id":"279236","messageId":"CADsr5c_DyzTNcPg9aZ6TJse0i0o=4LMz7_-QXtOpfnLhF3cKLw@mail.gmail.com","threadId":"41507","inReplyTo":"CADsr5c8akqt7tsgptuDqCyt2JW8ie9js5eFt7oxXxDxtGMLJFA@mail.gmail.com","subject":"Re: git mv messed up file mapping if folders contain identical files","fromName":"Bill Okara","fromEmail":"billokara@gmail.com","sentAt":"2016-02-25T00:03:04Z","receivedAt":"2016-02-25T00:03:04Z","isPatch":false,"sender":{"key":"billokara@gmail.com","avatar":null},"body":"following are the steps to help illustrate the issue. its actually\nquite common to have projects include identical placeholder files\nbefore update/refactoring...\n\n// Create in master branch\n\n> mkdir gittest\n> cd gittest\n> init\n> mkdir -p gitmvtest/resources\n> mkdir -p gitmvtest/resources/demo\n> mkdir -p gitmvtest/resources/dev\n> mkdir -p gitmvtest/resources/prod\n> cd gitmvtest/resources/demo/\n> echo 'This is the line that contains the common content’ >> content.txt\n> cd ..\n> cp demo/content.txt dev/.\n> cp demo/content.txt prod/.\n> cd ../..\n> git add .\n> git commit -m \"master content.txt first commit\"\n\n\n# change to a new branch\n\n> git checkout -b newTestBranch\n> mkdir -p gitmvtest/src/main\n> git mv gitmvtest/resources gitmvtest/src/main/.\n> git commit -m \"newTestBranch: mv resources to src/main/resources\"\n\n[newTestBranch 5faed26] newTestBranch: mv resources to src/main/resources\n 3 files changed, 0 insertions(+), 0 deletions(-)\n\n rename gitmvtest/{resources/prod => src/main/resources/demo}/content.txt (100%)\n rename gitmvtest/{ => src/main}/resources/dev/content.txt (100%)\n rename gitmvtest/{resources/demo => src/main/resources/prod}/content.txt (100%)\n\n\n// Change back to master and update the 3 files\n\n> git checkout master\n> echo 'this is DEMO content' >> gitmvtest/resources/demo/content.txt\n> echo 'this is DEV content' >> gitmvtest/resources/dev/content.txt\n> echo 'this is PROD content' >> gitmvtest/resources/prod/content.txt\n> git add .\n> git commit -m \"master: update content.txt to include parent folder name\"\n\n[master 18d85f9] master: update content.txt to include parent folder name\n 3 files changed, 3 insertions(+)\n\n\n// Change back to the new branch and merge from master\n\n> git checkout newTestBranch\n> git merge master\nAuto-merging gitmvtest/src/main/resources/prod/content.txt\nAuto-merging gitmvtest/src/main/resources/dev/content.txt\nAuto-merging gitmvtest/src/main/resources/demo/content.txt\n\nMerge made by the 'recursive' strategy.\n gitmvtest/src/main/resources/demo/content.txt | 1 +\n gitmvtest/src/main/resources/dev/content.txt  | 1 +\n gitmvtest/src/main/resources/prod/content.txt | 1 +\n 3 files changed, 3 insertions(+)\n\n\n// SEE the ERROR:\n//demo/content.txt wrongly merged with data from prod/content.txt\n\n> cat gitmvtest/src/main/resources/demo/content.txt\n\nThis is the line that contains the common content\nthis is PROD content\n\nOn Wed, Feb 24, 2016 at 4:51 PM, Bill Okara <billokara@gmail.com> wrote:\n> it actually does matter in the following scenario:\n>\n> 1) master branch has identical content.txt files in the folder structure\n> 2) do the git mv in a new branch\n> 3) master branch updated the context.txt to contain new data (more\n> relevant to the containing folder)\n> 4) new branch need to merge the updates from master\n>\n> after the merge, demo/content.txt in the new path would contain\n> updates from dev/content.txt from master...\n>\n> On Wed, Feb 24, 2016 at 4:39 PM, Junio C Hamano <gitster@pobox.com> wrote:\n>> Bill Okara <billokara@gmail.com> writes:\n>>\n>>> just want to see if this is a bug, user error (on my end), or??\n>>\n>> Not a bug, not a user error, just \"it does not matter\", I think.\n>>\n>>\n"},{"id":"279311","messageId":"20160225114958.GC15324@ikke.info","threadId":"41507","inReplyTo":"CADsr5c_Hk34KBN06dM9Hk5HPW9-Mt3eZLMgvyes8sSgxCA-k0w@mail.gmail.com","subject":"Re: git mv messed up file mapping if folders contain identical files","fromName":"Kevin Daudt","fromEmail":"me@ikke.info","sentAt":"2016-02-25T11:49:58Z","receivedAt":"2016-02-25T11:49:58Z","isPatch":false,"sender":{"key":"me@ikke.info","avatar":"https://avatars.githubusercontent.com/u/135698?v=4"},"body":"On Wed, Feb 24, 2016 at 04:38:11PM -0700, Bill Okara wrote:\n> Hi,\n> \n> I noticed the following 'git mv' issue with:\n> git version 2.6.4\n> \n> \n> If there are identical files in different subfolders, 'git mv' the\n> root folder (and/or each file individually) will mess up the file path\n> mapping. that is, if having identical 'content.txt' file under\n> gitmvtest\n>     |--demo/content.txt\n>     |--dev/content.txt\n>     |--prod/content.txt\n> \n> after doing the \"git mv gitmvtest/resources\n> gitmvtest/src/main/resources\", the 'git status' will show:\n> \n> renamed:    gitmvtest/resources/demo/content.txt ->\n> gitmvtest/src/main/resources/demo/content.txt\n> renamed:    gitmvtest/resources/prod/content.txt ->\n> gitmvtest/src/main/resources/dev/content.txt            <== NOTE:\n> wrongly mapped the prod/content.txt to dev/content.txt\n> renamed:    gitmvtest/resources/dev/content.txt ->\n> gitmvtest/src/main/resources/prod/content.txt            <== NOTE:\n> wrongly mapped the dev/content.txt to prod/content.txt\n> \n> I tried running 'git mv' on each file individually, got the same problem:\n> > git mv gitmvtest/resources/demo/content.txt gitmvtest/src/main/resources/demo/content.txt\n> > git mv gitmvtest/resources/dev/content.txt gitmvtest/src/main/resources/dev/content.txt\n> > git mv gitmvtest/resources/prod/content.txt gitmvtest/src/main/resources/prod/content.txt\n> \n> > git status\n> renamed:    gitmvtest/resources/demo/content.txt ->\n> gitmvtest/src/main/resources/demo/content.txt\n> renamed:    gitmvtest/resources/prod/content.txt ->\n> gitmvtest/src/main/resources/dev/content.txt          <== WRONG\n> renamed:    gitmvtest/resources/dev/content.txt ->\n> gitmvtest/src/main/resources/prod/content.txt          <== WRONG\n> \n> \n> NOTE:\n> =======\n> if modified the content.txt in the 3 folders to contain different\n> data, then repeating the above 'git mv' will produce correct result,\n> \n> renamed:    gitmvtest/resources/demo/content.txt ->\n> gitmvtest/src/main/resources/demo/content.txt       <== CORRECT\n> renamed:    gitmvtest/resources/dev/content.txt ->\n> gitmvtest/src/main/resources/dev/content.txt             <== CORRECT\n> renamed:    gitmvtest/resources/prod/content.txt ->\n> gitmvtest/src/main/resources/prod/content.txt          <== CORRECT\n> \n> \n> \n> just want to see if this is a bug, user error (on my end), or??\n> \n\nThis looks like the same issue as submodule--helper list has:\nhttp://article.gmane.org/gmane.comp.version-control.git/287227\n"},{"id":"279336","messageId":"CAGZ79kZApquSRaY_BtHrqfvuWmtYuPjeshmT-oW6T8Z7atYdFQ@mail.gmail.com","threadId":"41507","inReplyTo":"20160225114958.GC15324@ikke.info","subject":"Re: git mv messed up file mapping if folders contain identical files","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2016-02-25T13:56:22Z","receivedAt":"2016-02-25T13:56:22Z","isPatch":false,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Thu, Feb 25, 2016 at 3:49 AM, Kevin Daudt <me@ikke.info> wrote:\n> On Wed, Feb 24, 2016 at 04:38:11PM -0700, Bill Okara wrote:\n>> Hi,\n>>\n>> I noticed the following 'git mv' issue with:\n>> git version 2.6.4\n>>\n>>\n>> If there are identical files in different subfolders, 'git mv' the\n>> root folder (and/or each file individually) will mess up the file path\n>> mapping. that is, if having identical 'content.txt' file under\n>> gitmvtest\n>>     |--demo/content.txt\n>>     |--dev/content.txt\n>>     |--prod/content.txt\n>>\n>> after doing the \"git mv gitmvtest/resources\n>> gitmvtest/src/main/resources\", the 'git status' will show:\n>>\n>> renamed:    gitmvtest/resources/demo/content.txt ->\n>> gitmvtest/src/main/resources/demo/content.txt\n>> renamed:    gitmvtest/resources/prod/content.txt ->\n>> gitmvtest/src/main/resources/dev/content.txt            <== NOTE:\n>> wrongly mapped the prod/content.txt to dev/content.txt\n>> renamed:    gitmvtest/resources/dev/content.txt ->\n>> gitmvtest/src/main/resources/prod/content.txt            <== NOTE:\n>> wrongly mapped the dev/content.txt to prod/content.txt\n>>\n>> I tried running 'git mv' on each file individually, got the same problem:\n>> > git mv gitmvtest/resources/demo/content.txt gitmvtest/src/main/resources/demo/content.txt\n>> > git mv gitmvtest/resources/dev/content.txt gitmvtest/src/main/resources/dev/content.txt\n>> > git mv gitmvtest/resources/prod/content.txt gitmvtest/src/main/resources/prod/content.txt\n>>\n>> > git status\n>> renamed:    gitmvtest/resources/demo/content.txt ->\n>> gitmvtest/src/main/resources/demo/content.txt\n>> renamed:    gitmvtest/resources/prod/content.txt ->\n>> gitmvtest/src/main/resources/dev/content.txt          <== WRONG\n>> renamed:    gitmvtest/resources/dev/content.txt ->\n>> gitmvtest/src/main/resources/prod/content.txt          <== WRONG\n>>\n>>\n>> NOTE:\n>> =======\n>> if modified the content.txt in the 3 folders to contain different\n>> data, then repeating the above 'git mv' will produce correct result,\n>>\n>> renamed:    gitmvtest/resources/demo/content.txt ->\n>> gitmvtest/src/main/resources/demo/content.txt       <== CORRECT\n>> renamed:    gitmvtest/resources/dev/content.txt ->\n>> gitmvtest/src/main/resources/dev/content.txt             <== CORRECT\n>> renamed:    gitmvtest/resources/prod/content.txt ->\n>> gitmvtest/src/main/resources/prod/content.txt          <== CORRECT\n>>\n>>\n>>\n>> just want to see if this is a bug, user error (on my end), or??\n>>\n>\n> This looks like the same issue as submodule--helper list has:\n> http://article.gmane.org/gmane.comp.version-control.git/287227\n\nThe submodule--helper is not called from within git-mv, so it may be\na similar but not the same issue. ;)\n\nLooking through the code, the pathspec is not treated according to the newest\nstyle convention, I think it is one of the last places where the\npathspec internals\nare poked with, instead of using parse_parsespec && match_parsespec.\n(That said it is very old hence often tested code in the wild. old\ncode != bad code)\n\nStefan\n"},{"id":"279344","messageId":"CADsr5c9j1ne5K4TKZGMvoFeaNWbQxDs253Y29bfb9BsA+7A0aA@mail.gmail.com","threadId":"41507","inReplyTo":"CAGZ79kZApquSRaY_BtHrqfvuWmtYuPjeshmT-oW6T8Z7atYdFQ@mail.gmail.com","subject":"Re: git mv messed up file mapping if folders contain identical files","fromName":"Bill Okara","fromEmail":"billokara@gmail.com","sentAt":"2016-02-25T16:25:24Z","receivedAt":"2016-02-25T16:25:24Z","isPatch":false,"sender":{"key":"billokara@gmail.com","avatar":null},"body":"resent, forgot to reply to all...\n\nI guess a bigger concern of this issue is the mess up of history. That\nis, even if not doing an merge/update, just doing the 'git mv' will\nmessed up the file history, as shown in following:\n\n// Add a new resources/qa/content.txt files with a new commit message:\n\n> mkdir gitmvtest/resources/qa\n> cp gitmvtest/resources/demo/content.txt gitmvtest/resources/qa/.\n> git add .\n>git commit -m \"Add a new QA context.txt\"\n[master caba387] Add a new QA context.txt\n 1 file changed, 2 insertions(+)\n\n// Do the git mv\n\n> git checkout -b branch5\n> git mv gitmvtest/resources gitmvtest/src/main/.\n> git commit -m \"Move resources to src/main/resources\"\n[branch5 dd44309] Move resources to src/main/resources\n 4 files changed, 0 insertions(+), 0 deletions(-)\n rename gitmvtest/{resources/qa =>\nsrc/main/resources/demo}/content.txt (100%)    <-- WRONG\n rename gitmvtest/{resources/prod =>\nsrc/main/resources/dev}/content.txt (100%)    <-- WRONG\n rename gitmvtest/{resources/dev =>\nsrc/main/resources/prod}/content.txt (100%)    <-- WRONG\n rename gitmvtest/{resources/demo =>\nsrc/main/resources/qa}/content.txt (100%)   <-- WRONG\n\n// WRONG HISTORY\n> git log --follow --oneline  gitmvtest/src/main/resources/demo/content.txt   <== demo/content.txt points to the new QA history\ndd44309 Move resources to src/main/resources\ncaba387 Add a new QA context.txt                <== WRONG HISTORY\n\n\n\nthanks,\nBill\n\nOn Thu, Feb 25, 2016 at 6:56 AM, Stefan Beller <sbeller@google.com> wrote:\n> On Thu, Feb 25, 2016 at 3:49 AM, Kevin Daudt <me@ikke.info> wrote:\n>> On Wed, Feb 24, 2016 at 04:38:11PM -0700, Bill Okara wrote:\n>>> Hi,\n>>>\n>>> I noticed the following 'git mv' issue with:\n>>> git version 2.6.4\n>>>\n>>>\n>>> If there are identical files in different subfolders, 'git mv' the\n>>> root folder (and/or each file individually) will mess up the file path\n>>> mapping. that is, if having identical 'content.txt' file under\n>>> gitmvtest\n>>>     |--demo/content.txt\n>>>     |--dev/content.txt\n>>>     |--prod/content.txt\n>>>\n>>> after doing the \"git mv gitmvtest/resources\n>>> gitmvtest/src/main/resources\", the 'git status' will show:\n>>>\n>>> renamed:    gitmvtest/resources/demo/content.txt ->\n>>> gitmvtest/src/main/resources/demo/content.txt\n>>> renamed:    gitmvtest/resources/prod/content.txt ->\n>>> gitmvtest/src/main/resources/dev/content.txt            <== NOTE:\n>>> wrongly mapped the prod/content.txt to dev/content.txt\n>>> renamed:    gitmvtest/resources/dev/content.txt ->\n>>> gitmvtest/src/main/resources/prod/content.txt            <== NOTE:\n>>> wrongly mapped the dev/content.txt to prod/content.txt\n>>>\n>>> I tried running 'git mv' on each file individually, got the same problem:\n>>> > git mv gitmvtest/resources/demo/content.txt gitmvtest/src/main/resources/demo/content.txt\n>>> > git mv gitmvtest/resources/dev/content.txt gitmvtest/src/main/resources/dev/content.txt\n>>> > git mv gitmvtest/resources/prod/content.txt gitmvtest/src/main/resources/prod/content.txt\n>>>\n>>> > git status\n>>> renamed:    gitmvtest/resources/demo/content.txt ->\n>>> gitmvtest/src/main/resources/demo/content.txt\n>>> renamed:    gitmvtest/resources/prod/content.txt ->\n>>> gitmvtest/src/main/resources/dev/content.txt          <== WRONG\n>>> renamed:    gitmvtest/resources/dev/content.txt ->\n>>> gitmvtest/src/main/resources/prod/content.txt          <== WRONG\n>>>\n>>>\n>>> NOTE:\n>>> =======\n>>> if modified the content.txt in the 3 folders to contain different\n>>> data, then repeating the above 'git mv' will produce correct result,\n>>>\n>>> renamed:    gitmvtest/resources/demo/content.txt ->\n>>> gitmvtest/src/main/resources/demo/content.txt       <== CORRECT\n>>> renamed:    gitmvtest/resources/dev/content.txt ->\n>>> gitmvtest/src/main/resources/dev/content.txt             <== CORRECT\n>>> renamed:    gitmvtest/resources/prod/content.txt ->\n>>> gitmvtest/src/main/resources/prod/content.txt          <== CORRECT\n>>>\n>>>\n>>>\n>>> just want to see if this is a bug, user error (on my end), or??\n>>>\n>>\n>> This looks like the same issue as submodule--helper list has:\n>> http://article.gmane.org/gmane.comp.version-control.git/287227\n>\n> The submodule--helper is not called from within git-mv, so it may be\n> a similar but not the same issue. ;)\n>\n> Looking through the code, the pathspec is not treated according to the newest\n> style convention, I think it is one of the last places where the\n> pathspec internals\n> are poked with, instead of using parse_parsespec && match_parsespec.\n> (That said it is very old hence often tested code in the wild. old\n> code != bad code)\n>\n> Stefan\n"},{"id":"279516","messageId":"1456487400-31174-1-git-send-email-szeder@ira.uka.de","threadId":"41507","inReplyTo":"CADsr5c9j1ne5K4TKZGMvoFeaNWbQxDs253Y29bfb9BsA+7A0aA@mail.gmail.com","subject":"Re: git mv messed up file mapping if folders contain identical files","fromName":"SZEDER Gábor","fromEmail":"szeder@ira.uka.de","sentAt":"2016-02-26T11:50:00Z","receivedAt":"2016-02-26T11:50:00Z","isPatch":false,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"Hi,\n\nPlease don't top-post on this list.\n\n> I guess a bigger concern of this issue is the mess up of history. That\n> is, even if not doing an merge/update, just doing the 'git mv' will\n> messed up the file history, as shown in following:\n> \n> \n> // Add a new resources/qa/content.txt files with a new commit message:\n> \n> > mkdir gitmvtest/resources/qa\n> > cp gitmvtest/resources/demo/content.txt gitmvtest/resources/qa/.\n> > git add .\n> >git commit -m \"Add a new QA context.txt\"\n> [master caba387] Add a new QA context.txt\n>  1 file changed, 2 insertions(+)\n> \n> // Do the git mv\n> \n> > git checkout -b branch5\n> > git mv gitmvtest/resources gitmvtest/src/main/.\n> > git commit -m \"Move resources to src/main/resources\"\n> [branch5 dd44309] Move resources to src/main/resources\n>  4 files changed, 0 insertions(+), 0 deletions(-)\n>  rename gitmvtest/{resources/qa =>\n> src/main/resources/demo}/content.txt (100%)    <-- WRONG\n>  rename gitmvtest/{resources/prod =>\n> src/main/resources/dev}/content.txt (100%)    <-- WRONG\n>  rename gitmvtest/{resources/dev =>\n> src/main/resources/prod}/content.txt (100%)    <-- WRONG\n>  rename gitmvtest/{resources/demo =>\n> src/main/resources/qa}/content.txt (100%)   <-- WRONG\n> \n> // WRONG HISTORY\n> > git log --follow --oneline  gitmvtest/src/main/resources/demo/content.txt   <== demo/content.txt points to the new QA history\n> dd44309 Move resources to src/main/resources\n> caba387 Add a new QA context.txt                <== WRONG HISTORY\n\nGit doesn't track copies and renames.\n\nGit only tracks content and infers copies and renames from content\nchanges.  For example, if a commit removes path 'A' and adds path 'B'\nthen Git checks whether they both have identical (or very similar)\ncontent, and reports this change as a rename if they do.  This is not\nrecorded anywhere in the repository, but 'git log --follow <path>'\nperforms this check upon seeing that the path in question doesn't\nexist in the previous commit.\n\nAnyway, diffcore used to handle your case better, and the patch below\nrestores the original behavior.\n\n ---- >8 ----\n\nSubject: [PATCH] diffcore: fix iteration order of identical files during rename detection\n\nIf the two paths 'dir/A/file' and 'dir/B/file' have identical content\nand the parent directory is renamed, e.g. 'git mv dir other-dir', then\ndiffcore reports the following exact renames:\n\n    renamed:    dir/B/file -> other-dir/A/file\n    renamed:    dir/A/file -> other-dir/B/file\n\nWhile technically not wrong, this is confusing not only for the user,\nbut also for git commands that make decisions based on rename\ninformation, e.g. 'git log --follow'.\n\nThis behavior is a side effect of commit v2.0.0-rc4~8^2~14\n(diffcore-rename.c: simplify finding exact renames, 2013-11-14): the\nhashmap storing sources returns entries from the same bucket, i.e.\nsources matching the current destination, in LIFO order.  Thus the\niteration first examines 'other-dir/A/file' and 'dir/B/file' and, upon\nfinding identical content and basename, reports an exact rename.\n\nRestore the original behavior by reversing the order of filling the\nhashmap with source entries.\n\nReported-by: Bill Okara <billokara@gmail.com>\nSigned-off-by: SZEDER Gábor <szeder@ira.uka.de>\n---\n diffcore-rename.c      |  6 ++++--\n t/t4001-diff-rename.sh | 11 +++++++++++\n 2 files changed, 15 insertions(+), 2 deletions(-)\n\ndiff --git a/diffcore-rename.c b/diffcore-rename.c\nindex af1fe08861e6..69fcf77be02d 100644\n--- a/diffcore-rename.c\n+++ b/diffcore-rename.c\n@@ -340,9 +340,11 @@ static int find_exact_renames(struct diff_options *options)\n \tint i, renames = 0;\n \tstruct hashmap file_table;\n \n-\t/* Add all sources to the hash table */\n+\t/* Add all sources to the hash table in reverse order, because\n+\t * later on they will be retrieved in LIFO order.\n+\t */\n \thashmap_init(&file_table, NULL, rename_src_nr);\n-\tfor (i = 0; i < rename_src_nr; i++)\n+\tfor (i = rename_src_nr-1; i >= 0; i--)\n \t\tinsert_file_table(&file_table, i, rename_src[i].p->one);\n \n \t/* Walk the destinations and find best source match */\ndiff --git a/t/t4001-diff-rename.sh b/t/t4001-diff-rename.sh\nindex 2f327b749588..ed90c6c6f984 100755\n--- a/t/t4001-diff-rename.sh\n+++ b/t/t4001-diff-rename.sh\n@@ -77,6 +77,17 @@ test_expect_success 'favour same basenames even with minor differences' '\n \tgit show HEAD:path1 | sed \"s/15/16/\" > subdir/path1 &&\n \tgit status | test_i18ngrep \"renamed: .*path1 -> subdir/path1\"'\n \n+test_expect_success 'two files with same basename and same content' '\n+\tgit reset --hard &&\n+\tmkdir -p dir/A dir/B &&\n+\tcp path1 dir/A/file &&\n+\tcp path1 dir/B/file &&\n+\tgit add dir &&\n+\tgit commit -m 2 &&\n+\tgit mv dir other-dir &&\n+\tgit status | test_i18ngrep \"renamed: .*dir/A/file -> other-dir/A/file\"\n+'\n+\n test_expect_success 'setup for many rename source candidates' '\n \tgit reset --hard &&\n \tfor i in 0 1 2 3 4 5 6 7 8 9;\n-- \n2.7.2.410.g92cb358\n"},{"id":"279525","messageId":"CADsr5c-WztuTM5Tmu9_h_9_uSnGLwqSR1c5ZPa_DDi9yAJBNnw@mail.gmail.com","threadId":"41507","inReplyTo":"1456487400-31174-1-git-send-email-szeder@ira.uka.de","subject":"Re: git mv messed up file mapping if folders contain identical files","fromName":"Bill Okara","fromEmail":"billokara@gmail.com","sentAt":"2016-02-26T15:48:56Z","receivedAt":"2016-02-26T15:48:56Z","isPatch":false,"sender":{"key":"billokara@gmail.com","avatar":null},"body":"Hi,\n\nOn Fri, Feb 26, 2016 at 4:50 AM, SZEDER Gábor <szeder@ira.uka.de> wrote:\n>\n> Please don't top-post on this list.\n>\nSorry about that. Just learned what that means and why it is bad...\n\n> Subject: [PATCH] diffcore: fix iteration order of identical files during rename detection\n>\n> If the two paths 'dir/A/file' and 'dir/B/file' have identical content\n> and the parent directory is renamed, e.g. 'git mv dir other-dir', then\n> diffcore reports the following exact renames:\n>\n>     renamed:    dir/B/file -> other-dir/A/file\n>     renamed:    dir/A/file -> other-dir/B/file\n>\n> While technically not wrong, this is confusing not only for the user,\n> but also for git commands that make decisions based on rename\n> information, e.g. 'git log --follow'.\n>\n> This behavior is a side effect of commit v2.0.0-rc4~8^2~14\n> (diffcore-rename.c: simplify finding exact renames, 2013-11-14): the\n> hashmap storing sources returns entries from the same bucket, i.e.\n> sources matching the current destination, in LIFO order.  Thus the\n> iteration first examines 'other-dir/A/file' and 'dir/B/file' and, upon\n> finding identical content and basename, reports an exact rename.\n>\n> Restore the original behavior by reversing the order of filling the\n> hashmap with source entries.\n>\n> Reported-by: Bill Okara <billokara@gmail.com>\n> Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>\n> ---\n>  diffcore-rename.c      |  6 ++++--\n>  t/t4001-diff-rename.sh | 11 +++++++++++\n>  2 files changed, 15 insertions(+), 2 deletions(-)\n\n> diff --git a/t/t4001-diff-rename.sh b/t/t4001-diff-rename.sh\n> index 2f327b749588..ed90c6c6f984 100755\n> --- a/t/t4001-diff-rename.sh\n> +++ b/t/t4001-diff-rename.sh\n> @@ -77,6 +77,17 @@ test_expect_success 'favour same basenames even with minor differences' '\n>         git show HEAD:path1 | sed \"s/15/16/\" > subdir/path1 &&\n>         git status | test_i18ngrep \"renamed: .*path1 -> subdir/path1\"'\n>\n> +test_expect_success 'two files with same basename and same content' '\n> +       git reset --hard &&\n> +       mkdir -p dir/A dir/B &&\n> +       cp path1 dir/A/file &&\n> +       cp path1 dir/B/file &&\n> +       git add dir &&\n> +       git commit -m 2 &&\n> +       git mv dir other-dir &&\n> +       git status | test_i18ngrep \"renamed: .*dir/A/file -> other-dir/A/file\"\n> +'\n> +\n>  test_expect_success 'setup for many rename source candidates' '\n>         git reset --hard &&\n>         for i in 0 1 2 3 4 5 6 7 8 9;\n> --\n> 2.7.2.410.g92cb358\n>\n\nThank you very much for the fix and the detailed explanation!\n\n-Bill\n"}]}