Question

I'm writing a shell script that makes some git calls. In particular, I'm looking for a way to figure out if a git rebase call is successful or if there is a merge conflict. This is what I have so far.

returnStatus=$(git rebase master);
if [[ returnStatus == 1 ]]; then
    break;
else
    echo $branch; echo "rebased successfully";
fi

However, I think the first line isn't storing the return value, but the actual output of the rebase call. I need to know whether it was successful or not. How can I do this?

Thanks in advance! Any advice is much appreciated.

Was it helpful?

Solution

Just this should do:

if git rebase master; then
    echo "$branch"
    echo "rebased successfully"
else
    break
fi

I don't know why you have a break there... are you in a loop? otherwise you probably mean exit...

OTHER TIPS

$? contains the exit code of the last command. You can execute e.g.

git rebase ...
case $? in
    0) ... ;;
    1) ... ;;
    ...
esac
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top