Last active
September 12, 2017 09:11
-
-
Save qoomon/41697079eef82a56f8de51357c7ee9d9 to your computer and use it in GitHub Desktop.
Deploy to Git
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
set -e | |
if [ $# -ne 3 ]; then | |
echo "Usage: ... <SOURCE_FOLDER> <TARGET_REPO> <TARGET_BRANCH>" | |
exit 1; | |
fi | |
SOURCE_FOLDER="$1" | |
TARGET_REPO="$2" | |
TARGET_BRANCH="$3" | |
COMMIT_MESSAGE="$(git log -1 --format='Commit: %h - %s%nAuthor: %an <%ae>')\n$(git config --get remote.origin.url)" | |
SHADOW_DIR='.git.shadow' | |
echo "Deploy '${SOURCE_FOLDER}' to '${TARGET_REPO}' '${TARGET_BRANCH}'" | |
echo '' | |
echo "--- Change directory to ${SOURCE_FOLDER}" | |
cd "${SOURCE_FOLDER}"; | |
echo '' | |
echo "--- Init Repository" | |
rm -rf '.git' | |
git clone --single-branch --branch "${TARGET_BRANCH}" --depth 1 "${TARGET_REPO}" "$SHADOW_DIR" | |
mv "$SHADOW_DIR/.git" './' && rm -rf "$SHADOW_DIR" | |
echo '' | |
echo '--- Add & Commit Changes' | |
git add * | |
if git commit -am "${COMMIT_MESSAGE}" --quiet; then | |
git --no-pager log -n 1 --name-status --stat --oneline | |
echo '' | |
echo '--- Push Changes' | |
git push 'origin' "${TARGET_BRANCH}" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment