forked from MoeClub/Note
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gitUpload.sh
53 lines (41 loc) · 1.22 KB
/
gitUpload.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
#!/bin/bash
target="${1:-}"
repo="${2:-}"
branch="${3:-main}"
clone="${4:-}"
[ -n "${target}" ] && [ -n "${repo}" ] || exit 1
tmp="$(mktemp -d)"
trap "rm -rf ${tmp}" EXIT
cd "$tmp"
function createRepo(){
rn="${1:-}"
[ -n "$rn" ] || return 0
resp=`curl -X POST -sSL "${rn%github.com*}api.github.com/user/repos" -d "{\"name\":\"${rn##*/}\"}"`
echo "$resp" |grep '"status":' && return 1 || return 0
}
# init
git config --global init.defaultBranch "$branch"
git config --global pull.rebase true
git config --global user.name "remote"
git config --global user.email "remote@user"
git init
git checkout -b "$branch"
git remote rm origin >/dev/null 2>&1
git remote rm clone >/dev/null 2>&1
[ "$repo" != "-" ] && {
git remote add origin "$repo"
git pull origin "$branch"
}
[ -n "$clone" ] && {
git remote add clone "$clone"
createRepo "$clone"
}
[ -n "${target}" ] && [ "${target}" != "-" ] && {
[ -f "${target}" ] && cp -rf "${target}" "${tmp}"
[ -d "${target}" ] && cp -rf "${target%/}/." "${tmp}"
}
[ "${target}" == "-" ] && read -p "Pause <${tmp}> ..."
git add .
git commit -m `date +'%Y%m%d%H%M%S'`
# git config http.postBuffer 524288000
[ -n "$clone" ] && git push clone "$branch" -f || git push origin "$branch" -f