{"thread":{"id":"37146","subject":"git update-index not delete lock file when using different worktree","startedAt":"2014-07-17T03:18:45Z","lastAt":"2014-07-18T08:21:35Z","messageCount":4,"participants":["Yue Lin Ho","Duy Nguyen"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"246212","messageId":"1405567125455-7615300.post@n2.nabble.com","threadId":"37146","inReplyTo":null,"subject":"git update-index not delete lock file when using different worktree","fromName":"Yue Lin Ho","fromEmail":"yuelinho777@gmail.com","sentAt":"2014-07-17T03:18:45Z","receivedAt":"2014-07-17T03:18:45Z","isPatch":false,"sender":{"key":"yuelinho777@gmail.com","avatar":"https://gravatar.com/avatar/dbf9652003664c7518c86149f9e24df4d178c52526eaffab6f3c3d15b61671e2?d=mp&s=160"},"body":"This is a [issue from\nTortoiseGit](https://code.google.com/p/tortoisegit/issues/detail?id=2233).\nAfter doing some test, I report it here.\nThe following is the testing information I have tested.\n\n### Folder Structure\n```\nTest\n  |-- myrepo\n  |     |-- bar.txt\n  |     |-- foo.txt\n  |\n  |-- myrepo.git\n        |-- .git\n```\nTesting repository is\n[here](https://code.google.com/p/tortoisegit/issues/detail?id=2233#c2).\n\n### Using different worktree\nSet the config file (in the .git folder)\n```\n[core]\n\tworktree = ../../myrepo\n```\n\n### Test 1 - Git Bash\n```\nUser@PC /d/Repo/myrepo.git (master)\n$ git --version\ngit version 1.9.4.msysgit.0\n\nUser@PC /d/Repo/myrepo.git (master)\n$ git update-index --refresh\nfatal: Unable to write new index file\n```\nD:\\Repo\\myrepo.git\\\\**index.lock** is not deleted.\n\n### Test 2 - Git 2.0.0\nCopy testing repository into ```C:\\msysgit\\MyTest```\n\nExecute```msys.bat```\n```$ vagrant up```\n```$ vagrant ssh```\n```vagrant@precise64:/vagrant/git$ cd /vagrant```\n```vagrant@precise64:/vagrant$ cd mytest/myrepo.git```\n```\nvagrant@precise64:/vagrant/mytest/myrepo.git$ git --version\ngit version 2.0.0\n```\n```\nvagrant@precise64:/vagrant/mytest/myrepo.git$ git update-index --refresh\nfatal: Unable to write new index file\n```\nAlso, **index.lock is not deleted.**\n\n### Test 3 - gitdll of TortoiseGit \n(git version 1.9.0)\nTracing the source code into **compat/mingw.c**\nline 289 : xutftowcs_canonical_path() get the value of var. wpathname\n```\nD:\\Repo\\myrepo\\.git\\index.lock\n```\nIt should be\n```\nD:\\Repo\\myrepo.git\\.git\\index.lock\n```\n\nline 294 : _wunlink() try to delete the\nfile.(```D:\\Repo\\myrepo\\.git\\index.lock```)\nline 295 : GetLastError() return 3(ERROR_PATH_NOT_FOUND)\n(Actually, there is no ```D:\\Repo\\myrepo\\.git``` folder.)\n\n\n\n\n\n--\nView this message in context: http://git.661346.n2.nabble.com/git-update-index-not-delete-lock-file-when-using-different-worktree-tp7615300.html\nSent from the git mailing list archive at Nabble.com.\n"},{"id":"246218","messageId":"1405585628972-7615306.post@n2.nabble.com","threadId":"37146","inReplyTo":"1405567125455-7615300.post@n2.nabble.com","subject":"Re: git update-index not delete lock file when using different worktree","fromName":"Yue Lin Ho","fromEmail":"yuelinho777@gmail.com","sentAt":"2014-07-17T08:27:08Z","receivedAt":"2014-07-17T08:27:08Z","isPatch":false,"sender":{"key":"yuelinho777@gmail.com","avatar":"https://gravatar.com/avatar/dbf9652003664c7518c86149f9e24df4d178c52526eaffab6f3c3d15b61671e2?d=mp&s=160"},"body":"I see that refresh() of update_index.c calls setup_work_tree() to change dir\nto working tree.\nAnd the dir is not changed back to git dir before commit_lock_file() or\nrollback_lock_file() is called.\n\nSo, commit_lock_file() rename file failed.\nor rollback_lock_file() delete file failed.\n\n\n\n--\nView this message in context: http://git.661346.n2.nabble.com/git-update-index-not-delete-lock-file-when-using-different-worktree-tp7615300p7615306.html\nSent from the git mailing list archive at Nabble.com.\n"},{"id":"246222","messageId":"20140717103654.GA18897@lanh","threadId":"37146","inReplyTo":"1405585628972-7615306.post@n2.nabble.com","subject":"Re: git update-index not delete lock file when using different worktree","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2014-07-17T10:36:54Z","receivedAt":"2014-07-17T10:36:54Z","isPatch":false,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Thu, Jul 17, 2014 at 01:27:08AM -0700, Yue Lin Ho wrote:\n> I see that refresh() of update_index.c calls setup_work_tree() to change dir\n> to working tree.\n> And the dir is not changed back to git dir before commit_lock_file() or\n> rollback_lock_file() is called.\n> \n> So, commit_lock_file() rename file failed.\n> or rollback_lock_file() delete file failed.\n\nI think you're on the right track. Although the problem is\nhold_locked_index() in cmd_update_index() when the index path is\nrelative. After setup_work_tree(), the saved path points to a wrong\nplace and can't be unlinked anymore.\n\nThis patch seems to fix it\n\n-- 8< --\ndiff --git a/lockfile.c b/lockfile.c\nindex 2a800ce..69fe837 100644\n--- a/lockfile.c\n+++ b/lockfile.c\n@@ -264,7 +264,8 @@ int commit_lock_file(struct lock_file *lk)\n \n int hold_locked_index(struct lock_file *lk, int die_on_error)\n {\n-\treturn hold_lock_file_for_update(lk, get_index_file(),\n+\treturn hold_lock_file_for_update(lk,\n+\t\t\t\t\t absolute_path(get_index_file()),\n \t\t\t\t\t die_on_error\n \t\t\t\t\t ? LOCK_DIE_ON_ERROR\n \t\t\t\t\t : 0);\n-- 8< --\n\nWe could turn all lockfile's path absolute when setup_work_tree()\nmoves pwd, but that seems dangerous without looking through how all\nlockfiles are used.\n\n--\nDuy\n"},{"id":"246288","messageId":"1405671695257-7615378.post@n2.nabble.com","threadId":"37146","inReplyTo":"20140717103654.GA18897@lanh","subject":"Re: git update-index not delete lock file when using different worktree","fromName":"Yue Lin Ho","fromEmail":"yuelinho777@gmail.com","sentAt":"2014-07-18T08:21:35Z","receivedAt":"2014-07-18T08:21:35Z","isPatch":false,"sender":{"key":"yuelinho777@gmail.com","avatar":"https://gravatar.com/avatar/dbf9652003664c7518c86149f9e24df4d178c52526eaffab6f3c3d15b61671e2?d=mp&s=160"},"body":"Hi Duy:\n\nI tested your patch. It works. :)\n(only one case.)\n\nThank you.\n\nThere are 26 hold_locked_index() in these files:\n\nLine  475 of builtin\\add.c\nLine 4234 of \\builtin\\apply.c\nLine  259 of \\builtin\\checkout.c\nLine  448 of \\builtin\\checkout.c\nLine  139 of \\builtin\\checkout-index.c\nLine  643 of \\builtin\\clone.c\nLine  323 of \\builtin\\commit.c\nLine  362 of \\builtin\\commit.c\nLine  383 of \\builtin\\commit.c\nLine  434 of \\builtin\\commit.c\nLine 1295 of \\builtin\\commit.c\nLine  479 of \\builtin\\describe.c\nLine  211 of \\builtin\\diff.c\nLine  660 of \\builtin\\merge.c\nLine  700 of \\builtin\\merge.c\nLine   88 of \\builtin\\mv.c\nLine  152 of \\builtin\\read-tree.c\nLine  338 of \\builtin\\reset.c\nLine  296 of \\builtin\\rm.c\nLine  808 of \\builtin\\update-index.c\nLine  588 of \\cache-tree.c\nLine   75 of \\merge.c\nLine 2004 of \\merge-recursive.c\nLine  482 of \\rerere.c\nLine  301 of \\sequencer.c\nLine  671 of \\sequencer.c\n\nYue Lin\n\n\n\n\n--\nView this message in context: http://git.661346.n2.nabble.com/git-update-index-not-delete-lock-file-when-using-different-worktree-tp7615300p7615378.html\nSent from the git mailing list archive at Nabble.com.\n"}]}