Ajout scripts GIT
[hvutilities.git] / scripts / git-project-list.sh
diff --git a/scripts/git-project-list.sh b/scripts/git-project-list.sh
new file mode 100755 (executable)
index 0000000..ecbf9b8
--- /dev/null
@@ -0,0 +1,63 @@
+#!/bin/bash
+
+SCRIPT="`readlink -e $0`"
+SCRIPTPATH=$(dirname ${SCRIPT})
+
+SUBREPOS_LIST=.gitsubrepos
+
+# Uncomment to have verbose debug output
+##debug=1
+
+print_usage()
+{
+    echo "$(basename $0) -- List last SHA for each repo"
+    echo "Usage: $(basename $0) [OPTIONS...]"
+}
+
+if [ "x${1}" = "x--help" ]; then
+    print_usage
+    exit 1
+fi
+
+if [ ! -f ${SUBREPOS_LIST} ]; then
+    echo "Missing file for list of subrepos: ${SUBREPOS_LIST}"
+    print_usage
+    exit 1
+fi
+
+list_revisions()
+{
+    if [ ${#} -ne 1 ]; then
+        echo "Missing repository name"
+        exit 1
+    fi
+
+    local r=${1}
+
+    pushd "${r}" 1> /dev/null
+    local sha=$(git log --oneline HEAD~1..HEAD)
+    echo "${r}: ${sha}"
+    popd 1> /dev/null
+}
+
+list_revisions ./
+
+# Read list of repositories from file named .gitsubrepos
+while IFS=$'\n' read r ; do
+    [[ "${r}" =~ \#.* ]] && continue # Skip comment lines
+    [ -z ${r} ] && continue # Skip enmpty lines
+
+    # Make sure directory exists
+    if [ ! -d "${r}" ]; then
+        echo "Missing repos ${r}"
+        exit 1
+    fi
+
+    # Update only git repos
+    if [ ! -d "${r}/.git" ]; then
+        echo "Not a GIT repository"
+        exit 1
+    fi
+
+    list_revisions ${r}
+done < ${SUBREPOS_LIST}