-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgirt-add
68 lines (54 loc) · 1.67 KB
/
girt-add
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
#!/bin/dash
# test if the repo does not exist
if ! test -d ".girt"
then
echo "$0: error: girt repository directory .girt not found" 1>&2
exit 1
fi
# test if no filename is provided
if test "$#" -eq 0
then
echo "usage: $0 <filenames>" 1>&2
exit 1
fi
# going through filenames in command line arguments
for file_names in "$@"
do
# storing filenames with incorrect format
wrong_format=$(echo "$file_names" | grep -E '^[^a-zA-Z0-9]')
# if the file does not exit in cwd
if ! test -e $file_names
then
if test "$wrong_format" != ""
then
echo "$0: error: invalid filename '$file_names'" 1>&2
exit 1
# if the file is not stored in index, can not open file and exit
elif ! test -e ".girt/index/$file_names"
then
echo "$0: error: can not open '$file_names'" 1>&2
exit 1
# if the file is stored in the index, remove it from index and continue
else
rm ".girt/index/$file_names"
continue
fi
# if the file exists in cwd
else
# if the format is wrong, output invalid file name and exit
if test "$wrong_format" != ""
then
echo "$0: error: invalid filename '$file_names'" 1>&2
exit 1
# if the file is stored in index, replace it
elif test -e ".girt/index/$file_names"
then
cp "$file_names" ".girt/index/$file_names"
continue
# if the file is not stored in index, copy it in index and continue
else
cp "$file_names" ".girt/index/$file_names"
continue
fi
fi
done