X-Git-Url: https://ruderich.org/simon/gitweb/?a=blobdiff_plain;f=setup.sh;h=6e5a69ae0b71c3fe3801fff8e8df89140be76e2d;hb=a3e64d7edcef3412cc64056510aacb046a2cc4a7;hp=8bb651c8f83c50ebf0a4b621b072e730484b4d61;hpb=55dee6c2ef0b12f154d4d4cb2be1a2df882bcf3d;p=config%2Fdotfiles.git diff --git a/setup.sh b/setup.sh index 8bb651c..6e5a69a 100755 --- a/setup.sh +++ b/setup.sh @@ -7,7 +7,7 @@ # Creates a new git repository in $1, adds a new remote named $2 and fetches # the master on $3. If the git repository already exists a new remote $2 for # $3 is added. If the remote already exists nothing happens. -function git_remote_init_update() { +git_remote_init_update() { # Make sure the requested directory exists. mkdir -p "$1" # Go to the target directory. @@ -28,6 +28,12 @@ function git_remote_init_update() { echo "Adding remote '$2' to '$1'." git remote add -t master "$2" "$3/$1" git fetch "$2" > /dev/null + # Remove the remote and abort if the fetch was unsuccessful. + if [ "$?" -ne "0" ]; then + git remote rm "$2" + exit 1 + fi + # Pushing to the remote pushes only the master branch in remotes named # the hostname of this machine. This makes it easy to see where # changes came from. @@ -38,9 +44,10 @@ function git_remote_init_update() { fi # Merge with remote master if the repository was just created, otherwise - # the repository starts empty. + # the repository starts empty. Also run gc to compress the new repository. if [ $new = yes ]; then git merge "$2/master" + git gc > /dev/null fi # Go back to the starting directory. @@ -50,12 +57,14 @@ function git_remote_init_update() { # Run setup.sh in each project. if [ "$#" -eq "0" ]; then - for project in `find . -name .git -type d`; do + for path in `find . -name setup.sh -type f -executable`; do # Skip this directory to prevent an infinite loop. - [ "$project" = "./.git" ] && continue + [ "$path" = "./setup.sh" ] && continue + + project=`echo "$path" | sed 's|/setup.sh$||'` - [ -d "$project" ] && (echo "running setup.sh in '$project'"; - cd "$project/.."; ./setup.sh > /dev/null) + echo "running setup.sh in '$project'" + ( cd "$project"; ./setup.sh > /dev/null ) done # Create git repository if necessary and/or additional remotes and fetch them. elif [ "$#" -ge "2" ]; then