54 lines
1.4 KiB
Bash
54 lines
1.4 KiB
Bash
#!/bin/bash
|
|
# bash <(curl -s https://git.technozone.com.au/vijay/Scripts/branch/main/git_commit) && rm -f git_commit
|
|
|
|
|
|
# Prompt for the Gitea repository URL
|
|
read -p "Enter your Gitea repository URL: " GITEA_URL
|
|
|
|
# Function to prompt for username and password
|
|
prompt_for_credentials() {
|
|
read -p "Enter your Gitea username: " username
|
|
read -sp "Enter your Gitea password: " password
|
|
echo
|
|
}
|
|
|
|
# Check for existing Git credentials (token)
|
|
if [ -z "$GIT_TOKEN" ]; then
|
|
echo "No Git token found."
|
|
prompt_for_credentials
|
|
else
|
|
echo "Using existing Git token."
|
|
fi
|
|
|
|
# Fetch the list of remote repositories
|
|
echo "Fetching remote repositories..."
|
|
git remote -v
|
|
|
|
# Check for changes in the remote repository
|
|
echo "Checking for changes in the remote repository..."
|
|
git fetch
|
|
|
|
# Check if there are any changes to pull
|
|
if [ $(git rev-list --count HEAD..origin/main) -gt 0 ]; then
|
|
echo "Changes found in the remote repository. Pulling changes..."
|
|
git pull origin main
|
|
fi
|
|
|
|
# Stage changes
|
|
echo "Staging changes..."
|
|
git add .
|
|
|
|
# Commit changes
|
|
read -p "Enter your commit message: " commit_message
|
|
git commit -m "$commit_message"
|
|
|
|
# Push changes
|
|
if [ -z "$GIT_TOKEN" ]; then
|
|
echo "Pushing changes using username and password..."
|
|
git push "$GITEA_URL" --username "$username" --password "$password"
|
|
else
|
|
echo "Pushing changes using token..."
|
|
git push "$GITEA_URL"
|
|
fi
|
|
|
|
echo "Changes pushed successfully." |