0

I create a shell script for run project in a local environment. When running the script I need include if git update also updates my local code with git code before run project.

cd /var/www/html/project && \
    git stash && \
    git pull && \
    git stash apply

There is my try. But problem their when conflict happens no way to change conflict. I need when git stash apply if conflict happen stop a script make way to resolve conflict.

Saditha Udayanga
  • 354
  • 2
  • 10
  • 1
    `git pull` already has an [`--autostash` option](https://git-scm.com/docs/git-pull#Documentation/git-pull.txt---autostash). It stops if the `git pull` part triggers a conflict, and leaves your stashed changes in the stash. Is this the behavior you are looking for ? – LeGEC Jul 30 '20 at 09:41
  • 1
    note : this option was added pretty recently to git, you may need to update your local `git` to version 2.27 to have this option. A more detailed history for this option in [this answer](https://stackoverflow.com/a/30209750/86072) – LeGEC Jul 30 '20 at 09:43
  • Yes, that is I'm looking for. But a problem there when conflicts happen. – Saditha Udayanga Jul 30 '20 at 10:24

1 Answers1

2

git pull or git stash apply will exit with an error code (= an exit code different from '0') if a conflict occurs.

In bash, the last command's exit code is stored in $? :

exitCode=$?
if [ $exitCode -ne 0 ]; then
    echo "*** something errored"
    exit $exitCode
fi
LeGEC
  • 46,477
  • 5
  • 57
  • 104