Ajout scripts GIT
authorHugo Villeneuve <hvilleneuve@addenergie.ca>
Fri, 22 Jul 2016 16:28:05 +0000 (12:28 -0400)
committerHugo Villeneuve <hvilleneuve@addenergie.ca>
Fri, 22 Jul 2016 16:32:00 +0000 (12:32 -0400)
scripts/Makefile.am
scripts/git-project-fetch.sh [new file with mode: 0755]
scripts/git-project-list.sh [new file with mode: 0755]
scripts/git-project-update.sh [new file with mode: 0755]

index d5f7271..48eefa6 100644 (file)
@@ -24,6 +24,9 @@ dist_bin_SCRIPTS = \
     hg-format-patch hg-update-subrepos \
     git-hg-sub-import git-hg-sub-update \
     git-repos-update-clean \
+    git-project-fetch.sh \
+    git-project-list.sh \
+    git-project-update.sh \
     source-code-stats \
     flac2ogg flac2mp3 \
     hv-scan \
diff --git a/scripts/git-project-fetch.sh b/scripts/git-project-fetch.sh
new file mode 100755 (executable)
index 0000000..483e2ff
--- /dev/null
@@ -0,0 +1,68 @@
+#!/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) -- GIT remote update for multiple subrepositories"
+    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
+
+remote_update_repo()
+{
+    if [ ${#} -ne 1 ]; then
+        echo "Missing repository name"
+        exit 1
+    fi
+
+    local r=${1}
+
+    echo "Repo ${r}:"
+
+    pushd "${r}" 1> /dev/null
+    git remote update 1> /dev/null
+    vco master
+    git pull --ff-only
+    vco latest
+    git pull --ff-only
+    popd 1> /dev/null
+}
+
+remote_update_repo ./
+
+# 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
+
+    remote_update_repo ${r}
+done < ${SUBREPOS_LIST}
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}
diff --git a/scripts/git-project-update.sh b/scripts/git-project-update.sh
new file mode 100755 (executable)
index 0000000..6fec40b
--- /dev/null
@@ -0,0 +1,97 @@
+#!/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) -- GIT update to branch for multiple subrepositories"
+    echo "Usage: $(basename $0) [OPTIONS...] BRANCH"
+}
+
+if [ "x${1}" = "x--help" ]; then
+    print_usage
+    exit 1
+fi
+
+if [ ${#} -ne 1 ]; then
+    echo "Missing BRANCH argument"
+    print_usage
+    exit 1
+fi
+
+if [ ! -f ${SUBREPOS_LIST} ]; then
+    echo "Missing file for list of subrepos: ${SUBREPOS_LIST}"
+    print_usage
+    exit 1
+fi
+
+branch=${1}
+
+update_repo()
+{
+    if [ ${#} -ne 1 ]; then
+        echo "Missing repository name"
+        exit 1
+    fi
+
+    local r=${1}
+
+    echo "Repo ${r}:"
+
+    pushd "${r}" 1> /dev/null
+    b=${branch}
+    exists=$(git show-ref refs/heads/${b})
+
+    if [ -n "$exists" ]; then
+        [ -n "${debug}" ] && echo "branch <${b}> exists"
+        vco ${b} 1> /dev/null
+    else
+        echo "Branch <${b}> not found, trying <latest>"
+        b=latest
+        exists=$(git show-ref refs/heads/${b})
+        if [ -n "$exists" ]; then
+            [ -n "${debug}" ] && echo "branch <${b}> exists"
+            vco ${b} 1> /dev/null
+        else
+            echo "Branch <${b}> not found, defaulting to <master>"
+            b=master
+            exists=$(git show-ref refs/heads/${b})
+            if [ -n "$exists" ]; then
+                [ -n "${debug}" ] && echo "branch <${b}> exists"
+                vco ${b} 1> /dev/null
+            else
+                echo "Error swtiching to branch <${b}>"
+                exit 1
+            fi
+        fi
+    fi
+    popd 1> /dev/null
+}
+
+update_repo ./
+
+# 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
+
+    update_repo ${r}
+done < ${SUBREPOS_LIST}