3

I have such a beautiful target in my Makefile which works in bash without a problem. git checkout - should checkout a previous branch, but it doesn't, it stays in that develop branch and that's it, while executing this in bash it works well. Do I have bad if statement maybe? In Makefile you need to you double dollar sign in order to have a bash subcommand right?

SHELL := /bin/bash

rebase:
     git stash
     git checkout develop
     git pull --rebase origin develop
     if [ $$(git status --porcelain | wc -l) -lt 1 ]; then \
         git checkout -;\
         git rebase develop;\
         git stash apply;\
     fi;
holms
  • 9,112
  • 14
  • 65
  • 95
  • you could add some echo to the if block to rule out shell logic issues – max630 Apr 09 '18 at 04:28
  • You right - it was one file which haven't been added anywhere and it was untraced one, so I've added `git stash --include-untracked` – holms Apr 09 '18 at 05:14
  • Note: `git config pull.rebase true; git config rebase.autoStash true` can be of interest here: no need for stashing: https://stackoverflow.com/a/30209750/6309 – VonC Apr 09 '18 at 07:39

1 Answers1

1

If the '-' is somehow misinterpreted, try the alternative syntax @{-1}.

Both are mentioned here.
The if/then shell syntax used in Makefile seems correct.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Not sure I interpreted the last part correctly but the `if/then/fi` syntax has nothing to do with `GNU make`, it's shell syntax. – Tim Apr 09 '18 at 10:39
  • @Tim Yes, I meant the "shell syntax used in that Makefile". I have edited the answer. – VonC Apr 09 '18 at 11:32