blob: b2c7573aef07979eab61ece95e9d1dc869999e4c (
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
|
#!/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, then current commit (default 0).
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
commit_files=".tigger/$branch/$commit/"
file_dir="$commit_files/commit/"
mkdir --parents "$file_dir"
mkdir --parents "$commit_files/staged/"
# -a causes all files already in the index to have their contents from the
# current directory added to the index before the commit. We have to remove
# the message arg before testing the regex here.
message=$(echo "$@" | grep -o -E "\-m\s?.*" | cut -d' ' -f2- | tr -d \"\')
if [ "$(echo "$@" | sed "s|$message||g" | grep -o -E "\-a")" != "" ]; then
for filename in "$commit_files"/staged/*; do
basename=$(basename "$filename")
if ! [ -e "$basename" ]; then
continue
fi
cp "$basename" "$commit_files"/staged/
done
fi
# If all files in staging are equal to those in commit, we have nothing to commit.
different=""
for filename in "$commit_files"/staged/*; do
basename=$(basename "$filename")
EXISTS="$(cmp --silent .tigger/"$branch"/"$commit"/commit/"$basename" "$filename"; echo $?)"
if [ "$EXISTS" -ne 0 ]; then
different="true"
break
fi
done
for filename in "$commit_files"/commit/*; do
basename=$(basename "$filename")
EXISTS="$(cmp --silent .tigger/"$branch"/"$commit"/staged/"$basename" "$filename"; echo $?)"
if [ "$EXISTS" -ne 0 ]; then
different="true"
break
fi
done
if [ "$different" = "" ] || [ -z "$(find .tigger/"$branch"/"$commit"/staged/ .tigger/"$branch"/"$commit"/commit/ -maxdepth 1 -type f)" ] ; then
printf "nothing to commit\n"
exit 0
fi
# Copy all from staged into commit.
#for filename in "$commit_files"/staged/*; do
# cp "$filename" "$file_dir"
#done
rm -r --force "$commit_files"/commit/
cp -r "$commit_files"/staged "$commit_files"/commit/
# Copy our commit message and setup our new commit (n + 1).
#printf "%s > .tigger/%s/%s/message.tig\n" "$branch" "$commit"
printf "%s" "$message" > .tigger/"$branch"/"$commit"/message.tig
new_commit="$((($(cat .tigger/commit_count.tig) + 1)))"
mkdir --parents ".tigger/$branch/$new_commit/commit"
cp -r ".tigger/$branch/$commit/commit" ".tigger/$branch/$new_commit/"
cp -r ".tigger/$branch/$commit/commit" ".tigger/$branch/$new_commit/staged"
touch .tigger/branch.unlock
# Increment our commit count value (which isn't used outside of printing).
echo "$new_commit" > .tigger/commit_count.tig
printf "Committed as commit %s\n" "$((($(printf "%s" "$new_commit") - 1)))"
exit 0
|