8

I set up a git alias like this:

git config --global alias.popmerge '!git stash pop && git merge master'

Then I call it, like this:

git popmerge

The "git stash pop" is executed, but the "git merge master" is ignored.

If I run "git merge master" right after the "git popmerge"... it sumply runs as expected, performing the merge.

I have other aliases with long sequences of commands... and they run flawlessly. It seems something at "git stash pop" makes the alias process to halt... Is it possible to avoid this behavior? How?

Thanks.

SQB
  • 3,926
  • 2
  • 28
  • 49
J. Bruni
  • 20,322
  • 12
  • 75
  • 92
  • 1
    Are you sure, you first want to make your working directory dirty using `stash pop` and then do a `merge`? Wouldn't it be safer to first do the `merge`, then `pop`? Also, I am not sure ignoring the exit status, accepted as an answer, is really desirable. Doesn't failure in `stash pop` mean, there were conflicts? Do you really want to increase the mess doing another conflict-prone `merge`? – Tilman Vogel May 25 '11 at 15:46
  • Yes, I am sure. The sole `stash save / stash pop` purpose is ONLY to allow the `checkout master` command [in this sequence](http://stackoverflow.com/questions/6112852/git-website-update-strategy-how-to-sync-dev-and-live-repositories/6121482#6121482) to be always successfull. I want the stash stack to be empty, and the `stash pop` to be always successfull. **The exit status of a successfull `stash pop` is not zero.** Don't ask me why. That's why I needed the `;` workaround. Consider the chances of conflict coming from a `pop` immediately after `save`: it is zero, in this context. – J. Bruni May 27 '11 at 07:24
  • ok, didn't know the save was based exactly on the same commit. Then, the only conflicts to be expected are from merging master to dev - fine. Too bad git command exit status behaviour is not really documented... – Tilman Vogel May 27 '11 at 09:19

1 Answers1

8

Have you checked the exit code from stash pop?

&& implies that the subsequent list is only executed if the exitcode is 0 (success).

You can simply ignore the exitcode by using ; instead of &&.


Verify the success by using stuff like:

true  && echo ok || echo fail   # echoes "ok"

false && echo ok || echo fail   # echoes "fail"
Leif Wickland
  • 3,693
  • 26
  • 43
sehe
  • 374,641
  • 47
  • 450
  • 633