A script for updating all the nested git clients

There's functionality in the make build to update (at least one layer
of) nested svn working copies of LLVM, but nothing in cmake and
nothing for git in either. I use the following script & after updating
it to handle arbitrary nesting (with the advent of the
clang-tools-extra repository) & generalize the discovery (had a
hardcoded list & after fixing up the Make build after some changes I
made I used something similar for my script) I figured I'd send it out
in case other people would like to use it (or just tell me why/how I'm
doing it wrong, if they think I am):

#!/bin/sh

if ! git remote -v 2> /dev/null | grep "http://llvm.org/git" > /dev/null; then
  echo "Not an llvm git repo"
  exit 1
fi

while ! git remote -v 2> /dev/null | grep
"http://llvm.org/git/llvm.git" > /dev/null; do
  if ! git remote -v 2> /dev/null > /dev/null; then
    echo "Could not find the root of the llvm git repository"
    exit 1
  fi
  cd `git rev-parse --show-toplevel`/../
done

cd `git rev-parse --show-toplevel` > /dev/null

function fetchAndRebase {
  if [ -d $1 ]; then
    pushd $1 > /dev/null
    if git status > /dev/null; then
      git stash | grep "No local changes to save" > /dev/null
      STASHED=$?
      git fetch > /dev/null
      git svn rebase -l > /dev/null
      if [ $STASHED -ne 0 ]; then git stash pop > /dev/null; fi
      for dir in `git status --ignored | grep /$ | sed -e "s/^#//"`; do
        fetchAndRebase $dir
      done
    fi
    popd > /dev/null
  fi
}

fetchAndRebase `git rev-parse --show-toplevel`

How about fitting Android's repo? :smiley:

I have not used repo for llvm, but been using my synthesized
repository (for my buildbot).

https://github.com/chapuni/llvm-project
https://github.com/chapuni/llvm-project-submodule

...Takumi

How about fitting Android's repo? :smiley:

I'm unfamiliar with Android's repository layout (do they have a nested
branch of LLVM? or just a similar arbitrary nesting/optionality system
to LLVM's that it'd be handy to generalize over?)

I have not used repo for llvm, but been using my synthesized
repository (for my buildbot).

Ah - well I'm sure you can see how this script could be modified (or
generalized) to handle an LLVM git mirror - just the two paths
mentioning llvm.org would need to be tweaked.