-
Notifications
You must be signed in to change notification settings - Fork 410
Expand file tree
/
Copy pathgitUpload.sh
More file actions
54 lines (43 loc) · 1.34 KB
/
gitUpload.sh
File metadata and controls
54 lines (43 loc) · 1.34 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
#!/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
git remote add origin "$repo"
git pull origin "$branch"
[ -n "${target}" ] && [ "${target}" != "-" ] && {
[ -f "${target}" ] && cp -rf "${target}" "${tmp}"
[ -d "${target}" ] && cp -rf "${target%/}/." "${tmp}"
}
[ -n "$clone" ] && {
rm -rf .git
git init
git checkout -b "$branch"
git remote add clone "$clone"
createRepo "$clone"
find "$tmp" -name "*.sh" |xargs sed -i "s#/${repo##https://*github.com/}#/${clone##https://*github.com/}#g"
}
[ "${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