Last active
July 9, 2024 10:32
-
-
Save CodeArtha/abb4bd4209eea1df6e9ec9a219120fc6 to your computer and use it in GitHub Desktop.
Excluding all your git repositories from nextcloud sync to avoid conflicts and merges
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/bash | |
## This script finds all the git repositories recurcively from the folder the scripts sits in and add them to the nextcloud exclusion list. | |
## I had issues with nextcloud syncing my git repositories, this either created nextcloud sync conflicts or git merge conflicts. So I always excluded my git repo from being synced by nextcloud. | |
## This script just automates the process. Best place it at the root of your nexcloud directory and execute it. That way it gets them all. | |
exlist=~/.config/Nextcloud/sync-exclude.lst | |
for string in $(find . -name .git -type d -prune ); | |
do | |
len=${#string}-6 | |
ex=${string:2:$len} | |
echo "excluding \"$ex\" from NextCloud sync" | |
echo $ex >> $exlist | |
done | |
# Cleaning up to remove duplicates | |
cat $exlist | sort -u | uniq -u > /tmp/nc_uniq | |
mv /tmp/nc_uniq $exlist |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sorry for necro'ing this old gist, but I noticed this script doesn't play nice when there are spaces in folder names in the path.
You can solve this by replacing line 9 with:
find . -name .git -type d -prune | while read -r string ;
Using read ensures the output of find is only split on newlines, not on spaces.