GetRepositoryPath 657 B

123456789101112131415161718192021222324252627
  1. #!/bin/sh
  2. usage() {
  3. echo "usage: $0 <source root>"
  4. echo " Prints the source control repository path of the given source"
  5. echo " directory, the exact format of the revision string depends on the"
  6. echo " source control system. If the source control system isn't known,"
  7. echo " the output is empty and the exit code is 1."
  8. exit 1
  9. }
  10. if [ $# != 1 ] || [ ! -d $1 ]; then
  11. usage;
  12. fi
  13. cd $1
  14. if [ -d .svn ]; then
  15. svn info | grep '^URL:' | cut -d: -f2-
  16. elif [ -f .git/svn/.metadata ]; then
  17. git svn info | grep 'URL:' | cut -d: -f2-
  18. elif [ -d .git ]; then
  19. git remote -v | grep 'fetch' | awk '{ print $2 }' | head -n1
  20. else
  21. exit 1;
  22. fi
  23. exit 0