Search code examples
gitrepo

List out-of-date branches with `repo forall`


Just to clarify, this is about Android Repo.

I would like to be able to compare my working directory against an arbitrary remote branch using repo forall to see if there are any changes that I need to pull from that branch.

This is the closest I've gotten so far:

repo forall -p -c "git rev-list HEAD..origin/branchname --count"

That command will print the number of commits the working copy is behind origin/branchname for each git project. I would like to make it better by:

  • Ignoring branches that are already up-to-date. Sometimes a remote branch contains an empty merge commit or something that will report a nonzero number with the above command, but the branch does not actually contain any new code.
  • Printing no output for branches that are up-to-date. I really only care about branches that aren't up-to-date. I don't need to see a bunch of 0's. repo forall will not print output if I can make the git command not print output.

Solution

  • Try this:

    repo forall -p -c "if [[ `git diff HEAD origin/branchname` ]]; then git rev-list HEAD..origin/branchname --count; fi"