{"action":"created","issue":{"url":"https://api.github.com/repos/libgit2/libgit2/issues/3230","labels_url":"https://api.github.com/repos/libgit2/libgit2/issues/3230/labels{/name}","comments_url":"https://api.github.com/repos/libgit2/libgit2/issues/3230/comments","events_url":"https://api.github.com/repos/libgit2/libgit2/issues/3230/events","html_url":"https://github.com/libgit2/libgit2/issues/3230","id":89059323,"number":3230,"title":"libgit2 stash apply doesn't behave like core git (2 cases)","user":{"login":"swisspol","id":627915,"avatar_url":"https://avatars.githubusercontent.com/u/627915?v=3","gravatar_id":"","url":"https://api.github.com/users/swisspol","html_url":"https://github.com/swisspol","followers_url":"https://api.github.com/users/swisspol/followers","following_url":"https://api.github.com/users/swisspol/following{/other_user}","gists_url":"https://api.github.com/users/swisspol/gists{/gist_id}","starred_url":"https://api.github.com/users/swisspol/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/swisspol/subscriptions","organizations_url":"https://api.github.com/users/swisspol/orgs","repos_url":"https://api.github.com/users/swisspol/repos","events_url":"https://api.github.com/users/swisspol/events{/privacy}","received_events_url":"https://api.github.com/users/swisspol/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2015-06-17T16:08:42Z","updated_at":"2015-06-20T19:22:02Z","closed_at":null,"body":"*From the discussion in #3018:*\r\n\r\n## Case 1\r\n\r\nStart with this state:\r\n```sh\r\nOn branch master\r\nChanges to be committed:\r\n  (use \"git reset HEAD <file>...\" to unstage)\r\n\r\n\tnew file:   bar.txt\r\n\tmodified:   hello_world.txt\r\n\r\nChanges not staged for commit:\r\n  (use \"git add <file>...\" to update what will be committed)\r\n  (use \"git checkout -- <file>...\" to discard changes in working directory)\r\n\r\n\tmodified:   foo.txt\r\n\r\nUntracked files:\r\n  (use \"git add <file>...\" to include in what will be committed)\r\n\r\n\ttest.txt\r\n```\r\n\r\nThen do `git stash -u` and verify that `git status` shows no pending changes afterwards.\r\n\r\nUsing `git stash apply` results in this state:\r\n```\r\nOn branch master\r\nChanges to be committed:\r\n  (use \"git reset HEAD <file>...\" to unstage)\r\n\r\n\tnew file:   bar.txt\r\n\r\nChanges not staged for commit:\r\n  (use \"git add <file>...\" to update what will be committed)\r\n  (use \"git checkout -- <file>...\" to discard changes in working directory)\r\n\r\n\tmodified:   foo.txt\r\n\tmodified:   hello_world.txt\r\n\r\nUntracked files:\r\n  (use \"git add <file>...\" to include in what will be committed)\r\n\r\n\ttest.txt\r\n```\r\n\r\nHowever using libgit2's `git_stash_apply()` results in this different state (which wasn't the case in my original implementation):\r\n```\r\nOn branch master\r\nChanges not staged for commit:\r\n  (use \"git add <file>...\" to update what will be committed)\r\n  (use \"git checkout -- <file>...\" to discard changes in working directory)\r\n\r\n\tmodified:   foo.txt\r\n\tmodified:   hello_world.txt\r\n\r\nUntracked files:\r\n  (use \"git add <file>...\" to include in what will be committed)\r\n\r\n\tbar.txt\r\n\ttest.txt\r\n```\r\n\r\nNotice that `bar.txt` wasn't restored in the index.\r\n\r\n## Case 2\r\n\r\nStart with this state:\r\n```\r\nOn branch master\r\nChanges to be committed:\r\n  (use \"git reset HEAD <file>...\" to unstage)\r\n\r\n\tnew file:   bar.txt\r\n\tmodified:   hello_world.txt\r\n\r\nChanges not staged for commit:\r\n  (use \"git add <file>...\" to update what will be committed)\r\n  (use \"git checkout -- <file>...\" to discard changes in working directory)\r\n\r\n\tmodified:   foo.txt\r\n\r\nUntracked files:\r\n  (use \"git add <file>...\" to include in what will be committed)\r\n\r\n\ttest.txt\r\n```\r\n\r\nThen do git `stash -u` and verify that `git status` shows no pending changes afterwards.\r\n\r\nUsing `git stash apply --index` results in this state:\r\n```\r\nOn branch master\r\nChanges to be committed:\r\n  (use \"git reset HEAD <file>...\" to unstage)\r\n\r\n\tnew file:   bar.txt\r\n\tmodified:   hello_world.txt\r\n\r\nChanges not staged for commit:\r\n  (use \"git add <file>...\" to update what will be committed)\r\n  (use \"git checkout -- <file>...\" to discard changes in working directory)\r\n\r\n\tmodified:   foo.txt\r\n\r\nUntracked files:\r\n  (use \"git add <file>...\" to include in what will be committed)\r\n\r\n\ttest.txt\r\n```\r\n\r\nHowever using libgit2's `git_stash_apply()` with the `GIT_STASH_APPLY_REINSTATE_INDEX` flag results in this different state (which wasn't the case in my original implementation):\r\n```\r\nOn branch master\r\nChanges not staged for commit:\r\n  (use \"git add <file>...\" to update what will be committed)\r\n  (use \"git checkout -- <file>...\" to discard changes in working directory)\r\n\r\n\tmodified:   foo.txt\r\n\tmodified:   hello_world.txt\r\n\r\nUntracked files:\r\n  (use \"git add <file>...\" to include in what will be committed)\r\n\r\n\tbar.txt\r\n\ttest.txt\r\n```\r\n\r\nNotice how the index wasn't restored at all."},"comment":{"url":"https://api.github.com/repos/libgit2/libgit2/issues/comments/113806805","html_url":"https://github.com/libgit2/libgit2/issues/3230#issuecomment-113806805","issue_url":"https://api.github.com/repos/libgit2/libgit2/issues/3230","id":113806805,"user":{"login":"ethomson","id":1130014,"avatar_url":"https://avatars.githubusercontent.com/u/1130014?v=3","gravatar_id":"","url":"https://api.github.com/users/ethomson","html_url":"https://github.com/ethomson","followers_url":"https://api.github.com/users/ethomson/followers","following_url":"https://api.github.com/users/ethomson/following{/other_user}","gists_url":"https://api.github.com/users/ethomson/gists{/gist_id}","starred_url":"https://api.github.com/users/ethomson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ethomson/subscriptions","organizations_url":"https://api.github.com/users/ethomson/orgs","repos_url":"https://api.github.com/users/ethomson/repos","events_url":"https://api.github.com/users/ethomson/events{/privacy}","received_events_url":"https://api.github.com/users/ethomson/received_events","type":"User","site_admin":false},"created_at":"2015-06-20T19:22:02Z","updated_at":"2015-06-20T19:22:02Z","body":"> So what's the reasoning behind not writing the index at the end of git_stash_apply()?\r\n\r\nSeems like it was probably an oversight.  Literally *one person* uses this functionality, so this is sort of like coding into a gaping blackhole of useful feedback."}}