Thanks to visit codestin.com
Credit goes to github.com

Skip to content

git_stash_pop() and git_stash_apply() #1447

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
TNick opened this issue Mar 30, 2013 · 5 comments
Closed

git_stash_pop() and git_stash_apply() #1447

TNick opened this issue Mar 30, 2013 · 5 comments

Comments

@TNick
Copy link

TNick commented Mar 30, 2013

As far as I can tell git_stash_save() does the following:

  • get last commit
  • create a commit for index - commit_index()
  • if untracked and/or ignored files are requested then create a commit for these - commit_untracked()
  • create a commit for workdir - commit_worktree() - that will be returned; set previous three commits (base, index, untracked in this order) as parents for this one
  • create a reference with update_reflog() that points to oid of the commit in previous step
  • reset index and worktree

Based on the model of git_stash_drop() I suggest this implementation tested with a repository created as follows:

git init
echo "File content 1" > f1.txt
echo "File content 2" > f2.txt
echo "File content 3" > f3.txt
git add f1.txt
git add f2.txt
git ci -m "Added files to repo"
echo "File content 1 changed" > f1.txt
rm f2.txt
git status
# On branch master
# Changes not staged for commit:
#   (use "git add/rm <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   f1.txt
#   deleted:    f2.txt
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   f3.txt

This fails to restore untracked files:

git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   modified:   f1.txt
#   deleted:    f2.txt
#   new file:   f3.txt
@carlosmn
Copy link
Member

These functions can't be implemented until merge support is in. What you're doing with stash pop or stash apply is applying a patch, not restoring files.

@TNick
Copy link
Author

TNick commented Mar 30, 2013

I see, thanks for the feedback. I see #1389, #1007, #769. These are the issue to follow to see how merge implementation advances?

@jspahrsummers
Copy link
Contributor

It would be awesome to use libgit2 for this. Right now, we're shelling out to git, which is messy and fragile.

@swisspol
Copy link
Contributor

I added a workaround implementation for git stash apply in #2636.

@ethomson
Copy link
Member

Closed now that we have some pull requests like #2636 ...!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants