summaryrefslogtreecommitdiff
path: root/bin/git-is-clean
blob: d6619d8f6de9f3b33e4ca43c7bbe6d1177f4ef77 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/bin/bash

# find dirty working directories/staging areas/stashes

# This is to find stuff that needs to be checked in, not stuff that
# needs to be pushed (`mr status` does a good job of the latter by
# also calling `git --no-pager log --branches --not --remotes
# --simplify-by-decoration --decorate --oneline`)

# The git-diff-files(1) call fails in v7 git-annex repos with unlocked
# empty files.  So can't use this script in such repos.

set -e

# we need to do something different in a direct mode annex
direct="$(git config --get annex.direct || true)"
if [ "$direct" = "true" ]; then
    output="$(git annex status)"
    test -z "$output" || ( echo $output && exit 1 )
else
    (
        # 1st command: check index against HEAD
        # 2nd command: check working tree against index
        # 3rd command: check for untracked files
        # 4th command: check for stashes
        git diff-index --quiet --cached HEAD \
            && git diff-files --quiet \
            && test -z "$(git status --porcelain)" \
            && test -z "$(git stash list)"
    ) || ( git status --porcelain && git stash list && exit 1 )
fi