blob: b623432079537f97697c5cba394a0fe997912d10 (
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
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
|
#!/bin/dash
# Test if we have a valid repo before doing anything.
if ! [ -d ".tigger/" ]; then
printf "tigger-add: error: tigger repository directory .tigger not found\n" >&2
exit 1
fi
# Get current branch + commit as usual.
branch=$(cat .tigger/branch.tig)
mkdir --parents ".tigger/$branch/"
commit=$(find .tigger/"$branch"/ -maxdepth 1 -type d | grep -o -E "[\/][^\/]*$" | tr -d "/" | sort -n -r | head -n 1)
if [ "$commit" = "" ]; then
commit="0"
mkdir --parents ".tigger/$branch/$commit/"
fi
# Grabs regular files from our working dir, staging and commit.
files=$(find .tigger/"$branch"/"$commit"/commit/ .tigger/"$branch"/"$commit"/staged/ ./ -maxdepth 1 -type f -printf "%P\n" | sort | uniq | grep -v -E "^\." 2>/dev/null)
for filename in $files; do
c_dir=".tigger/$branch/$commit/commit/$filename";
s_dir=".tigger/$branch/$commit/staged/$filename";
is_c=0
is_s=0
is_w=0
if [ -e "$c_dir" ]; then
is_c=1
fi
if [ -e "$s_dir" ]; then
is_s=1
fi
if [ -e "$filename" ]; then
is_w=1
fi
# There are a LOT of very specific cases here.
if [ $is_w -eq 0 ] && [ $is_s -eq 0 ] && [ $is_c -eq 1 ]; then
printf "%s - deleted\n" "$filename"
continue
fi
if [ $is_w -eq 1 ] && [ $is_s -eq 0 ] && [ $is_c -eq 0 ]; then
printf "%s - untracked\n" "$filename"
continue;
fi
if [ $is_w -eq 1 ] && [ $is_s -eq 1 ] && [ $is_c -eq 1 ]; then
c="$(cat "$c_dir")"
s="$(cat "$s_dir")"
w="$(cat "$filename")"
if [ "$w" != "$s" ] && [ "$s" != "$c" ] && [ "$c" != "$w" ]; then
printf "%s - file changed, different changes staged for commit\n" "$filename"
continue
fi
if [ "$w" = "$s" ] && [ "$s" != "$c" ]; then
printf "%s - file changed, changes staged for commit\n" "$filename"
continue
fi
if [ "$w" != "$s" ] && [ "$s" = "$c" ]; then
printf "%s - file changed, changes not staged for commit\n" "$filename"
continue
fi
if [ "$w" = "$s" ] && [ "$s" = "$c" ]; then
printf "%s - same as repo\n" "$filename"
continue
fi
fi
if [ $is_w -eq 0 ] && [ $is_s -eq 1 ] && [ $is_c -eq 1 ] && [ "$(diff "$s_dir" "$c_dir")" = "" ]; then
printf "%s - file deleted\n" "$filename"
continue
fi
if [ $is_w -eq 1 ] && [ $is_s -eq 1 ] && [ $is_c -eq 0 ] && [ "$(diff "$filename" "$s_dir")" = "" ]; then
printf "%s - added to index\n" "$filename"
continue
fi
if [ $is_w -eq 1 ] && [ $is_s -eq 1 ] && [ $is_c -eq 0 ] && [ "$(diff "$filename" "$s_dir")" != "" ]; then
printf "%s - added to index, file changed\n" "$filename"
continue;
fi
if [ $is_w -eq 0 ] && [ $is_s -eq 1 ] && [ $is_c -eq 0 ]; then
printf "%s - added to index, file deleted\n" "$filename"
continue;
fi
printf "%s - untracked\n" "$filename"
done
exit 0
|