Update sync_with_git.sh
This commit is contained in:
@@ -11,6 +11,8 @@
|
||||
# 4. Stages local files to check differences.
|
||||
# 5. Identifies real changes bypassing the Git --name-only whitespace bug.
|
||||
# 6. Prompts to override local files if diffs are found.
|
||||
#
|
||||
# Updated: Includes intelligent .gitignore handling (local vs remote comparison).
|
||||
# ==============================================================================
|
||||
|
||||
if [ -z "$1" ]; then
|
||||
@@ -31,7 +33,45 @@ git remote add origin "$REPO_URL"
|
||||
echo "Fetching from origin..."
|
||||
git fetch origin
|
||||
|
||||
# --- .GITIGNORE LOGIC ---
|
||||
REMOTE_IGNORE_TEMP=$(mktemp)
|
||||
if git show "origin/$BRANCH:.gitignore" > "$REMOTE_IGNORE_TEMP" 2>/dev/null; then
|
||||
if [ -f .gitignore ]; then
|
||||
# Check if local and remote versions are actually different
|
||||
if ! diff -q .gitignore "$REMOTE_IGNORE_TEMP" > /dev/null; then
|
||||
echo "---"
|
||||
echo "NOTICE: .gitignore conflict detected."
|
||||
echo "Differences ( - Local / + Remote ):"
|
||||
diff -u .gitignore "$REMOTE_IGNORE_TEMP" | tail -n +3
|
||||
echo "---"
|
||||
read -p "Overwrite local .gitignore with the remote version? (y/N): " ignore_choice
|
||||
case "$ignore_choice" in
|
||||
[yY]* )
|
||||
mv "$REMOTE_IGNORE_TEMP" .gitignore
|
||||
echo "Replaced with remote .gitignore."
|
||||
;;
|
||||
* )
|
||||
echo "Keeping local .gitignore. Note: This may cause extra files to show in the diff below."
|
||||
rm "$REMOTE_IGNORE_TEMP"
|
||||
;;
|
||||
esac
|
||||
else
|
||||
echo "Local and remote .gitignore are identical."
|
||||
rm "$REMOTE_IGNORE_TEMP"
|
||||
fi
|
||||
else
|
||||
echo "No local .gitignore found. Applying remote version..."
|
||||
mv "$REMOTE_IGNORE_TEMP" .gitignore
|
||||
fi
|
||||
else
|
||||
echo "No .gitignore found on remote. Proceeding with existing local state..."
|
||||
rm -f "$REMOTE_IGNORE_TEMP"
|
||||
fi
|
||||
# ---------------------------------
|
||||
|
||||
echo "Staging local files so Git can compare them..."
|
||||
# Clear cache first to ensure we aren't tracking things the new .gitignore should skip
|
||||
git rm -r --cached . > /dev/null 2>&1
|
||||
git add .
|
||||
|
||||
echo "Checking for differences (ignoring line-endings and whitespace)..."
|
||||
|
||||
Reference in New Issue
Block a user