-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcommit.sh
executable file
·77 lines (62 loc) · 1.65 KB
/
commit.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env bash
SOURCE_VERSION=""
TARGET_VERSION=""
REMOTE_NAME=""
while getopts ":s:t:r:" opt ; do
case ${opt} in
s)
SOURCE_VERSION="${OPTARG}";
;;
t)
TARGET_VERSION="${OPTARG}";
;;
r)
REMOTE_NAME="${OPTARG}";
;;
\?)
echo "Invalid option: -${OPTARG}"
;;
esac;
done;
shift $((OPTIND-1))
if [ -z "${SOURCE_VERSION}" ]; then
>&2 echo "-s is required";
exit 1;
fi;
if [ -z "${TARGET_VERSION}" ]; then
TARGET_VERSION="${SOURCE_VERSION}"
fi;
if [ -z "${REMOTE_NAME}" ]; then
REMOTE_NAME="origin"
fi;
ARGS=""
for ARG in "$@"; do
ARGS="${ARGS} \"${ARG//\"/\\\"}\""
done;
echo "${ARGS}"
BASE_PATH=$(cd "$(dirname "$0")" && pwd -P);
BRANCH_NAME="build/${TARGET_VERSION}"
SOURCE_VERSION_PATH="${BASE_PATH}/build/${SOURCE_VERSION}"
TARGET_VERSION_PATH="${BASE_PATH}/published/${BRANCH_NAME}"
GIT_DIR="${BASE_PATH}/.git"
if [ -d "${TARGET_VERSION_PATH}" ]; then
rm -rf "${TARGET_VERSION_PATH}"
fi;
mkdir -p "${TARGET_VERSION_PATH}"
cp -R "${GIT_DIR}" "${TARGET_VERSION_PATH}"
cd "${TARGET_VERSION_PATH}"
git fetch "${REMOTE_NAME}"
if [ `git branch --list --remote "${REMOTE_NAME}/${BRANCH_NAME}"` ]; then
git checkout "${REMOTE_NAME}/${BRANCH_NAME}" -b "${BRANCH_NAME}"
else
git checkout --orphan "${BRANCH_NAME}"
fi;
git rm -rf .
git clean -fxd
cp -R "${SOURCE_VERSION_PATH}/." "${TARGET_VERSION_PATH}"
mv "gitignore.tpl" ".gitignore"
mv "gitattributes.tpl" ".gitattributes"
git add .
CMD=$(which git)" commit ${ARGS}"
eval ${CMD}
# git -C "${GIT_DIR}" fetch "${TARGET_VERSION_PATH}" "${BRANCH_NAME}:${BRANCH_NAME}"