Initial commit
This commit is contained in:
@@ -12,6 +12,7 @@
|
|||||||
# The branch name will be read from the VERSION file (first line)
|
# The branch name will be read from the VERSION file (first line)
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
set -o pipefail
|
||||||
|
|
||||||
if [ "$#" -lt 3 ]; then
|
if [ "$#" -lt 3 ]; then
|
||||||
echo "Usage: $0 <git-url> <git-user> <git-token>"
|
echo "Usage: $0 <git-url> <git-user> <git-token>"
|
||||||
@@ -56,29 +57,43 @@ fi
|
|||||||
|
|
||||||
echo "Version detected: $GIT_BRANCH"
|
echo "Version detected: $GIT_BRANCH"
|
||||||
|
|
||||||
if [[ "$GIT_URL" == https://* ]]; then
|
if [[ "$GIT_URL" != http://* && "$GIT_URL" != https://* ]]; then
|
||||||
URL_WITHOUT_PROTOCOL="${GIT_URL#https://}"
|
|
||||||
AUTH_URL="https://${GIT_USER}:${GIT_TOKEN}@${URL_WITHOUT_PROTOCOL}"
|
|
||||||
elif [[ "$GIT_URL" == http://* ]]; then
|
|
||||||
URL_WITHOUT_PROTOCOL="${GIT_URL#http://}"
|
|
||||||
AUTH_URL="http://${GIT_USER}:${GIT_TOKEN}@${URL_WITHOUT_PROTOCOL}"
|
|
||||||
else
|
|
||||||
echo "Error: URL must start with http:// or https://"
|
echo "Error: URL must start with http:// or https://"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Configuring Git for large files..."
|
# Credentials are passed to git through GIT_ASKPASS instead of being embedded in
|
||||||
# Increase HTTP post buffer to handle large files (500MB)
|
# the remote URL. Embedding breaks on passwords containing '@', '#', ':' or '/'
|
||||||
git config --global http.postBuffer 524288000
|
# (git splits the userinfo on the first '@'), and it would also persist the
|
||||||
# Optimize compression for large files
|
# secret in .git/config and echo it back in error messages.
|
||||||
git config --global core.compression 9
|
ASKPASS_SCRIPT=$(mktemp "${TMPDIR:-/tmp}/git-askpass.XXXXXX")
|
||||||
# Increase timeout for long operations (30 minutes)
|
trap 'rm -f "$ASKPASS_SCRIPT"' EXIT
|
||||||
git config --global http.lowSpeedLimit 0
|
cat > "$ASKPASS_SCRIPT" <<'ASKPASS'
|
||||||
git config --global http.lowSpeedTime 1800
|
#!/bin/bash
|
||||||
|
case "$1" in
|
||||||
|
*[Uu]sername*) printf '%s' "$GIT_ASKPASS_USER" ;;
|
||||||
|
*) printf '%s' "$GIT_ASKPASS_TOKEN" ;;
|
||||||
|
esac
|
||||||
|
ASKPASS
|
||||||
|
chmod 700 "$ASKPASS_SCRIPT"
|
||||||
|
export GIT_ASKPASS="$ASKPASS_SCRIPT"
|
||||||
|
export GIT_ASKPASS_USER="$GIT_USER"
|
||||||
|
export GIT_ASKPASS_TOKEN="$GIT_TOKEN"
|
||||||
|
export GIT_TERMINAL_PROMPT=0
|
||||||
|
|
||||||
echo "Initializing git repository..."
|
echo "Initializing git repository..."
|
||||||
git init
|
git init
|
||||||
|
|
||||||
|
echo "Configuring Git for large files..."
|
||||||
|
# Repository-local so the caller's global git config is left untouched.
|
||||||
|
# Increase HTTP post buffer to handle large files (500MB)
|
||||||
|
git config http.postBuffer 524288000
|
||||||
|
# Optimize compression for large files
|
||||||
|
git config core.compression 9
|
||||||
|
# Increase timeout for long operations (30 minutes)
|
||||||
|
git config http.lowSpeedLimit 0
|
||||||
|
git config http.lowSpeedTime 1800
|
||||||
|
|
||||||
echo "Adding all files (this may take a while for large files)..."
|
echo "Adding all files (this may take a while for large files)..."
|
||||||
git add -A
|
git add -A
|
||||||
TOTAL_FILES=$(git ls-files | wc -l)
|
TOTAL_FILES=$(git ls-files | wc -l)
|
||||||
@@ -93,17 +108,12 @@ git branch -M "$GIT_BRANCH"
|
|||||||
|
|
||||||
echo "Adding remote origin..."
|
echo "Adding remote origin..."
|
||||||
git remote remove origin 2>/dev/null || true
|
git remote remove origin 2>/dev/null || true
|
||||||
git remote add origin "$AUTH_URL"
|
git remote add origin "$GIT_URL"
|
||||||
|
|
||||||
echo "Pushing to remote (this may take a while for large files)..."
|
echo "Pushing to remote (this may take a while for large files)..."
|
||||||
# Use progress flag to show upload progress
|
# Not piped: piping made the exit status that of the pipe's last command, so a
|
||||||
git push --progress -u origin "$GIT_BRANCH" 2>&1 | while IFS= read -r line; do
|
# failed push was reported as success.
|
||||||
echo "$line"
|
git push --progress -u origin "$GIT_BRANCH"
|
||||||
# Show progress indicators
|
|
||||||
if [[ "$line" =~ (Counting|Compressing|Writing|remote:) ]]; then
|
|
||||||
echo "$line"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "Done! Repository pushed to $GIT_URL on branch $GIT_BRANCH"
|
echo "Done! Repository pushed to $GIT_URL on branch $GIT_BRANCH"
|
||||||
|
|||||||
Reference in New Issue
Block a user