libgit2 / libgit2/libgit2

Stash apply requires clean index

Open
#5,501 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
10.6k
Forks
2.7k
PR merge metrics
No merged PRs in 30d

Description

Reproduction steps

try to apply a stash when index is dirty. This is specifically prevented by https://github.com/libgit2/libgit2/blob/66137ff6ea9e516e0fa840134393d5a81d5b86e9/src/stash.c#L900 which was added in #3259

However, git allows this:

3066 $ git init
Initialized empty Git repository in /home/wmertens/testgit/.git/
3067 $ touch bar
3071 $ git commit  -a -m 'hi'
[master (root-commit) b37d552] hi
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 bar
3082 $ echo hi  > foo
3084 $ git add foo
3088 $ git stash
Saved working directory and index state WIP on master: b37d552 hi
3089 $ echo boom  > foo
3091 $ git add foo
3093 $ git stash apply
CONFLICT (add/add): Merge conflict in foo
Auto-merging foo
3094 $ git status
On branch master
Unmerged paths:
  (use "git restore --staged <file>..." to unstage)
  (use "git add <file>..." to mark resolution)
        both added:      foo
3095 $ cat foo
<<<<<<< Updated upstream
boom
=======
hi
>>>>>>> Stashed changes

IMHO libgit should behave like git, and the clean check should not be done.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/stash.c around the clean-index check at the cited line, then compare the behavior with the provided Git reproduction. Remove the restriction only if the existing stash-apply flow can handle the dirty index; done means applying the stash permits the conflict behavior shown by Git.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, git
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.