-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgit-export
executable file
·109 lines (98 loc) · 2.46 KB
/
git-export
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
#!/bin/bash
# TODO add archive
# TODO filter D files
# TODO remove -w flag move to end of options
# Init
VERBOSE=false
ERROR=false
RECORD=false
RETRIEVE=false
while getopts ":w:o:cld:zvrR" flag
do
case $flag in
o) # exported to
DEST_ROOT=$OPTARG
[ ! $(echo $DEST_ROOT | grep '^/') ] && DEST_ROOT=$PWD/$DEST_ROOT
[ ! $(echo $DEST_ROOT | grep '/$') ] && DEST_ROOT=$DEST_ROOT/
;;
w)
WORKPATH=$OPTARG
;;
c) # export and compress these files in tar formmat
COMPRESS=true
;;
l) # only list these file names
LIST=true
;;
z) # zip formmat compress exported files
ZIP=true
;;
d) #
DIFF=$OPTARG
;;
v) # verbose
VERBOSE=true
;;
r)
RECORD=true
;;
R)
RECORD=true
RETRIEVE=true
;;
*)
ERROR=true
;;
esac
done
[ -z "$WORKPATH" ] && ERROR=true
if $ERROR; then
echo "usage: git-export [-w GIT_WORKSPACE] -lvc [-o EXPORT_TO] [-d GIT_DIFF_COMMIT_HASH]"
echo '-l List files which are going to be exported.'
echo '-v Cause to be verbose, showing files after they are exported.'
echo '-c Compress exported files into tar formmat.[not implemented yet]'
echo '-z Compress exported files into zip formmat.[not implemented yet]'
echo '-r Record last commit id to the file .git-export located in the root of workpath.'
echo '-R Diff from last commit id recorded in .git-export file.'
exit 8
fi
[ -z "$DEST_ROOT" ] && DEST_ROOT=$PWD/
# CD to root of workpath
cd $WORKPATH
WORKPATH=`git rev-parse --show-cdup`
if [ -n "$WORKPATH" ]; then
cd $WORKPATH
fi
if $RETRIEVE ;then
if [ -e ".git-export" ]; then
DIFF=`cat .git-export`
fi
fi
if [ -z "$DIFF" ]; then
GIT_LIST=`git diff --name-status`
else
GIT_LIST=`git diff --name-status $DIFF`
fi
for f in $GIT_LIST; do
[ $(echo $f | grep '^[M|A|D|R|C|U]$') ] && continue
p=$PWD/$f
if ${LIST:=false}; then
echo $p
else
if [ $(echo $f | grep '/') ]; then
DEST_DIR=$DEST_ROOT${f%/*}
[ ! -d $DEST_DIR ] && mkdir -p $DEST_DIR
cp $p $DEST_DIR
else
cp $p $DEST_ROOT
fi
[ $VERBOSE = true ] && echo $DEST_ROOT$f
fi
done
if $RECORD; then
LAST_COMMIT_ID=`git log --pretty=oneline -n1`
if [ -n "$LAST_COMMIT_ID" ]; then
LAST_COMMIT_ID=${LAST_COMMIT_ID:0:20}
echo $LAST_COMMIT_ID > .git-export
fi
fi