-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlegit-show
executable file
·58 lines (50 loc) · 1.43 KB
/
legit-show
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
#!/bin/dash
filename="`echo "$0" | rev | cut -d'/' -f1 | rev `"
if [ ! -d ".legit" ]; then
echo "$filename: error: no .legit directory containing legit repository exists" >&2
exit 1
fi
branch=`cat .legit/current_branch`
if [ -z "$(ls -A .legit/"$branch"/commit)" ]; then
echo "$filename: error: your repository does not have any commits yet" >&2
exit 1
elif [ $# -ne 1 ]; then
echo "usage: $filename <commit>:<filename>" >&2
exit 1
fi
check=$(echo "$1" | egrep ":")
if [ -z "$check" ]; then
echo "$filename: error: invalid object "$1"" >&2
exit 1
fi
commit=$(echo "$1" | cut -d':' -f1)
file=$(echo "$1" | cut -d':' -f2)
files=$(echo "$file" | egrep "[^a-zA-Z0-9._-]")
if [ ! -z $files ]; then
echo ""$filename": error: invalid filename '"$file"'" >&2
exit 1
fi
if [ -z $commit ]; then
if [ ! -f .legit/add/"$file" ]; then
echo "$filename: error: '"$file"' not found in index" >&2
exit 1
else
cat .legit/add/"$file"
exit 1
fi
fi
testing=$(echo "$commit" | egrep [0-9])
if [ -z $testing ]; then
echo "usage: $filename <commit>:<filename>" >&2
exit 1
fi
check=$(cat .legit/"$branch"/commit/commit_history.txt | egrep "commit $commit")
if [ -z "$check" ]; then
echo "$filename: error: unknown commit '$commit'" >&2
exit 1
elif [ ! -f .legit/"$branch"/commit/commit_$commit/"$file" ]; then
echo "$filename: error: '"$file"' not found in commit $commit" >&2
exit 1
else
cat .legit/"$branch"/commit/commit_$commit/"$file"
fi