-
Notifications
You must be signed in to change notification settings - Fork 0
/
GitBiff.sh
58 lines (45 loc) · 1.32 KB
/
GitBiff.sh
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/bash
# parse input arguments
while getopts ":g:t:" opts; do
case ${opts} in
g)
TARGET_GIT_DIR=${OPTARG} ;;
t)
TARGET_PATCH_DIR=${OPTARG} ;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit;
;;
esac
done
# do some parameters validation
if [ ! -d "$TARGET_GIT_DIR" ]; then
echo "Directory $TARGET_GIT_DIR doesn't exist." >&2
exit;
fi
if [ ! -d "$TARGET_GIT_DIR"/.git ]; then
echo "Directory $TARGET_GIT_DIR is not a GIT repository." >&2
exit;
fi;
if [ ! -d "$TARGET_PATCH_DIR" ]; then
echo "Directory $TARGET_PATCH_DIR doesn't exist." >&2
exit;
fi
# get more information for the diff
echo "Select the NAME of the path:";
read PATCH_NAME
echo "Select the branch to export:";
read BRANCH
echo "Select the START node for this patch:";
read FROM_NODE
echo "Select the END node for this patch:";
read TO_NODE
# let's go
cd $TARGET_GIT_DIR
COMMIT_COUNT=$(git rev-list --count $TO_NODE);
COMMIT_HASH=$(git rev-parse $TO_NODE | head -c9);
FILES_TO_EXPORT=$(git diff --name-only --diff-filter=ACMRTUXB $FROM_NODE $TO_NODE)
FULL_FILE_NAME=$COMMIT_COUNT."$PATCH_NAME"_"$FROM_NODE".patch
git archive $BRANCH --output="$TARGET_PATCH_DIR""$FULL_FILE_NAME".tar.gz $FILES_TO_EXPORT
FILE_COUNT=$(tar -tzf "$TARGET_PATCH_DIR""$FULL_FILE_NAME".tar.gz | wc -l)
echo "Created $FULL_FILE_NAME ($FILE_COUNT files)"