From 710c6db7b2d33eb34b1d30d6e44bd5491153d074 Mon Sep 17 00:00:00 2001
From: Mirko Dietrich <dietrich@math.tu-berlin.de>
Date: Thu, 26 Jul 2018 18:02:42 +0200
Subject: [PATCH] mirror all branches

---
 README.md     | 17 +++++------------
 git-mirror.sh | 13 ++++++++-----
 2 files changed, 13 insertions(+), 17 deletions(-)

diff --git a/README.md b/README.md
index 9d4c75f..c72d4ff 100644
--- a/README.md
+++ b/README.md
@@ -2,26 +2,19 @@
 
 *No-thrills / uni-directional git mirroring.*
 
-Mirrors a git repository **A** to a repository **B**.
+Mirrors all branches in a git repository **A** to a repository **B**.
 (This solution does not need a post-receive hook on **A**.)
 
 ### Usage
 
-Clone the source to a location of your choice.
+Clone the source **A** to a location of your choice.
 
 ```sh
-$ git clone git@gitlab.example.com:path/to/repo.git source_repo
+$ git clone --mirror git@gitlab.example.com:path/to/repo.git source_repo
 ```
 
-Add the target repository as a remote (make sure you can push to target!).
+Run script manually or trigger via cronjob/systemd timer to mirror to repo **B**.
 
 ```sh
-$ cd source_repo
-$ git remote add target git@github.com:target/repo.git
-```
-
-Trigger script manually or via cronjob/systemd timer.
-
-```sh
-$ ./git-mirror.sh source_repo
+$ ./git-mirror.sh source_repo git@github.com:target/repo.git
 ```
diff --git a/git-mirror.sh b/git-mirror.sh
index bad2127..b9f2796 100755
--- a/git-mirror.sh
+++ b/git-mirror.sh
@@ -2,13 +2,16 @@
 
 set -e
 
-SOURCE_REPO=$1
+SOURCE_REPO_DIR=$1
+TARGET_REPO=$2
 
-if [[ ! -d ${SOURCE_REPO}/.git ]]; then
-    echo Repository ${SOURCE_REPO} not found!
+if [[ ! -d ${SOURCE_REPO_DIR}/objects ]]; then
+    echo Repository ${SOURCE_REPO_DIR} not found!
     exit -1
 fi
 
-cd ${SOURCE_REPO}
+cd ${SOURCE_REPO_DIR}
+
+# get branches in origin
 git fetch --prune origin
-git push --mirror --prune target
+git push --prune --mirror ${TARGET_REPO}
-- 
GitLab