Compare commits

...

2 commits

Author SHA1 Message Date
sanj
9155daf978 Auto-update: Tue Jul 30 20:57:45 PDT 2024 2024-07-30 20:57:45 -07:00
sanj
7b89cb187c Auto-update: Tue Jul 30 20:55:02 PDT 2024 2024-07-30 20:55:02 -07:00
2 changed files with 53 additions and 2 deletions

33
gitpurge Executable file
View file

@ -0,0 +1,33 @@
#!/bin/bash
# Ensure we're in a git repository
if ! git rev-parse --is-inside-work-tree > /dev/null 2>&1; then
echo "Error: This script must be run inside a Git repository."
exit 1
fi
# Check if git-filter-repo is installed
if ! command -v git-filter-repo &> /dev/null; then
echo "Error: git-filter-repo is not installed. Please install it first."
echo "You can install it via pip: pip install git-filter-repo"
exit 1
fi
# Get a list of files that currently exist in the repository
current_files=$(git ls-files)
# Create a file with the list of files to keep
echo "$current_files" > files_to_keep.txt
# Use git-filter-repo to keep only the files that currently exist
git filter-repo --paths-from-file files_to_keep.txt --force
# Remove the temporary file
rm files_to_keep.txt
# Force push all branches
git push origin --all --force
echo "Purge complete. All files not present in the local repo have been removed from all commits on all branches."
echo "The changes have been force-pushed to the remote repository."

22
up
View file

@ -37,12 +37,26 @@ while IFS= read -r repo_path || [[ -n "$repo_path" ]]; do
continue
fi
# Check if 'origin' remote exists
if ! git remote | grep -q '^origin$'; then
echo "Remote 'origin' not found. Attempting to set it up..."
# Try to guess the remote URL based on the directory name
repo_name=$(basename "$repo_path")
remote_url="https://git.sij.ai/sij/$repo_name.git"
git remote add origin "$remote_url"
echo "Added remote 'origin' with URL: $remote_url"
fi
# Get the current branch
current_branch=$(git rev-parse --abbrev-ref HEAD)
# Pull the latest changes from the repository
echo "Pulling from $current_branch branch..."
git pull origin "$current_branch"
if ! git pull origin "$current_branch"; then
echo "Failed to pull from origin. The remote branch might not exist or there might be conflicts."
echo "Skipping further operations for this repository."
continue
fi
# Add changes to the Git index (staging area)
echo "Adding all changes..."
@ -58,7 +72,11 @@ while IFS= read -r repo_path || [[ -n "$repo_path" ]]; do
# Push changes to the remote repository
echo "Pushing all changes..."
git push origin "$current_branch"
if ! git push origin "$current_branch"; then
echo "Failed to push changes. The remote branch might not exist."
echo "Creating remote branch and pushing..."
git push -u origin "$current_branch"
fi
fi
echo "Update complete for $repo_path!"