1

I've got a script that takes changes from master and applies them to all branches. The script works well for us because we tag our releases and use dev-branches. We don't maintain a separate branch for each release.

git-rebase started failing recently with a return code of 1. Here's what it looks like when debugging it:

$ bash -x ./master-merge.sh 
++ git rev-parse HEAD
+ [[ -z 66dc925f94c15f92d0a2f16a03d8776df33e9144 ]]
+ ret_code=0
++ git rev-parse --abbrev-ref HEAD
+ current=master
+ git fetch --all
+ [[ 0 -eq 0 ]]
++ git branch -vv
++ grep -v ': gone]'
++ awk '{print $1}'
+ for branch in '$(git branch -vv | grep -v ": gone]" | awk '\''{print $1}'\'')'
+ '[' -e detsig ']'
+ echo 'Merging detsig'
Merging detsig
+ git checkout detsig
+ [[ 0 -ne 0 ]]
+ git rebase origin/detsig
+ [[ 1 -ne 0 ]]
+ echo 'Rebase failed for detsig'
Rebase failed for detsig
+ ret_code=1
+ continue
+ for branch in '$(git branch -vv | grep -v ": gone]" | awk '\''{print $1}'\'')'
+ '[' -e ecies ']'
+ echo 'Merging ecies'
Merging ecies
+ git checkout ecies
+ [[ 0 -ne 0 ]]
+ git rebase origin/ecies
+ [[ 1 -ne 0 ]]
+ echo 'Rebase failed for ecies'
Rebase failed for ecies
+ ret_code=1
+ continue
+ for branch in '$(git branch -vv | grep -v ": gone]" | awk '\''{print $1}'\'')'
+ '[' -e hmqv ']'
+ echo 'Merging hmqv'
Merging hmqv
+ git checkout hmqv
+ [[ 0 -ne 0 ]]
+ git rebase origin/hmqv
+ [[ 1 -ne 0 ]]
+ echo 'Rebase failed for hmqv'
Rebase failed for hmqv
+ ret_code=1
+ continue

The git-rebase man page does not discuss return codes, so I'm not sure what it means. I'm also not sure about other values the command can return.

What does a git-rebase return code of 1 mean? Does git-rebase have "hard failure" and "soft failure" return codes such that I should relax the test against 0?


$ git --version
git version 1.8.5.2 (Apple Git-48)

$ cat master-merge.sh 
#!/usr/bin/env bash

# make sure this is a Git directory
if [[ (-z $(git rev-parse HEAD 2>/dev/null)) ]]; then
    echo "$PWD is not a Git repository"
    [[ "$0" = "$BASH_SOURCE" ]] && exit 2 || return 2
fi

ret_code=0
current=$(git rev-parse --abbrev-ref HEAD 2>/dev/null)

git fetch --all &>/dev/null
if [[ ("$?" -eq "0") ]]; then
    for branch in $(git branch -vv | grep -v ": gone]" | awk '{print $1}'); do

        # For some reason, this picks up all files
        if [ -e "$branch" ]; then
            continue
        fi

        echo "Merging $branch"

        git checkout "$branch" &>/dev/null
        if [[ ("$?" -ne "0") ]]; then
            echo "Checkout failed for $branch"
            ret_code=1
            continue
        fi

        git rebase "origin/$branch" &>/dev/null
        if [[ ("$?" -ne "0") ]]; then
            echo "Rebase failed for $branch"
            ret_code=1
            continue
        fi

        git merge master -m "Merge 'master' into '$branch'"
        if [[ ("$?" -ne "0") ]]; then
            echo "Merge failed for $branch"
            ret_code=1
            continue
        fi

        git push
        if [[ ("$?" -ne "0") ]]; then
            echo "Push failed for $branch"
            ret_code=1
            continue
        fi
    done    
fi

if [[ (! -z "$current") ]]; then
    echo "Switching to $current"
    git checkout "$current" &>/dev/null
fi

[[ "$0" = "$BASH_SOURCE" ]] && exit "$ret_code" || return "$ret_code"
  • 2
    redirect to logfile instead of /dev/null and read the error message from git rebase – lesmana Sep 8 '16 at 15:00
  • @lesmana - a redirect only gives me one error message in this particular instance. I'm interested in all of the error messages and return codes (and if there's a difference between hard and soft failures). – user56041 Sep 8 '16 at 15:22
  • Perhaps this discussion would be helpful: stackoverflow.com/questions/4917871/… – Thomas N Sep 8 '16 at 18:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy