-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgit-pending
More file actions
executable file
·135 lines (122 loc) · 3.23 KB
/
git-pending
File metadata and controls
executable file
·135 lines (122 loc) · 3.23 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/bin/bash
# Searching for .git without checking type handles git worktrees.
# TODO: Make the ignore list a param, but for now this works.
# echo Start
if [[ $1 == "--diff" ]]
then
# This sub-process will exit with non-0 if there are any interesting
# differences, a bit like "git diff"
#
# set -x
# pwd
shift
[[ $# == 1 ]] || exit 1
tmp=$1
shift
# If in a valid git dir, succeeds, so continue
# If in an invalid git dir, fails, so exit with success
git --no-pager status -s -b >& "${tmp}" || exit 0
# If grep finds matches, succeeds, so exit with a failure.
# If no matches, succeeds, fails, so continue
grep -q -e '\[ahead' -e '\[behind' -e '\[gone' "${tmp}" && exit 1
# If there are no diffs, succeeds, so continue.
# If there are diffs, fails, so exit with a failure.
git --no-pager diff --quiet >& /dev/null || exit 1
# If there are no problems, succeeds, so continue.
# If there are problems, fails, so exit with a failure.
git --no-pager diff --check >& /dev/null || exit 1
# There are no interesting differences, exit with success
exit 0
fi
if [[ $1 == "--git" ]]
then
git rev-parse --git-dir >/dev/null 2>&1
exit $?
fi
if [[ $1 == "--worktree" ]]
then
# This sub-process will exit with non-0 if this is a valid git work
# tree. Additionally, if it is a bare git folder, will output `git
# worktree list`.
#
# set -x
# pwd
shift
[[ $# == 1 ]] || exit 1
tmp=$1
shift
# If in a valid git dir, succeeds, so continue
# If in an invalid git dir, fails, so exit with 0
git rev-parse --is-bare-repository >& "${tmp}" || exit 0
if [[ $( cat "${tmp}" ) == "true" ]]
then
# This is a bare repo. Show any interesting working trees
echo
git worktree list | grep -v "(bare)"
exit 0
fi
# This is a valid work tree, so exit with non-0
exit 1
fi
if [[ $1 == "--progress" ]]
then
# This sub-process will output whether any "unusual" operations are in
# progress. Exit code only indicates errors
# pwd
shift
[[ $# == 0 ]] || exit 1
git --no-pager status | grep -i -e "in progress" -e "you have" -e "you are" \
-e "detached" | head -1
exit 0
fi
# set -x
if [[ $1 == "-v" ]]
then
verbose=1
shift
fi
tmp=$(mktemp)
search=( "$@" )
conditions=()
depth=()
interesting=( -execdir $0 --diff "${tmp}" \; -o )
print=( -printf "%h\n" )
status=( -execdir git --no-pager status -s -b \; )
if [[ "$1" == "--current" ]]
then
search=( "." )
conditions=( -o -execdir $0 --git \; )
depth=( -maxdepth 1 )
# Default interesting suppresses output if this is in a valid work dir
interesting=( -execdir $0 --worktree "${tmp}" \; -o )
print=( -printf "\n" )
status=( -execdir $0 --progress \; )
status+=( -execdir git --no-pager status -s -b --untracked-files=no \; )
shift
elif [[ "$1" == "--all" ]]
then
interesting=()
shift
search=( "$@" )
fi
find -L "${search[@]}" \
"${depth[@]}" \
-iname .nih_c -prune -o \
-iname nih_c -prune -o \
-iname _deps -prune -o \
\( -iname .git "${conditions[@]}" \) \
-prune \
\( \
"${interesting[@]}" \
"${print[@]}" \
"${status[@]}" \
-execdir git --no-pager diff --check \; \
-printf "\n" \
\) \
# || echo -e "\n\nTmp:" && cat "${tmp}"
rm -f "${tmp}"
if [[ -n "${verbose}" ]]
then
echo Done
fi
# echo End