{"action":"created","issue":{"url":"https://api.github.com/repos/libgit2/libgit2sharp/issues/1128","labels_url":"https://api.github.com/repos/libgit2/libgit2sharp/issues/1128/labels{/name}","comments_url":"https://api.github.com/repos/libgit2/libgit2sharp/issues/1128/comments","events_url":"https://api.github.com/repos/libgit2/libgit2sharp/issues/1128/events","html_url":"https://github.com/libgit2/libgit2sharp/issues/1128","id":91931047,"number":1128,"title":"Repository.RemoveUntrackedFiles() throws exception : fail to rename git lockfile : access denied","user":{"login":"john-grandy-opentable","id":3277564,"avatar_url":"https://avatars.githubusercontent.com/u/3277564?v=3","gravatar_id":"","url":"https://api.github.com/users/john-grandy-opentable","html_url":"https://github.com/john-grandy-opentable","followers_url":"https://api.github.com/users/john-grandy-opentable/followers","following_url":"https://api.github.com/users/john-grandy-opentable/following{/other_user}","gists_url":"https://api.github.com/users/john-grandy-opentable/gists{/gist_id}","starred_url":"https://api.github.com/users/john-grandy-opentable/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/john-grandy-opentable/subscriptions","organizations_url":"https://api.github.com/users/john-grandy-opentable/orgs","repos_url":"https://api.github.com/users/john-grandy-opentable/repos","events_url":"https://api.github.com/users/john-grandy-opentable/events{/privacy}","received_events_url":"https://api.github.com/users/john-grandy-opentable/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":13,"created_at":"2015-06-29T23:01:57Z","updated_at":"2015-07-17T03:08:23Z","closed_at":"2015-07-17T03:08:23Z","body":"Windows Server 2008 \r\nMcAfee Agent v4.8.0.1938 \r\nno indexing service \r\nASP.NET C# app \r\nlibgit2sharp v0.21.0.176 NuGet package \r\n\r\nMy ASP.NET app uses libgit2sharp `Repository.Clone()` method to create a local clone of a GitHub repo. ( But note that I experience the same errors when I manually clone the repo via CLI `git clone` on the deploy server. )\r\n\r\nOn my local dev workstation, various libgit2sharp operations succeed ( e.g. `Repository.Checkout()` , `Repository.Fetch()` ) with no issues.\r\n\r\nHowever, once my app is deployed to a remote server and hosted inside IIS , I'm encountering what appear to be either permissions or locking issues.\r\n\r\n    Repository.RemoveUntrackedFiles()\r\n\r\nException thrown :\r\n\r\n    Failed to rename lockfile to 'c:/github/{org-name}/{target-repo-name}/.git/index': Access is denied.\r\n\r\nIf I re-attempt the operation it again fails but this time with a different exception :\r\n\r\n    The index is locked. This might be due to a concurrent or crashed process.\r\n\r\nSubsequent attempts ( no matter how many ) fail with this same exception.\r\n\r\nIssue is not resolved with iisreset or reboot.\r\n\r\nIf I re-create the local repo by going to cli and deleting local repo folder and then running git clone, I'm now able to successfully execute various git operations until I again attempt `Repository.RemoveUntrackedFiles()` at which point the above error-sequence re-occurs.\r\n\r\nEDIT : I'm also encountering similar issues with\r\n\r\n    Repository.Checkout()\r\n\r\nException thrown : \r\n\r\n    Failed to rename lockfile to 'c:/github/{org-name}/{target-repo-name}/.git/index': Access is denied.\r\n\r\nI then go to the server and from the command line attempt `git checkout master` :\r\n\r\n    c:\\github\\{org-name}\\{target-repo-name}>git checkout master\r\n    fatal: Unable to create 'c:/github/{org-name}/{target-repo-name}/.git/index.lock': File exists.\r\n\r\nIf no other git process is currently running, this probably means a\r\ngit process crashed in this repository earlier. Make sure no other git\r\nprocess is running and remove the file manually to continue.\r\n"},"comment":{"url":"https://api.github.com/repos/libgit2/libgit2sharp/issues/comments/122157018","html_url":"https://github.com/libgit2/libgit2sharp/issues/1128#issuecomment-122157018","issue_url":"https://api.github.com/repos/libgit2/libgit2sharp/issues/1128","id":122157018,"user":{"login":"john-grandy-opentable","id":3277564,"avatar_url":"https://avatars.githubusercontent.com/u/3277564?v=3","gravatar_id":"","url":"https://api.github.com/users/john-grandy-opentable","html_url":"https://github.com/john-grandy-opentable","followers_url":"https://api.github.com/users/john-grandy-opentable/followers","following_url":"https://api.github.com/users/john-grandy-opentable/following{/other_user}","gists_url":"https://api.github.com/users/john-grandy-opentable/gists{/gist_id}","starred_url":"https://api.github.com/users/john-grandy-opentable/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/john-grandy-opentable/subscriptions","organizations_url":"https://api.github.com/users/john-grandy-opentable/orgs","repos_url":"https://api.github.com/users/john-grandy-opentable/repos","events_url":"https://api.github.com/users/john-grandy-opentable/events{/privacy}","received_events_url":"https://api.github.com/users/john-grandy-opentable/received_events","type":"User","site_admin":false},"created_at":"2015-07-17T03:08:23Z","updated_at":"2015-07-17T03:08:23Z","body":"@nulltoken I refactored my code to wrap every usage of Repository methods in a `using(){}` block but it did not solve my issue.\r\n\r\nHere's the error-sequence : on the remote server I manually clean-up. From CLI I delete local repo dir and `git clone` the local repo. Then I logoff the server.\r\n\r\nMy app code creates a new branch and maps it to the remote origin. Next I successfully execute 'Repository.Network.Fetch()` , but when I attempt `Repository.RemoveUntrackedFiles()` I receive exception : \r\n\r\n    [Failed to rename lockfile to 'c:/github/{org-name}/{repo-name}/.git/index': Access is denied.\r\n\r\nRDP to remote server Unlocker indicates no locks on local repo dir but both `\\.git\\index` and `\\.git\\index.lock` are present.\r\n\r\nPlease note that if repeat the experiment with commented-out `Repository.RemoveUntrackedFiles()` , the next git operation `Repository.Checkout()` will trigger the same exception.  So the Access Denied error appears to be triggered by any `Repository` operation that accesses `\\.git\\index`"}}