{"thread":{"id":"33567","subject":"[BUG] Silent data loss on merge with uncommited changes + renames","startedAt":"2013-04-22T09:24:45Z","lastAt":"2013-04-22T15:19:50Z","messageCount":4,"participants":["Matthieu Moy","Johannes Sixt","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"215065","messageId":"vpqobd6q5nm.fsf@grenoble-inp.fr","threadId":"33567","inReplyTo":null,"subject":"[BUG] Silent data loss on merge with uncommited changes + renames","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@grenoble-inp.fr","sentAt":"2013-04-22T09:24:45Z","receivedAt":"2013-04-22T09:24:45Z","isPatch":false,"sender":{"key":"matthieu.moy@grenoble-inp.fr","avatar":"https://gravatar.com/avatar/72c8a2705971a25dfaff23cece15130d405685845d911aedd5667ace277f3fc5?d=mp&s=160"},"body":"Hi,\n\nFollowing the discussion on \"merge with uncommited changes\" inside the\n\"git pull --autostash\" thread, I did a bit of testing, and encountered a\ncase with silent data loss. In short: merge a branch introducing changes\nto a file. If the file has been renamed in the current branch, then \"git\nmerge\" follows the rename and brings changes to the renamed file, but\nuncommited changes in this file are overriden silently.\n\nI could have expected \"git merge --abort\" to fail, but the problem is\nreally more serious here: data loss is done silently before giving me an\nopportunity to do or abort anything.\n\nReproduction script below:\n\n#! /bin/sh\n\n# Create repo\ngit init git.$$\ncd git.$$\necho init > test.txt\ngit add test.txt\ngit commit -m init\n\n# Make a branch changing test.txt\ngit checkout -b branch\necho new > test.txt\ngit commit -am new\n\n# Move test.txt on master\ngit checkout master\ngit mv test.txt moved.txt\ngit commit -m move\n\n# Make uncommited changes to moved.txt\necho precious > moved.txt\n\n# Merge loses uncommited content \"precious\" in \"moved.txt\" silently\ngit merge --no-edit branch\nls # lists just moved.txt\ngit status # nothing to commit, working directory clean\ncat moved.txt # Says \"new\".\n\n-- \nMatthieu Moy\nhttp://www-verimag.imag.fr/~moy/\n"},{"id":"215079","messageId":"517547F8.3040004@viscovery.net","threadId":"33567","inReplyTo":"vpqobd6q5nm.fsf@grenoble-inp.fr","subject":"Re: [BUG] Silent data loss on merge with uncommited changes + renames","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2013-04-22T14:23:52Z","receivedAt":"2013-04-22T14:23:52Z","isPatch":false,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 4/22/2013 11:24, schrieb Matthieu Moy:\n> Following the discussion on \"merge with uncommited changes\" inside the\n> \"git pull --autostash\" thread, I did a bit of testing, and encountered a\n> case with silent data loss. In short: merge a branch introducing changes\n> to a file. If the file has been renamed in the current branch, then \"git\n> merge\" follows the rename and brings changes to the renamed file, but\n> uncommited changes in this file are overriden silently.\n\nCan you check whether your case is already covered by one of:\n\n  git grep expect_failure t/*merge*\n\nand if not, contribute a test case?\n\n-- Hannes\n"},{"id":"215082","messageId":"vpqtxmy7hih.fsf@grenoble-inp.fr","threadId":"33567","inReplyTo":"517547F8.3040004@viscovery.net","subject":"Re: [BUG] Silent data loss on merge with uncommited changes + renames","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@grenoble-inp.fr","sentAt":"2013-04-22T14:43:34Z","receivedAt":"2013-04-22T14:43:34Z","isPatch":false,"sender":{"key":"matthieu.moy@grenoble-inp.fr","avatar":"https://gravatar.com/avatar/72c8a2705971a25dfaff23cece15130d405685845d911aedd5667ace277f3fc5?d=mp&s=160"},"body":"Johannes Sixt <j.sixt@viscovery.net> writes:\n\n> Am 4/22/2013 11:24, schrieb Matthieu Moy:\n>> Following the discussion on \"merge with uncommited changes\" inside the\n>> \"git pull --autostash\" thread, I did a bit of testing, and encountered a\n>> case with silent data loss. In short: merge a branch introducing changes\n>> to a file. If the file has been renamed in the current branch, then \"git\n>> merge\" follows the rename and brings changes to the renamed file, but\n>> uncommited changes in this file are overriden silently.\n>\n> Can you check whether your case is already covered by one of:\n>\n>   git grep expect_failure t/*merge*\n\nIndeed, it's already here:\n\ntest_expect_failure 'will not overwrite unstaged changes in renamed file' '\n\tgit reset --hard c1 &&\n\tgit mv c1.c other.c &&\n\tgit commit -m rename &&\n\tcp important other.c &&\n\tgit merge c1a &&\n\ttest_cmp important other.c\n'\n\n-- \nMatthieu Moy\nhttp://www-verimag.imag.fr/~moy/\n"},{"id":"215086","messageId":"7v61zer3s9.fsf@alter.siamese.dyndns.org","threadId":"33567","inReplyTo":"vpqobd6q5nm.fsf@grenoble-inp.fr","subject":"Re: [BUG] Silent data loss on merge with uncommited changes + renames","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-04-22T15:19:50Z","receivedAt":"2013-04-22T15:19:50Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> writes:\n\n> I could have expected \"git merge --abort\" to fail, but the problem is\n> really more serious here: data loss is done silently before giving me an\n> opportunity to do or abort anything.\n\nI think this is a well known and longstanding failure case in the\nrecursive merge.  As it does not perform its internal operation\nwhile handling renames in clean and distinct steps (i.e. figure out\nwhat goes to where before touching any index entry or working tree,\nthen check if a proposed change to the index or the working tree\nconflicts with local changes, and finally carry out the proposed\nchange), it is somewhat hard to fix it correctly in the current\nimplementation, even though you probably could patch these up case\nby case basis.\n"}]}