{"thread":{"id":"27840","subject":"Bug Report: Creating a hardlink to any of the file in git repo cause the source file to show up in git commit message editor under \"Changes not staged for commit\" section.","startedAt":"2011-07-18T03:42:52Z","lastAt":"2011-07-18T18:37:53Z","messageCount":2,"participants":["Michael","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"171539","messageId":"02a20a168c52beb42e57258bcc5c0551@mail.mxes.net","threadId":"27840","inReplyTo":null,"subject":"Bug Report: Creating a hardlink to any of the file in git repo cause the source file to show up in git commit message editor under \"Changes not staged for commit\" section.","fromName":"Michael","fromEmail":"git-scm@webhippo.net","sentAt":"2011-07-18T03:42:52Z","receivedAt":"2011-07-18T03:42:52Z","isPatch":false,"sender":{"key":"git-scm@webhippo.net","avatar":null},"body":" Creating a hardlink to any of the file in git repo cause the source \n file\n to show up in git commit message editor under \"Changes not staged for \n commit\"\n section.\n\n Reproduced on:\n Ubuntu 10.04, Gentoo, FreeBSD\n Git version: 1.7.6\n\n Bug has been observed by atleast 3 people.\n\n Follow these steps to reproduce:\n\n # create test repo\n cd /tmp\n mkdir -p test-repo/repo\n cd test-repo/repo\n git init\n git config user.name \"Foo\"\n git config user.email \"foo@example.com\"\n\n # put some files in the repo\n touch FILE1 FILE2 FILE3 FILE4 FILE5\n git add -A\n git commit -m \"initial commit\"\n\n # create git hook that hardlink FILE2 and FILE3 and remove the \n hardlinks\n # right then and there\n echo \"ln -vf FILE2 ../HARDLINK_TO_FILE2\" >| .git/hooks/pre-commit\n echo \"rm -vf ../HARDLINK_TO_FILE2\" >> .git/hooks/pre-commit\n echo \"ln -vf FILE3 ../HARDLINK_TO_FILE3\" >> .git/hooks/pre-commit\n echo \"rm -vf ../HARDLINK_TO_FILE3\" >> .git/hooks/pre-commit\n\n # make pre-commit executable\n chmod u+x .git/hooks/pre-commit\n\n # modify FILE1\n echo \"hello world\" >> FILE1\n\n # run git status\n git status\n -------------------------------------------------------------------------------\n # On branch master\n # Changes not staged for commit:\n #   (use \"git add <file>...\" to update what will be committed)\n #   (use \"git checkout -- <file>...\" to discard changes in working \n directory)\n #\n #       modified:   FILE1\n #\n no changes added to commit (use \"git add\" and/or \"git commit -a\")\n -------------------------------------------------------------------------------\n\n # try commit using nano as commit editor and without usin -a flag\n VISUAL=nano git commit FILE1\n\n # Despite the fact that they are modified FILE2 and FILE3 will show in \n the\n # commit message, under \"Changes not staged for commit\" section\n # like so:\n\n --------------------------------------------------------------------------------\n # Please enter the commit message for your changes. Lines starting\n # with '#' will be ignored, and an empty message aborts the commit.\n # Explicit paths specified without -i nor -o; assuming --only paths...\n # On branch master\n # Changes to be committed:\n #   (use \"git reset HEAD <file>...\" to unstage)\n #\n #       modified:   FILE1\n #\n # Changes not staged for commit:\n #   (use \"git add <file>...\" to update what will be committed)\n #   (use \"git checkout -- <file>...\" to discard changes in working \n directory)\n #\n #       modified:   FILE2\n #       modified:   FILE3\n #\n --------------------------------------------------------------------------------\n\n\n In case anyone interested, tor me this happens when I do a python EGG \n build\n which hardlinks files in order to build.\n\n\n -- Michael\n"},{"id":"171598","messageId":"7vwrffjuym.fsf@alter.siamese.dyndns.org","threadId":"27840","inReplyTo":"02a20a168c52beb42e57258bcc5c0551@mail.mxes.net","subject":"Re: Bug Report: Creating a hardlink to any of the file in git repo cause the source file to show up in git commit message editor under \"Changes not staged for commit\" section.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-07-18T18:37:53Z","receivedAt":"2011-07-18T18:37:53Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Michael <git-scm@webhippo.net> writes:\n\n> echo \"ln -vf FILE2 ../HARDLINK_TO_FILE2\" >| .git/hooks/pre-commit\n> echo \"rm -vf ../HARDLINK_TO_FILE2\" >> .git/hooks/pre-commit\n> echo \"ln -vf FILE3 ../HARDLINK_TO_FILE3\" >> .git/hooks/pre-commit\n> echo \"rm -vf ../HARDLINK_TO_FILE3\" >> .git/hooks/pre-commit\n\nThis does not have to do anything with hardlink. A simple \"touch\" should\ndo as long as FILE2/FILE3 are sufficiently old.\n\nYou are smudging cached stat information in your pre-commit hook (st_ctime\nwould be different), and that is shown as a difference between the working\ntree and the index (note that nowhere in githooks documentation we say\npre-commit hook is allowed to muck with the working tree files). I think\nwe do refresh the cached stat information before running the pre-commit\nhook so that the hook can check the list of working tree files that are\ndifferent from the index using diff-files, but the purpose of the said\nhook is to validate, and not affect, the state of the working tree, and I\nwouldn't be surprised if we do not update the cached stat information\nafter the hook returns control to us.\n\nIf you really want to munge the working tree inside pre-commit, I think\nadding \"git update-index --refresh\" at the end of pre-commit hook would\nmake the phantom change go away.\n"}]}