eldoy / fiks

Repo management tool
MIT License
0 stars 0 forks source link

Fiks pull stash #8

Closed eldoy closed 5 months ago

eldoy commented 5 months ago

When doing git pull, you changes are stashed, and after the pull they are re-applied with git stash apply. The problem is when the stash is not empty from before, then you stash apply unwanted changes. Maybe it's better if pull just fails and you get an error message?

Please discuss solutions.

acmb commented 5 months ago

Hei, @eldoy!

My tests lead me to believe that git stash apply translates to git stash apply 0, applying the latest stash, not all of them at once. This also seems to be the behaviour described in this article.

Screenshot 2024-06-10 at 15 54 37

So, in practice, we'd be applying the stash we just created before pull, not including previous unwanted changes. My only suggestion would be to consider the option of running git stash pop instead of git stash apply, so we would apply the latest stash and remove it simultaneously. At the same time, I fear using pop may lead to lost changes if we encounter some unexpected bug in fiks, so it is probably safer to use apply.

Did I misunderstand the issue in any way? Please let me know your thoughts.

eldoy commented 5 months ago

The problem is that you might have done git stash before and forgot to re-apply. When we do git stash, nothing new happens, but when we do git stash apply, then the old stash is being applied.

Maybe the safest is to abort the pull if we have uncommitted changes? The alternative would be to do git stash clear before apply. I'm ok with it, but it's risky.

acmb commented 5 months ago

Oh, got it!

The scenario is: we're doing pull but we don't have changes. Meaning our git stash does nothing and in that case we shouldn't apply the latest stash, because it was not created in the context of our current operation. Did I get it right?

In that case, we could do something like this:

var res = extras.get(`git -C ./${directory} stash`)
var stashed = res.includes('Saved working directory')

extras.get(`git -C ./${directory} pull --rebase`)

stashed && extras.get(`git -C ./${directory} stash apply`)

Meaning, we will only apply the latest stash if we actually stashed something before pulling.

What are your thoughts on this solution?

eldoy commented 5 months ago

Ok, if that works then that should solve it.