-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLFS_GUI.sh
More file actions
406 lines (362 loc) · 7.8 KB
/
LFS_GUI.sh
File metadata and controls
406 lines (362 loc) · 7.8 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
#!/bin/sh
#####################
# LFS GUI #
# BY FattyMieo #
# #
# VERSION: 2.2 #
# DATE: 04/10/2018 #
#####################
# Config
REPO_PATH=".."
# Color Codes
RED='\033[1;31m'
DARKRED='\033[0;31m'
GREEN='\033[1;32m'
YELLOW='\033[1;33m'
CYAN='\033[1;36m'
MAGENTA='\033[1;35m'
NOCOLOR='\033[0m'
clear-inputs()
{
while read -r -t 0; do read -r; done
}
title()
{
echo -e "${YELLOW}\c"
echo "=============================="
echo "| LFS File Locking |"
echo "=============================="
echo -e "${NOCOLOR}\c"
echo ""
}
git_fetch()
{
echo -e "${YELLOW}Fetching changes...${NOCOLOR}"
git fetch
}
git_lfs_verify()
{
echo -e "${YELLOW}Verifying ${MAGENTA}${1}${YELLOW}...${NOCOLOR}"
verify_cmd=$(git log --follow --oneline HEAD...origin/master -- "./${1}")
if [[ -z "${verify_cmd}" ]]
then
echo "The file is safe to edit and may not cause future merge conflicts"
else
echo "This file is identified in the following commits:"
git log --follow --oneline HEAD...origin/master -- "./${1}"
echo ""
echo -e "${RED}[WARNING] It's not safe to edit this file from the current HEAD!${NOCOLOR}"
echo ""
fi
}
git_lfs_lock()
{
git_lfs_verify "./${1}"
echo -e "${DARKRED}Locking ${MAGENTA}${1}${DARKRED}...${NOCOLOR}"
if [[ -z "${verify_cmd}" ]]
then
git lfs lock "./${1}"
else
echo "Failed to lock unsafe file"
fi
}
git_lfs_unlock()
{
echo -e "${GREEN}Unlocking ${MAGENTA}${1}${GREEN}...${NOCOLOR}"
git lfs unlock "./${1}"
}
git_lfs_unlock_id()
{
echo -e "${GREEN}Unlocking ID ${MAGENTA}${1}${GREEN}...${NOCOLOR}"
git lfs unlock "--id=$id"
}
verify_file()
{
echo -e "${YELLOW}\c"
echo "=============================="
echo "| Verifying File |"
echo "=============================="
echo -e "${NOCOLOR}\c"
echo ""
echo -e "${CYAN}\c"
echo "Tips: Drag the file into the windows to directly copy the path."
echo "Type in the file's path:"
echo -e "${NOCOLOR}\c"
echo ""
clear-inputs
read -e -p "\$ git lfs verify " input
echo ""
# Path Conversion
actual_path="${input%\'}" # Remove quote suffix
actual_path="${actual_path#\'}" # Remove quote prefix
actual_path="${actual_path#./}" # Remove any . prefix
actual_path="${actual_path##$PWD/}" # Remove PWD path
git_fetch
git_lfs_verify "$actual_path"
}
lock_file()
{
echo -e "${DARKRED}\c"
echo "=============================="
echo "| Locking File |"
echo "=============================="
echo -e "${NOCOLOR}\c"
echo ""
echo -e "${CYAN}\c"
echo "Tips: Drag the file into the windows to directly copy the path."
echo "Type in the file's path:"
echo -e "${NOCOLOR}\c"
echo ""
clear-inputs
read -e -p "\$ git lfs lock " input
echo ""
# Path Conversion
actual_path="${input%\'}" # Remove quote suffix
actual_path="${actual_path#\'}" # Remove quote prefix
actual_path="${actual_path#./}" # Remove any . prefix
actual_path="${actual_path##$PWD/}" # Remove PWD path
git_fetch
git_lfs_lock "$actual_path"
}
unlock_file()
{
echo -e "${GREEN}\c"
echo "=============================="
echo "| Unlocking File |"
echo "=============================="
echo -e "${NOCOLOR}\c"
echo ""
echo -e "${CYAN}\c"
echo "Tips: Drag the file into the windows to directly copy the path."
echo "Type in the file's path (or \"--id=<lock_id>\"):"
echo -e "${NOCOLOR}\c"
echo ""
clear-inputs
read -e -p "\$ git lfs unlock " input
echo ""
if [[ "$input" = --id=* ]]
then
id="${input#--id=}"
git_lfs_unlock_id "$id"
else
# Path Conversion
actual_path="${input%\'}" # Remove quote suffix
actual_path="${actual_path#\'}" # Remove quote prefix
actual_path="${actual_path#./}" # Remove any ./ prefix
actual_path="${actual_path##$PWD/}" # Remove PWD path
git_lfs_unlock "$actual_path"
fi
}
show_locks()
{
echo "\$ git lfs locks"
echo ""
echo -e "${YELLOW}\c"
echo "Loading locked files..."
echo -e "${NOCOLOR}\c"
echo ""
echo "=========="
echo ""
git lfs locks
echo ""
echo "=========="
}
show_tracked()
{
echo "\$ git lfs ls-files"
echo ""
echo -e "${YELLOW}\c"
echo "Loading all tracked files in the project..."
echo -e "${NOCOLOR}\c"
echo ""
echo "=========="
echo ""
git lfs ls-files
echo ""
echo "=========="
}
main_menu()
{
exit=0
while [ $exit = 0 ]
do
title
echo -e "${CYAN}\c"
echo "1. Lock a File"
echo "2. Unlock a File"
echo "3. Verify a File"
echo "4. View Locked Files"
echo "5. View ALL Tracked Files"
echo ""
echo "0. Exit"
echo -e "${NOCOLOR}\c"
echo ""
clear-inputs
read -e -p "\$ " input
echo ""
if [ "$input" = 1 ]
then
lock_file
elif [ "$input" = 2 ]
then
unlock_file
elif [ "$input" = 3 ]
then
verify_file
elif [ "$input" = 4 ]
then
show_locks
elif [ "$input" = 5 ]
then
show_tracked
elif [ "$input" = 0 ]
then
exit=1
exit
else
$input
fi
echo ""
done
}
quick_action_menu()
{
if [ -z "$1" ]
then
return
fi
# Determine path type
path_type="posix"
if [ "$1" = "--windows" ]
then
path_type="windows"
shift
elif [ "$1" = "--posix" ]
then
path_type="posix"
shift
fi
declare -a path_array # Declare an array externally
count=0
while [ "x${1}" != "x" ]
do
# Path Conversion
if [ "$path_type" = "windows" ]
then
# Windows PATH to POSIX
actual_path="${1%\"}" # Remove quote suffix
actual_path="${actual_path#\"}" # Remove quote prefix
actual_path="${1//\\/\/}" # Swap \ to /
actual_path="${actual_path//:\//\/}" # Swap :/ to /
actual_path="/${actual_path,}" # Add "/" and lowercase firts letter
actual_path="${actual_path##$PWD/}" # Remove PWD path
elif [ "$path_type" = "posix" ]
then
# POSIX direct copy-paste
actual_path="${1%\'}" # Remove quote suffix
actual_path="${actual_path#\'}" # Remove quote prefix
actual_path="${actual_path#./}" # Remove any ./ prefix
actual_path="${actual_path##$PWD/}" # Remove PWD path
else
actual_path="${1}"
fi
path_array[$count]=$actual_path
count=$(( $count + 1 ))
shift
done
echo -e "${GREEN}LFS-GUI${NOCOLOR}: File Drag&Drop detected"
echo ""
exit=0
while [ $exit = 0 ]
do
title
echo "Files(s):" # Show relative path to file
echo -e "${MAGENTA}\c"
count=0
while [ "x${path_array[count]}" != "x" ]
do
echo "${path_array[count]}"
count=$(( $count + 1 ))
done
echo -e "${NOCOLOR}\c"
#echo "File: ${1##*/}" # Show only filename
echo ""
echo -e "${CYAN}\c"
echo "1. Lock"
echo "2. Unlock"
echo "3. Verify"
echo "4. View Locked Files"
echo "5. View ALL Tracked Files"
echo ""
echo "0. Cancel"
echo -e "${NOCOLOR}\c"
echo ""
clear-inputs
read -e -p "\$ " input
echo ""
if [ "$input" = 1 ]
then
git_fetch
count=0
while [ "x${path_array[count]}" != "x" ]
do
git_lfs_lock "${path_array[count]}"
count=$(( $count + 1 ))
done
exit=1
elif [ "$input" = 2 ]
then
count=0
while [ "x${path_array[count]}" != "x" ]
do
git_lfs_unlock "${path_array[count]}"
count=$(( $count + 1 ))
done
exit=1
elif [ "$input" = 3 ]
then
git_fetch
count=0
while [ "x${path_array[count]}" != "x" ]
do
git_lfs_verify "${path_array[count]}"
count=$(( $count + 1 ))
done
elif [ "$input" = 4 ]
then
show_locks
elif [ "$input" = 5 ]
then
show_tracked
elif [ "$input" = 0 ]
then
exit=1
exit
else
$input
fi
echo ""
if [ $exit = 1 ]
then
clear-inputs
read -n 1 -s -r -p "Press any key to continue..."
fi
done
}
# Run program
cd $REPO_PATH
if [ ! -d "$PWD/.git" ]
then
echo "Unable to detect a git repository. (\".git\" not found)"
echo "Tips: This script should be placed in LFS-GUI folder located at the topmost level of the repository."
echo ""
clear-inputs
read -n 1 -s -r -p "Press any key to continue..."
exit
fi
if [ ! -z "$1" ]
then
quick_action_menu "$@" # Pass in all arguments
else
main_menu
fi