You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.8 KiB

2 years ago
  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. git_user_id=$1
  6. git_repo_id=$2
  7. release_note=$3
  8. git_host=$4
  9. if [ "$git_host" = "" ]; then
  10. git_host="github.com"
  11. echo "[INFO] No command line input provided. Set \$git_host to $git_host"
  12. fi
  13. if [ "$git_user_id" = "" ]; then
  14. git_user_id="GIT_USER_ID"
  15. echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id"
  16. fi
  17. if [ "$git_repo_id" = "" ]; then
  18. git_repo_id="GIT_REPO_ID"
  19. echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id"
  20. fi
  21. if [ "$release_note" = "" ]; then
  22. release_note="Minor update"
  23. echo "[INFO] No command line input provided. Set \$release_note to $release_note"
  24. fi
  25. # Initialize the local directory as a Git repository
  26. git init
  27. # Adds the files in the local repository and stages them for commit.
  28. git add .
  29. # Commits the tracked changes and prepares them to be pushed to a remote repository.
  30. git commit -m "$release_note"
  31. # Sets the new remote
  32. git_remote=$(git remote)
  33. if [ "$git_remote" = "" ]; then # git remote not defined
  34. if [ "$GIT_TOKEN" = "" ]; then
  35. echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment."
  36. git remote add origin https://${git_host}/${git_user_id}/${git_repo_id}.git
  37. else
  38. git remote add origin https://${git_user_id}:"${GIT_TOKEN}"@${git_host}/${git_user_id}/${git_repo_id}.git
  39. fi
  40. fi
  41. git pull origin master
  42. # Pushes (Forces) the changes in the local repository up to the remote repository
  43. echo "Git pushing to https://${git_host}/${git_user_id}/${git_repo_id}.git"
  44. git push origin master 2>&1 | grep -v 'To https'