|
38 | 38 |
|
39 | 39 | for remote in $list;
|
40 | 40 | do
|
41 |
| - # check commits and branches |
42 |
| - out=`git push --all -n $remote 2>&1` |
43 |
| - if [ "$out" != 'Everything up-to-date' ]; |
| 41 | + # Check commits and branches |
| 42 | + # An approach where you `git push --all -n $remote 2>&1` and check whether the result is |
| 43 | + # 'Everything up-to-date' can (and often will) yield |
| 44 | + # "To prevent you from losing history, non-fast-forward updates were rejected" |
| 45 | + # Since such an approach does traffic with the remote anyway, I choose to fetch the origin |
| 46 | + # and inspect it's branches. This is a bit inefficient network-wise, but couldn't see a better solution |
| 47 | + if ! git fetch $remote |
44 | 48 | then
|
45 |
| - echo -e "***** Dirty commits/branches: *****\n$out" >&2 |
| 49 | + echo "could not git fetch $remote" >&2 |
46 | 50 | ret=1
|
47 | 51 | fi
|
| 52 | + IFS_BACKUP=$IFS |
| 53 | + IFS=$'\n' |
| 54 | + for branch in `git branch` |
| 55 | + do |
| 56 | + branch=${branch/\*/}; |
| 57 | + branch_local=${branch// /}; # git branch prefixes branches with spaces. and spaces in branchnames are illegal. |
| 58 | + if ! git branch -r --contains $branch_local 2>/dev/null | grep -q "^ $remote/" |
| 59 | + then |
| 60 | + echo "Branch $branch_local is not contained within remote $remote!" >&2 |
| 61 | + ret=1 |
| 62 | + fi |
| 63 | + if ! git branch -r | grep -q "^ $remote/$branch_local" |
| 64 | + then |
| 65 | + echo "Branch $branch_local exists, but not $remote/$branch_local" >&2 |
| 66 | + ret=1 |
| 67 | + fi |
| 68 | + done |
| 69 | + IFS=$IFS_BACKUP |
48 | 70 |
|
49 |
| - # check tags |
| 71 | + # Check tags |
50 | 72 | out=`git push --tags -n $remote 2>&1`
|
51 | 73 | if [ "$out" != 'Everything up-to-date' ];
|
52 | 74 | then
|
|
55 | 77 | fi
|
56 | 78 | done
|
57 | 79 |
|
58 |
| -# added/deleted/modified files in the currently checked out branch or index. |
59 |
| -# this should do I think. (other branch, esp remote tracking branch should not be checked, right? maybe if this one is dirty..) |
| 80 | +# Check WC/index |
60 | 81 | cur_branch=`git branch | grep '^\* ' | cut -d ' ' -f2`
|
61 | 82 | cur_branch=${cur_branch// /}
|
62 | 83 | exp="# On branch $cur_branch
|
63 | 84 | nothing to commit (working directory clean)"
|
64 | 85 | out=`git status`
|
65 |
| -if [ "$out" != "$exp" ]; |
| 86 | +if [ "$out" != "$exp" ] |
66 | 87 | then
|
67 |
| - echo "***** Dirty WC or index *****" >&2 |
68 |
| - git status |
69 |
| - ret=1 |
| 88 | + # usually i'd use bash regex, but this case is multiple-lines so bash regex is no go |
| 89 | + out=$(echo "$out" | egrep -v "^(# On branch $cur_branch|# Your branch is behind .* commits, and can be fast-forwarded.|#|nothing to commit \(working directory clean\))$") |
| 90 | + if [ -n "$out" ] |
| 91 | + then |
| 92 | + echo "***** Dirty WC or index *****" >&2 |
| 93 | + git status |
| 94 | + ret=1 |
| 95 | + fi |
70 | 96 | fi
|
71 | 97 |
|
72 |
| -# stash |
| 98 | +# Check stash |
73 | 99 | if [ `git stash list | wc -l` -gt 0 ];
|
74 | 100 | then
|
75 | 101 | echo "***** Dirty stash: *****" >&2
|
|
0 commit comments