Elffuss BraidHub

kikocis/continue public

c977fe2591e2 · 1.8 KiBRawPermalink
1#!/bin/sh
2# ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/
3#
4# Usage example: /bin/sh ./git_push.sh wing328 openapi-petstore-perl "minor update" "gitlab.com"
5
6git_user_id=$1
7git_repo_id=$2
8release_note=$3
9git_host=$4
10
11if [ "$git_host" = "" ]; then
12 git_host="github.com"
13 echo "[INFO] No command line input provided. Set \$git_host to $git_host"
14fi
15
16if [ "$git_user_id" = "" ]; then
17 git_user_id="GIT_USER_ID"
18 echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id"
19fi
20
21if [ "$git_repo_id" = "" ]; then
22 git_repo_id="GIT_REPO_ID"
23 echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id"
24fi
25
26if [ "$release_note" = "" ]; then
27 release_note="Minor update"
28 echo "[INFO] No command line input provided. Set \$release_note to $release_note"
29fi
30
31# Initialize the local directory as a Git repository
32git init
33
34# Adds the files in the local repository and stages them for commit.
35git add .
36
37# Commits the tracked changes and prepares them to be pushed to a remote repository.
38git commit -m "$release_note"
39
40# Sets the new remote
41git_remote=$(git remote)
42if [ "$git_remote" = "" ]; then # git remote not defined
43
44 if [ "$GIT_TOKEN" = "" ]; then
45 echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment."
46 git remote add origin https://${git_host}/${git_user_id}/${git_repo_id}.git
47 else
48 git remote add origin https://${git_user_id}:"${GIT_TOKEN}"@${git_host}/${git_user_id}/${git_repo_id}.git
49 fi
50
51fi
52
53git pull origin master
54
55# Pushes (Forces) the changes in the local repository up to the remote repository
56echo "Git pushing to https://${git_host}/${git_user_id}/${git_repo_id}.git"
57git push origin master 2>&1 | grep -v 'To https'