Git Repositories

Possibility to sync from a remote repository (only github now, or any
authorCyrille Pontvieux <jrd@enialis.net>
Mon, 4 Feb 2013 15:38:16 +0000 (16:38 +0100)
committerCyrille Pontvieux <jrd@enialis.net>
Mon, 4 Feb 2013 15:38:16 +0000 (16:38 +0100)
compatible POST request).

homegit/gitrepo.sh
src/post-update.php [new file with mode: 0644]

index 975a015..aaee57b 100755 (executable)
@@ -30,6 +30,8 @@ Action is one of:
    Position starts from 1 as listed by list-keys
  - graph Name
    Show a graphical representation of the repository.
+ - fetch Name Url
+   Fetch all remotes if the Url is in Name.git/fetchurls file
 EOF
 }
 
@@ -286,6 +288,18 @@ graph() {
   )
 }
 
+fetch() {
+  NAME="$1"
+  URL="$2"
+  check_repo "$NAME"
+  if [ -f "$NAME".git/fetchremotes ] && grep -q -F "$URL" "$NAME".git/fetchremotes; then
+    (
+      cd "$NAME".git
+      git fetch --all
+    )
+  fi
+}
+
 ACTION=''
 NAME=''
 REPO=''
@@ -295,6 +309,7 @@ DESC=''
 OPTION=''
 OPT_VAL=''
 KEY=''
+URL=''
 while [ -n "$1" ]; do
   case "$1" in
     -h|--help)
@@ -303,7 +318,7 @@ while [ -n "$1" ]; do
       ;;
     *)
       if [ -z "$ACTION" ]; then
-        if echo "$1" | grep -q '^\(create\|destroy\|get\|set\|list-users\|create-user\|change-user\|show-pwd\|destroy-user\|show-users\|add-user\|del-user\|list-keys\|add-key\|del-key\|graph\)$'; then
+        if echo "$1" | grep -q '^\(create\|destroy\|get\|set\|list-users\|create-user\|change-user\|show-pwd\|destroy-user\|show-users\|add-user\|del-user\|list-keys\|add-key\|del-key\|graph\|fetch\)$'; then
           ACTION="$1"
           shift
         else
@@ -390,6 +405,14 @@ while [ -n "$1" ]; do
           elif [ "$ACTION" = "graph" ]; then
             echo "Unrecognized parameter ($1)" >&2
             exit 1
+          elif [ "$ACTION" = "fetch" ]; then
+            if [ -z "$URL" ]; then
+              URL="$1"
+              shift
+            else
+              echo "Unrecognized parameter ($1)" >&2
+              exit 1
+            fi
           fi
         fi
       fi
@@ -479,4 +502,9 @@ case "$ACTION" in
     checkparams REPO
     graph "$REPO"
     ;;
+  fetch)
+    REPO="$NAME"
+    checkparams REPO URL
+    fetch "$REPO" "$URL"
+    ;;
 esac
diff --git a/src/post-update.php b/src/post-update.php
new file mode 100644 (file)
index 0000000..867b5ee
--- /dev/null
@@ -0,0 +1,10 @@
+<?php
+require('include.inc.php');
+if (isset($_POST['payload'])) {
+  // github post update
+  $info = json_decode($_POST['payload'], true);
+  $repoName = $info['repository']['name'];
+  $repoUrl = $info['repository']['url'];
+  gitrepoinfo('fetch', $repoName, $repoUrl);
+}
+?>