Просмотр исходного кода

Implementation and tests of GC, GcJob, S3 files

Winston Li 9 лет назад
Родитель
Сommit
ee61d72e2e
72 измененных файлов с 1668 добавлено и 84 удалено
  1. 2 2
      services/git-bridge/pom.xml
  2. 17 3
      services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/bridge/Bridge.java
  3. 34 0
      services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/bridge/gc/GcJob.java
  4. 141 0
      services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/bridge/gc/GcJobImpl.java
  5. 7 0
      services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/bridge/repo/FSGitRepoStore.java
  6. 117 3
      services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepo.java
  7. 7 1
      services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/bridge/repo/ProjectRepo.java
  8. 2 0
      services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/bridge/repo/RepoStore.java
  9. 19 15
      services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/bridge/swap/job/SwapJobImpl.java
  10. 1 1
      services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/server/GitBridgeServer.java
  11. 55 20
      services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/snapshot/servermock/util/FileUtil.java
  12. 23 11
      services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/util/Tar.java
  13. 6 2
      services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/util/TimerUtils.java
  14. 10 6
      services/git-bridge/src/test/java/uk/ac/ic/wlgitbridge/bridge/BridgeTest.java
  15. 107 0
      services/git-bridge/src/test/java/uk/ac/ic/wlgitbridge/bridge/gc/GcJobImplTest.java
  16. 3 1
      services/git-bridge/src/test/java/uk/ac/ic/wlgitbridge/bridge/repo/FSGitRepoStoreTest.java
  17. 65 9
      services/git-bridge/src/test/java/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest.java
  18. 10 8
      services/git-bridge/src/test/java/uk/ac/ic/wlgitbridge/util/TarTest.java
  19. 2 2
      services/git-bridge/src/test/java/uk/ac/ic/wlgitbridge/util/TimerUtilsTest.java
  20. 2 0
      services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/incoming/.gitignore
  21. 1 0
      services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/incoming/DOTgit/COMMIT_EDITMSG
  22. 1 0
      services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/incoming/DOTgit/HEAD
  23. 7 0
      services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/incoming/DOTgit/config
  24. 1 0
      services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/incoming/DOTgit/description
  25. 15 0
      services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/incoming/DOTgit/hooks/applypatch-msg.sample
  26. 24 0
      services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/incoming/DOTgit/hooks/commit-msg.sample
  27. 8 0
      services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/incoming/DOTgit/hooks/post-update.sample
  28. 14 0
      services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/incoming/DOTgit/hooks/pre-applypatch.sample
  29. 49 0
      services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/incoming/DOTgit/hooks/pre-commit.sample
  30. 53 0
      services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/incoming/DOTgit/hooks/pre-push.sample
  31. 169 0
      services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/incoming/DOTgit/hooks/pre-rebase.sample
  32. 36 0
      services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/incoming/DOTgit/hooks/prepare-commit-msg.sample
  33. 128 0
      services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/incoming/DOTgit/hooks/update.sample
  34. BIN
      services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/incoming/DOTgit/index
  35. 6 0
      services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/incoming/DOTgit/info/exclude
  36. 1 0
      services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/incoming/DOTgit/info/refs
  37. 0 0
      services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/incoming/DOTgit/logs/HEAD
  38. 0 0
      services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/incoming/DOTgit/logs/refs/heads/master
  39. 1 0
      services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/incoming/DOTgit/objects/incoming_4632440628786417060.pack
  40. 1 0
      services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/incoming/DOTgit/objects/incoming_4635689790689803605.pack
  41. 2 0
      services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/incoming/DOTgit/objects/info/packs
  42. BIN
      services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/incoming/DOTgit/objects/pack/pack-71e0b18bc4675e30d48c891ae9bfc2487ec6e0bb.idx
  43. BIN
      services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/incoming/DOTgit/objects/pack/pack-71e0b18bc4675e30d48c891ae9bfc2487ec6e0bb.pack
  44. 2 0
      services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/incoming/DOTgit/packed-refs
  45. 0 0
      services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/incoming/file1.txt
  46. 0 0
      services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/incoming/file2.txt
  47. BIN
      services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/repo/DOTgit/index
  48. 2 0
      services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/without_incoming/.gitignore
  49. 1 0
      services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/without_incoming/DOTgit/COMMIT_EDITMSG
  50. 1 0
      services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/without_incoming/DOTgit/HEAD
  51. 7 0
      services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/without_incoming/DOTgit/config
  52. 1 0
      services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/without_incoming/DOTgit/description
  53. 15 0
      services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/without_incoming/DOTgit/hooks/applypatch-msg.sample
  54. 24 0
      services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/without_incoming/DOTgit/hooks/commit-msg.sample
  55. 8 0
      services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/without_incoming/DOTgit/hooks/post-update.sample
  56. 14 0
      services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/without_incoming/DOTgit/hooks/pre-applypatch.sample
  57. 49 0
      services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/without_incoming/DOTgit/hooks/pre-commit.sample
  58. 53 0
      services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/without_incoming/DOTgit/hooks/pre-push.sample
  59. 169 0
      services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/without_incoming/DOTgit/hooks/pre-rebase.sample
  60. 36 0
      services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/without_incoming/DOTgit/hooks/prepare-commit-msg.sample
  61. 128 0
      services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/without_incoming/DOTgit/hooks/update.sample
  62. BIN
      services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/without_incoming/DOTgit/index
  63. 6 0
      services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/without_incoming/DOTgit/info/exclude
  64. 1 0
      services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/without_incoming/DOTgit/info/refs
  65. 0 0
      services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/without_incoming/DOTgit/logs/HEAD
  66. 0 0
      services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/without_incoming/DOTgit/logs/refs/heads/master
  67. 2 0
      services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/without_incoming/DOTgit/objects/info/packs
  68. BIN
      services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/without_incoming/DOTgit/objects/pack/pack-71e0b18bc4675e30d48c891ae9bfc2487ec6e0bb.idx
  69. BIN
      services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/without_incoming/DOTgit/objects/pack/pack-71e0b18bc4675e30d48c891ae9bfc2487ec6e0bb.pack
  70. 2 0
      services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/without_incoming/DOTgit/packed-refs
  71. 0 0
      services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/without_incoming/file1.txt
  72. 0 0
      services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/without_incoming/file2.txt

+ 2 - 2
services/git-bridge/pom.xml

@@ -81,12 +81,12 @@
         <dependency>
             <groupId>org.eclipse.jgit</groupId>
             <artifactId>org.eclipse.jgit</artifactId>
-            <version>4.4.1.201607150455-r</version>
+            <version>4.6.0.201612231935-r</version>
         </dependency>
         <dependency>
             <groupId>org.eclipse.jgit</groupId>
             <artifactId>org.eclipse.jgit.http.server</artifactId>
-            <version>4.4.1.201607150455-r</version>
+            <version>4.6.0.201612231935-r</version>
         </dependency>
         <dependency>
             <groupId>org.xerial</groupId>

+ 17 - 3
services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/bridge/Bridge.java

@@ -5,6 +5,8 @@ import org.eclipse.jgit.transport.ServiceMayNotContinueException;
 import uk.ac.ic.wlgitbridge.bridge.db.DBStore;
 import uk.ac.ic.wlgitbridge.bridge.db.ProjectState;
 import uk.ac.ic.wlgitbridge.bridge.db.sqlite.SqliteDBStore;
+import uk.ac.ic.wlgitbridge.bridge.gc.GcJob;
+import uk.ac.ic.wlgitbridge.bridge.gc.GcJobImpl;
 import uk.ac.ic.wlgitbridge.bridge.lock.LockGuard;
 import uk.ac.ic.wlgitbridge.bridge.lock.ProjectLock;
 import uk.ac.ic.wlgitbridge.bridge.repo.FSGitRepoStore;
@@ -145,6 +147,7 @@ public class Bridge {
     private final DBStore dbStore;
     private final SwapStore swapStore;
     private final SwapJob swapJob;
+    private final GcJob gcJob;
 
     private final SnapshotAPI snapshotAPI;
     private final ResourceCache resourceCache;
@@ -183,6 +186,7 @@ public class Bridge {
                         dbStore,
                         swapStore
                 ),
+                new GcJobImpl(repoStore, lock),
                 new NetSnapshotAPI(),
                 new UrlResourceCache(dbStore)
         );
@@ -197,6 +201,7 @@ public class Bridge {
      * @param dbStore the {@link DBStore} to use
      * @param swapStore the {@link SwapStore} to use
      * @param swapJob the {@link SwapJob} to use
+     * @param gcJob
      * @param snapshotAPI the {@link SnapshotAPI} to use
      * @param resourceCache the {@link ResourceCache} to use
      */
@@ -206,6 +211,7 @@ public class Bridge {
             DBStore dbStore,
             SwapStore swapStore,
             SwapJob swapJob,
+            GcJob gcJob,
             SnapshotAPI snapshotAPI,
             ResourceCache resourceCache
     ) {
@@ -216,6 +222,7 @@ public class Bridge {
         this.snapshotAPI = snapshotAPI;
         this.resourceCache = resourceCache;
         this.swapJob = swapJob;
+        this.gcJob = gcJob;
         postbackManager = new PostbackManager();
         Runtime.getRuntime().addShutdownHook(new Thread(this::doShutdown));
         repoStore.purgeNonexistentProjects(dbStore.getProjectNames());
@@ -234,6 +241,8 @@ public class Bridge {
         Log.info("Shutdown received.");
         Log.info("Stopping SwapJob");
         swapJob.stop();
+        Log.info("Stopping GcJob");
+        gcJob.stop();
         Log.info("Waiting for projects");
         lock.lockAll();
         Log.info("Bye");
@@ -243,8 +252,9 @@ public class Bridge {
      * Starts the swap job, which will begin checking whether projects should be
      * swapped with a configurable frequency.
      */
-    public void startSwapJob() {
+    public void startBackgroundJobs() {
         swapJob.start();
+        gcJob.start();
     }
 
     /**
@@ -348,8 +358,12 @@ public class Bridge {
      *
      * 1. Queries the project state for the given project name.
      *    a. NOT_PRESENT = We've never seen it before, and the row for the
-     *                     project doesn't even exist.
-     *    b. PRESENT = The
+     *                     project doesn't even exist. The project definitely
+     *                     exists because
+     *                     {@link #projectExists(Credential, String)} would
+     *                     have had to return true to get here.
+     *    b. PRESENT = The project is on disk.
+     *    c. SWAPPED = The project is in the {@link SwapStore}
      *
      * If the project has never been cloned, it is git init'd. If the project
      * is in swap, it is restored to disk. Otherwise, the project was already

+ 34 - 0
services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/bridge/gc/GcJob.java

@@ -0,0 +1,34 @@
+package uk.ac.ic.wlgitbridge.bridge.gc;
+
+import com.google.api.client.auth.oauth2.Credential;
+import uk.ac.ic.wlgitbridge.bridge.Bridge;
+import uk.ac.ic.wlgitbridge.bridge.repo.ProjectRepo;
+import uk.ac.ic.wlgitbridge.data.filestore.RawDirectory;
+
+import java.util.concurrent.CompletableFuture;
+
+/**
+ * Is started by the bridge. Every time a project is updated, we queue it for
+ * GC which executes every hour or so.
+ *
+ * We don't queue it into a more immediate Executor because there is no way to
+ * know if a call to {@link Bridge#updateProject(Credential, ProjectRepo)},
+ * which releases the lock, is going to call
+ * {@link Bridge#push(Credential, String, RawDirectory, RawDirectory, String)}.
+ *
+ * We don't want the GC to run in between an update and a push.
+ */
+public interface GcJob {
+
+    void start();
+
+    void stop();
+
+    void onPreGc(Runnable preGc);
+
+    void onPostGc(Runnable postGc);
+
+    void queueForGc(String projectName);
+
+    CompletableFuture<Void> waitForRun();
+}

+ 141 - 0
services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/bridge/gc/GcJobImpl.java

@@ -0,0 +1,141 @@
+package uk.ac.ic.wlgitbridge.bridge.gc;
+
+import uk.ac.ic.wlgitbridge.bridge.lock.LockGuard;
+import uk.ac.ic.wlgitbridge.bridge.lock.ProjectLock;
+import uk.ac.ic.wlgitbridge.bridge.repo.ProjectRepo;
+import uk.ac.ic.wlgitbridge.bridge.repo.RepoStore;
+import uk.ac.ic.wlgitbridge.util.Log;
+import uk.ac.ic.wlgitbridge.util.TimerUtils;
+
+import java.io.IOException;
+import java.util.*;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
+
+/**
+ * Implementation of {@link GcJob} using its own Timer and a synchronized
+ * queue.
+ */
+public class GcJobImpl implements GcJob {
+
+    private final RepoStore repoStore;
+    private final ProjectLock locks;
+
+    private final long intervalMs;
+    private final Timer timer;
+
+    private final Set<String> gcQueue;
+
+    /**
+     * Hooks in case they are needed, e.g. for testing.
+     */
+    private AtomicReference<Runnable> preGc;
+    private AtomicReference<Runnable> postGc;
+
+    /* We need to iterate over and empty it after every run */
+    private final Lock jobWaitersLock;
+    private final List<CompletableFuture<Void>> jobWaiters;
+
+    public GcJobImpl(RepoStore repoStore, ProjectLock locks, long intervalMs) {
+        this.repoStore = repoStore;
+        this.locks = locks;
+        this.intervalMs = intervalMs;
+        timer = new Timer();
+        gcQueue = Collections.newSetFromMap(new ConcurrentHashMap<>());
+        preGc = new AtomicReference<>(() -> {});
+        postGc = new AtomicReference<>(() -> {});
+        jobWaitersLock = new ReentrantLock();
+        jobWaiters = new ArrayList<>();
+    }
+
+    public GcJobImpl(RepoStore repoStore, ProjectLock locks) {
+        this(
+                repoStore,
+                locks,
+                TimeUnit.MILLISECONDS.convert(1, TimeUnit.HOURS)
+        );
+    }
+
+    @Override
+    public void start() {
+        Log.info("Starting GC job to run every [{}] ms", intervalMs);
+        timer.scheduleAtFixedRate(
+                TimerUtils.makeTimerTask(this::doGC),
+                intervalMs,
+                intervalMs
+        );
+    }
+
+    @Override
+    public void stop() {
+        Log.info("Stopping GC job");
+        timer.cancel();
+    }
+
+    @Override
+    public void onPreGc(Runnable preGc) {
+        this.preGc.set(preGc);
+    }
+
+    @Override
+    public void onPostGc(Runnable postGc) {
+        this.postGc.set(postGc);
+    }
+
+    /**
+     * Needs to be callable from any thread.
+     * @param projectName
+     */
+    @Override
+    public void queueForGc(String projectName) {
+        gcQueue.add(projectName);
+    }
+
+    @Override
+    public CompletableFuture<Void> waitForRun() {
+        CompletableFuture<Void> ret = new CompletableFuture<>();
+        jobWaitersLock.lock();
+        try {
+            jobWaiters.add(ret);
+        } finally {
+            jobWaitersLock.unlock();
+        }
+        return ret;
+    }
+
+    private void doGC() {
+        Log.info("GC job running");
+        int numGcs = 0;
+        preGc.get().run();
+        for (
+                Iterator<String> it = gcQueue.iterator();
+                it.hasNext();
+                it.remove(), ++numGcs
+        ) {
+            String proj = it.next();
+            Log.info("[{}] Running GC job on project", proj);
+            try (LockGuard __ = locks.lockGuard(proj)) {
+                try {
+                    ProjectRepo repo = repoStore.getExistingRepo(proj);
+                    repo.runGC();
+                    repo.deleteIncomingPacks();
+                } catch (IOException e) {
+                    Log.info("[{}] Failed to GC project", proj);
+                }
+            }
+        }
+        Log.info("GC job finished, num gcs: {}", numGcs);
+        jobWaitersLock.lock();
+        try {
+            jobWaiters.forEach(w -> w.complete(null));
+        } finally {
+            jobWaitersLock.unlock();
+        }
+        postGc.get().run();
+    }
+
+}

+ 7 - 0
services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/bridge/repo/FSGitRepoStore.java

@@ -45,6 +45,13 @@ public class FSGitRepoStore implements RepoStore {
         return rootDirectory;
     }
 
+    @Override
+    public ProjectRepo getExistingRepo(String project) throws IOException {
+        GitProjectRepo ret = new GitProjectRepo(project);
+        ret.useExistingRepository(this);
+        return ret;
+    }
+
     /* TODO: Perhaps we should just delete bad directories on the fly. */
     @Override
     public void purgeNonexistentProjects(

+ 117 - 3
services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepo.java

@@ -1,6 +1,7 @@
 package uk.ac.ic.wlgitbridge.bridge.repo;
 
 import com.google.common.base.Preconditions;
+import org.apache.commons.io.IOUtils;
 import org.eclipse.jgit.api.Git;
 import org.eclipse.jgit.api.ResetCommand;
 import org.eclipse.jgit.api.errors.GitAPIException;
@@ -10,7 +11,6 @@ import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
 import uk.ac.ic.wlgitbridge.data.filestore.GitDirectoryContents;
 import uk.ac.ic.wlgitbridge.data.filestore.RawFile;
 import uk.ac.ic.wlgitbridge.git.exception.GitUserException;
-import uk.ac.ic.wlgitbridge.git.exception.SizeLimitExceededException;
 import uk.ac.ic.wlgitbridge.git.util.RepositoryObjectTreeWalker;
 import uk.ac.ic.wlgitbridge.util.Log;
 import uk.ac.ic.wlgitbridge.util.Project;
@@ -18,10 +18,25 @@ import uk.ac.ic.wlgitbridge.util.Util;
 
 import java.io.File;
 import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.FileVisitResult;
+import java.nio.file.FileVisitor;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.attribute.BasicFileAttributes;
 import java.util.*;
 
 /**
- * Created by winston on 20/08/2016.
+ * Class representing a Git repository.
+ *
+ * It stores the projectName and repo separately because the hooks need to be
+ * able to construct one of these without knowing whether the repo exists yet.
+ *
+ * It can then be passed to the Bridge, which will either
+ * {@link #initRepo(RepoStore)} for a never-seen-before repo, or
+ * {@link #useExistingRepository(RepoStore)} for an existing repo.
+ *
+ * Make sure to acquire the project lock before calling methods here.
  */
 public class GitProjectRepo implements ProjectRepo {
 
@@ -81,6 +96,105 @@ public class GitProjectRepo implements ProjectRepo {
         }
     }
 
+    @Override
+    public void runGC() throws IOException {
+        Preconditions.checkState(
+                repository.isPresent(),
+                "Repo is not present"
+        );
+        File dir = getProjectDir();
+        Preconditions.checkState(dir.isDirectory());
+        Log.info("[{}] Running git gc", projectName);
+        Process proc = new ProcessBuilder(
+                "git", "gc"
+        ).directory(dir).start();
+        int exitCode;
+        try {
+            exitCode = proc.waitFor();
+            Log.info("Exit: {}", exitCode);
+        } catch (InterruptedException e) {
+            throw new RuntimeException(e);
+        }
+        if (exitCode != 0) {
+            Log.warn("[{}] Git gc failed", dir.getAbsolutePath());
+            Log.warn(IOUtils.toString(
+                    proc.getInputStream(),
+                    StandardCharsets.UTF_8
+            ));
+            Log.warn(IOUtils.toString(
+                    proc.getErrorStream(),
+                    StandardCharsets.UTF_8
+            ));
+            try {
+                Thread.sleep(1000000);
+            } catch (InterruptedException e) {
+                e.printStackTrace();
+            }
+            throw new IOException("git gc error");
+        }
+        Log.info("[{}] git gc successful", projectName);
+    }
+
+    @Override
+    public void deleteIncomingPacks() throws IOException {
+        Log.info(
+                "[{}] Checking for garbage `incoming` files",
+                projectName
+        );
+        Files.walkFileTree(getDotGitDir().toPath(), new FileVisitor<Path>() {
+            @Override
+            public FileVisitResult preVisitDirectory(
+                    Path dir,
+                    BasicFileAttributes attrs
+            ) throws IOException {
+                return FileVisitResult.CONTINUE;
+            }
+
+            @Override
+            public FileVisitResult visitFile(
+                    Path file,
+                    BasicFileAttributes attrs
+            ) throws IOException {
+                File file_ = file.toFile();
+                String name = file_.getName();
+                if (name.startsWith("incoming_") && name.endsWith(".pack")) {
+                    Log.info("Deleting garbage `incoming` file: {}", file_);
+                    Preconditions.checkState(file_.delete());
+                }
+                return FileVisitResult.CONTINUE;
+            }
+
+            @Override
+            public FileVisitResult visitFileFailed(
+                    Path file,
+                    IOException exc
+            ) throws IOException {
+                Preconditions.checkNotNull(file);
+                Preconditions.checkNotNull(exc);
+                Log.warn("Failed to visit file: " + file, exc);
+                return FileVisitResult.TERMINATE;
+            }
+
+            @Override
+            public FileVisitResult postVisitDirectory(
+                    Path dir,
+                    IOException exc
+            ) throws IOException {
+                Preconditions.checkNotNull(dir);
+                if (exc != null) {
+                    return FileVisitResult.TERMINATE;
+                }
+                return FileVisitResult.CONTINUE;
+            }
+
+        });
+    }
+
+    @Override
+    public File getProjectDir() {
+        return getJGitRepository().getDirectory().getParentFile();
+    }
+
     public void resetHard() throws IOException {
         Git git = new Git(getJGitRepository());
         try {
@@ -94,7 +208,7 @@ public class GitProjectRepo implements ProjectRepo {
         return repository.get();
     }
 
-    public File getDirectory() {
+    public File getDotGitDir() {
         return getJGitRepository().getWorkTree();
     }
 

+ 7 - 1
services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/bridge/repo/ProjectRepo.java

@@ -3,8 +3,8 @@ package uk.ac.ic.wlgitbridge.bridge.repo;
 import uk.ac.ic.wlgitbridge.data.filestore.GitDirectoryContents;
 import uk.ac.ic.wlgitbridge.data.filestore.RawFile;
 import uk.ac.ic.wlgitbridge.git.exception.GitUserException;
-import uk.ac.ic.wlgitbridge.git.exception.SizeLimitExceededException;
 
+import java.io.File;
 import java.io.IOException;
 import java.util.Collection;
 import java.util.Map;
@@ -31,4 +31,10 @@ public interface ProjectRepo {
             GitDirectoryContents gitDirectoryContents
     ) throws IOException;
 
+    void runGC() throws IOException;
+
+    void deleteIncomingPacks() throws IOException;
+
+    File getProjectDir();
+
 }

+ 2 - 0
services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/bridge/repo/RepoStore.java

@@ -17,6 +17,8 @@ public interface RepoStore {
 
     File getRootDirectory();
 
+    ProjectRepo getExistingRepo(String project) throws IOException;
+
     void purgeNonexistentProjects(
             Collection<String> existingProjectNames
     );

+ 19 - 15
services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/bridge/swap/job/SwapJobImpl.java

@@ -7,6 +7,7 @@ import uk.ac.ic.wlgitbridge.bridge.lock.ProjectLock;
 import uk.ac.ic.wlgitbridge.bridge.repo.RepoStore;
 import uk.ac.ic.wlgitbridge.bridge.swap.store.SwapStore;
 import uk.ac.ic.wlgitbridge.util.Log;
+import uk.ac.ic.wlgitbridge.util.TimerUtils;
 
 import java.io.IOException;
 import java.io.InputStream;
@@ -81,7 +82,7 @@ public class SwapJobImpl implements SwapJob {
     @Override
     public void start() {
         timer.schedule(
-                uk.ac.ic.wlgitbridge.util.Timer.makeTimerTask(this::doSwap),
+                TimerUtils.makeTimerTask(this::doSwap),
                 0
         );
     }
@@ -98,7 +99,7 @@ public class SwapJobImpl implements SwapJob {
             Log.warn("Exception thrown during swap job", t);
         }
         timer.schedule(
-                uk.ac.ic.wlgitbridge.util.Timer.makeTimerTask(this::doSwap),
+                TimerUtils.makeTimerTask(this::doSwap),
                 interval.toMillis()
         );
     }
@@ -161,10 +162,11 @@ public class SwapJobImpl implements SwapJob {
         Log.info("Evicting project: {}", projName);
         try (LockGuard __ = lock.lockGuard(projName)) {
             long[] sizePtr = new long[1];
-            InputStream bzipped = repoStore.bzip2Project(projName, sizePtr);
-            swapStore.upload(projName, bzipped, sizePtr[0]);
-            dbStore.setLastAccessedTime(projName, null);
-            repoStore.remove(projName);
+            try (InputStream blob = repoStore.bzip2Project(projName, sizePtr)) {
+                swapStore.upload(projName, blob, sizePtr[0]);
+                dbStore.setLastAccessedTime(projName, null);
+                repoStore.remove(projName);
+            }
         }
         Log.info("Evicted project: {}", projName);
     }
@@ -183,15 +185,17 @@ public class SwapJobImpl implements SwapJob {
     @Override
     public void restore(String projName) throws IOException {
         try (LockGuard __ = lock.lockGuard(projName)) {
-            repoStore.unbzip2Project(
-                    projName,
-                    swapStore.openDownloadStream(projName)
-            );
-            swapStore.remove(projName);
-            dbStore.setLastAccessedTime(
-                    projName,
-                    Timestamp.valueOf(LocalDateTime.now())
-            );
+            try (InputStream s3File = swapStore.openDownloadStream(projName)) {
+                repoStore.unbzip2Project(
+                        projName,
+                        s3File
+                );
+                swapStore.remove(projName);
+                dbStore.setLastAccessedTime(
+                        projName,
+                        Timestamp.valueOf(LocalDateTime.now())
+                );
+            }
         }
     }
 

+ 1 - 1
services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/server/GitBridgeServer.java

@@ -83,7 +83,7 @@ public class GitBridgeServer {
         try {
             bridge.checkDB();
             jettyServer.start();
-            bridge.startSwapJob();
+            bridge.startBackgroundJobs();
             Log.info(Util.getServiceName() + "-Git Bridge server started");
             Log.info("Listening on port: " + port);
             Log.info("Bridged to: " + apiBaseURL);

+ 55 - 20
services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/snapshot/servermock/util/FileUtil.java

@@ -1,5 +1,6 @@
 package uk.ac.ic.wlgitbridge.snapshot.servermock.util;
 
+import com.google.common.collect.ImmutableSet;
 import org.eclipse.jgit.api.Git;
 import org.eclipse.jgit.api.errors.GitAPIException;
 import org.eclipse.jgit.api.errors.NoHeadException;
@@ -10,9 +11,9 @@ import java.io.File;
 import java.io.IOException;
 import java.nio.file.Files;
 import java.nio.file.Path;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Set;
+import java.util.*;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 /**
  * Created by Winston on 11/01/15.
@@ -50,6 +51,26 @@ public class FileUtil {
                 dir2,
                 dir2.resolve(".git")
         );
+        return filesAreEqual(dir1, dir2, dir1Contents, dir2Contents);
+    }
+
+    public static boolean directoryDeepEquals(File dir, File dir_) {
+        return directoryDeepEquals(dir.toPath(), dir_.toPath());
+    }
+
+    public static boolean directoryDeepEquals(Path path, Path path_) {
+        List<Set<String>> contents = Stream.of(path, path_).map(p ->
+                getAllFilesRecursively(
+                        p, p, Collections.emptySet(), true
+                )
+        ).collect(Collectors.toList());
+        return filesAreEqual(path, path_, contents.get(0), contents.get(1));
+    }
+
+    private static boolean filesAreEqual(
+            Path dir1, Path dir2,
+            Set<String> dir1Contents, Set<String> dir2Contents
+    ) {
         boolean filesEqual = dir1Contents.equals(dir2Contents);
         if (!filesEqual) {
             System.out.println(
@@ -106,14 +127,18 @@ public class FileUtil {
             Path dir,
             Path excluded
     ) {
-        return getAllRecursivelyInDirectoryApartFrom(dir, excluded, true);
+        return getAllRecursivelyInDirectoryApartFrom(
+                dir, excluded, true
+        );
     }
 
     public static Set<String> getOnlyFilesRecursivelyInDirectoryApartFrom(
             Path dir,
             Path excluded
     ) {
-        return getAllRecursivelyInDirectoryApartFrom(dir, excluded, false);
+        return getAllRecursivelyInDirectoryApartFrom(
+                dir, excluded, false
+        );
     }
 
     private static Set<String> getAllRecursivelyInDirectoryApartFrom(
@@ -124,30 +149,40 @@ public class FileUtil {
         if (!dir.toFile().isDirectory()) {
             throw new IllegalArgumentException("need a directory");
         }
-        return getAllFilesRecursively(dir, dir, excluded, directories);
+        return getAllFilesRecursively(
+                dir, dir, ImmutableSet.of(excluded.toFile()), directories
+        );
     }
 
+    private static final Set<String> ExcludedNames = ImmutableSet.of(
+            ".DS_Store"
+    );
+
     static Set<String> getAllFilesRecursively(
             Path baseDir,
             Path dir,
-            Path excluded,
+            Set<File> excluded,
             boolean directories
     ) {
         Set<String> files = new HashSet<String>();
         for (File file : dir.toFile().listFiles()) {
-            if (!file.equals(excluded.toFile())) {
-                boolean isDirectory = file.isDirectory();
-                if (directories || !isDirectory) {
-                    files.add(baseDir.relativize(file.toPath()).toString());
-                }
-                if (isDirectory) {
-                    files.addAll(getAllFilesRecursively(
-                            baseDir,
-                            file.toPath(),
-                            excluded,
-                            directories
-                    ));
-                }
+            if (excluded.contains(file)) {
+                continue;
+            }
+            if (ExcludedNames.contains(file.getName())) {
+                continue;
+            }
+            boolean isDirectory = file.isDirectory();
+            if (directories || !isDirectory) {
+                files.add(baseDir.relativize(file.toPath()).toString());
+            }
+            if (isDirectory) {
+                files.addAll(getAllFilesRecursively(
+                        baseDir,
+                        file.toPath(),
+                        excluded,
+                        directories
+                ));
             }
         }
         return files;

+ 23 - 11
services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/util/Tar.java

@@ -8,14 +8,19 @@ import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream;
 import org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream;
 import org.apache.commons.compress.utils.IOUtils;
 import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.output.ByteArrayOutputStream;
 
 import java.io.*;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 
 /**
- * Created by winston on 23/08/2016.
+ * Tar utilities.
+ *
+ * The resource returned by zip and tar are treated as unowned.
+ *
+ * The resource given to unzip is treated as unowned.
+ *
+ * Caller is responsible for all resources.
  */
 public class Tar {
 
@@ -31,23 +36,27 @@ public class Tar {
                 File fileOrDir,
                 long[] sizePtr
         ) throws IOException {
-            ByteArrayOutputStream target = new ByteArrayOutputStream();
+            File tmp = File.createTempFile(fileOrDir.getName(), ".tar.bz2");
+            tmp.deleteOnExit();
+            OutputStream target = new FileOutputStream(tmp);
+            /* Closes target */
             try (OutputStream bzip2 = new BZip2CompressorOutputStream(target)) {
                 tarTo(fileOrDir, bzip2);
             }
             if (sizePtr != null) {
-                sizePtr[0] = target.size();
+                sizePtr[0] = tmp.length();
             }
-            return target.toInputStream();
+            return new FileInputStream(tmp);
         }
 
         public static void unzip(
                 InputStream tarbz2,
                 File parentDir
         ) throws IOException {
-            try (InputStream tar = new BZip2CompressorInputStream(tarbz2)) {
-                untar(tar, parentDir);
-            }
+            /* BZip2CompressorInputStream does not need closing
+               Closing it would close tarbz2 which we should not do */
+            InputStream tar = new BZip2CompressorInputStream(tarbz2);
+            untar(tar, parentDir);
         }
 
     }
@@ -55,9 +64,12 @@ public class Tar {
     private Tar() {}
 
     public static InputStream tar(File fileOrDir) throws IOException {
-        ByteArrayOutputStream target = new ByteArrayOutputStream();
-        tarTo(fileOrDir, target);
-        return target.toInputStream();
+        File tmp = File.createTempFile(fileOrDir.getName(), ".tar");
+        tmp.deleteOnExit();
+        try (FileOutputStream target = new FileOutputStream(tmp)) {
+            tarTo(fileOrDir, target);
+            return new FileInputStream(tmp);
+        }
     }
 
     public static void tarTo(

+ 6 - 2
services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/util/Timer.java → services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/util/TimerUtils.java

@@ -5,13 +5,17 @@ import java.util.TimerTask;
 /**
  * Created by winston on 23/08/2016.
  */
-public class Timer {
+public class TimerUtils {
 
     public static TimerTask makeTimerTask(Runnable lamb) {
         return new TimerTask() {
             @Override
             public void run() {
-                lamb.run();
+                try {
+                    lamb.run();
+                } catch (Throwable t) {
+                    Log.warn("Error on timer", t);
+                }
             }
         };
     }

+ 10 - 6
services/git-bridge/src/test/java/uk/ac/ic/wlgitbridge/bridge/BridgeTest.java

@@ -4,6 +4,7 @@ import org.junit.Before;
 import org.junit.Test;
 import uk.ac.ic.wlgitbridge.bridge.db.DBStore;
 import uk.ac.ic.wlgitbridge.bridge.db.ProjectState;
+import uk.ac.ic.wlgitbridge.bridge.gc.GcJob;
 import uk.ac.ic.wlgitbridge.bridge.lock.ProjectLock;
 import uk.ac.ic.wlgitbridge.bridge.repo.ProjectRepo;
 import uk.ac.ic.wlgitbridge.bridge.repo.RepoStore;
@@ -20,9 +21,7 @@ import java.util.ArrayDeque;
 import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.anyInt;
 import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.*;
 
 /**
  * Created by winston on 20/08/2016.
@@ -38,6 +37,7 @@ public class BridgeTest {
     private SnapshotAPI snapshotAPI;
     private ResourceCache resourceCache;
     private SwapJob swapJob;
+    private GcJob gcJob;
 
     @Before
     public void setup() {
@@ -48,23 +48,27 @@ public class BridgeTest {
         snapshotAPI = mock(SnapshotAPI.class);
         resourceCache = mock(ResourceCache.class);
         swapJob = mock(SwapJob.class);
+        gcJob = mock(GcJob.class);
         bridge = new Bridge(
                 lock,
                 repoStore,
                 dbStore,
                 swapStore,
                 swapJob,
+                gcJob,
                 snapshotAPI,
                 resourceCache
         );
     }
 
     @Test
-    public void shutdownStopsSwapJob() {
-        bridge.startSwapJob();
-        bridge.doShutdown();
+    public void shutdownStopsSwapAndGcJobs() {
+        bridge.startBackgroundJobs();
         verify(swapJob).start();
+        verify(gcJob).start();
+        bridge.doShutdown();
         verify(swapJob).stop();
+        verify(gcJob).stop();
     }
 
     @Test

+ 107 - 0
services/git-bridge/src/test/java/uk/ac/ic/wlgitbridge/bridge/gc/GcJobImplTest.java

@@ -0,0 +1,107 @@
+package uk.ac.ic.wlgitbridge.bridge.gc;
+
+import org.junit.Test;
+import org.mockito.stubbing.OngoingStubbing;
+import uk.ac.ic.wlgitbridge.bridge.lock.LockGuard;
+import uk.ac.ic.wlgitbridge.bridge.lock.ProjectLock;
+import uk.ac.ic.wlgitbridge.bridge.repo.ProjectRepo;
+import uk.ac.ic.wlgitbridge.bridge.repo.RepoStore;
+import uk.ac.ic.wlgitbridge.data.ProjectLockImpl;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+
+import static org.junit.Assert.assertFalse;
+import static org.mockito.Mockito.*;
+
+/**
+ * Created by winston on 16/02/2017.
+ */
+public class GcJobImplTest {
+
+    RepoStore repoStore = mock(RepoStore.class);
+
+    ProjectLock locks = new ProjectLockImpl();
+
+    GcJobImpl gcJob = new GcJobImpl(repoStore, locks, 5);
+
+    @Test
+    public void addedProjectsAreAllEventuallyGcedOnce() throws Exception {
+        int numProjects = 5;
+        /* Make the mocks, make expectations, and keep a reference to them */
+        final OngoingStubbing<ProjectRepo>[] o = new OngoingStubbing[] {
+                when(repoStore.getExistingRepo(anyString()))
+        };
+        List<ProjectRepo> mockRepos = IntStream.range(
+                0, numProjects
+        ).mapToObj(i ->
+                String.valueOf((char) ('a' + i))
+        ).map(proj -> {
+            gcJob.queueForGc(proj);
+            ProjectRepo mockRepo = mock(ProjectRepo.class);
+            o[0] = o[0].thenReturn(mockRepo);
+            return mockRepo;
+        }).collect(Collectors.toList());
+        CompletableFuture<Void> fut = gcJob.waitForRun();
+        gcJob.start();
+        fut.join();
+        for (ProjectRepo mock : mockRepos) {
+            verify(mock).runGC();
+            verify(mock).deleteIncomingPacks();
+        }
+        /* Nothing should happen on the next run */
+        when(repoStore.getExistingRepo(anyString())).thenThrow(
+                new IllegalStateException()
+        );
+        gcJob.waitForRun().join();
+    }
+
+    @Test
+    public void cannotOverlapGcRuns() throws Exception {
+        CompletableFuture<Void> runningForever = new CompletableFuture<>();
+        gcJob.onPostGc(() -> {
+            try {
+                /* Pretend the GC is taking forever */
+                runningForever.join();
+            } catch (Throwable e) {
+                runningForever.completeExceptionally(e);
+            }
+        });
+        CompletableFuture<Void> fut = gcJob.waitForRun();
+        gcJob.start();
+        fut.join();
+        CompletableFuture<Void> ranAgain = new CompletableFuture<>();
+        gcJob.onPreGc(() -> ranAgain.complete(null));
+        /* Should not run again any time soon */
+        for (int i = 0; i < 50; ++i) {
+            assertFalse(ranAgain.isDone());
+            /* The gc interval is 5 ms, so 50 1ms sleeps should be more than
+               enough without making the test slow */
+            Thread.sleep(1);
+        }
+        assertFalse(runningForever.isCompletedExceptionally());
+    }
+
+    @Test
+    public void willNotGcProjectUntilItIsUnlocked()
+            throws InterruptedException, IOException {
+        ProjectRepo repo = mock(ProjectRepo.class);
+        when(repoStore.getExistingRepo(anyString())).thenReturn(repo);
+        gcJob.onPostGc(gcJob::stop);
+        gcJob.queueForGc("a");
+        CompletableFuture<Void> fut = gcJob.waitForRun();
+        try (LockGuard __ = locks.lockGuard("a")) {
+            gcJob.start();
+            for (int i = 0; i < 50; ++i) {
+                assertFalse(fut.isDone());
+                Thread.sleep(1);
+            }
+        }
+        /* Now that we've released the lock, fut should complete */
+        fut.join();
+    }
+
+}

+ 3 - 1
services/git-bridge/src/test/java/uk/ac/ic/wlgitbridge/bridge/repo/FSGitRepoStoreTest.java

@@ -47,7 +47,9 @@ public class FSGitRepoStoreTest {
 
     @Test
     public void testPurgeNonexistentProjects() {
-        File toDelete = new File(repoStore.getRootDirectory(), "idontexist");
+        File toDelete = new File(
+                repoStore.getRootDirectory(), "idontexist"
+        );
         File wlgb = new File(repoStore.getRootDirectory(), ".wlgb");
         assertTrue(toDelete.exists());
         assertTrue(wlgb.exists());

+ 65 - 9
services/git-bridge/src/test/java/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest.java

@@ -3,11 +3,13 @@ package uk.ac.ic.wlgitbridge.bridge.repo;
 import com.google.api.client.repackaged.com.google.common.base.Preconditions;
 import org.apache.commons.io.FileUtils;
 import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import uk.ac.ic.wlgitbridge.data.filestore.GitDirectoryContents;
 import uk.ac.ic.wlgitbridge.data.filestore.RawFile;
 import uk.ac.ic.wlgitbridge.data.filestore.RepositoryFile;
+import uk.ac.ic.wlgitbridge.snapshot.servermock.util.FileUtil;
 import uk.ac.ic.wlgitbridge.util.Files;
 
 import java.io.File;
@@ -16,8 +18,11 @@ import java.nio.charset.StandardCharsets;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.*;
+import java.util.function.Supplier;
 
-import static org.junit.Assert.assertEquals;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.lessThan;
+import static org.junit.Assert.*;
 
 /**
  * Created by winston on 08/10/2016.
@@ -42,17 +47,26 @@ public class GitProjectRepoTest {
     FSGitRepoStore repoStore;
     GitProjectRepo repo;
     GitProjectRepo badGitignore;
+    GitProjectRepo incoming;
+    GitProjectRepo withoutIncoming;
+
+    @Rule
+    public TemporaryFolder tmpFolder = new TemporaryFolder();
 
     @Before
     public void setup() throws IOException {
-        TemporaryFolder tmpFolder = new TemporaryFolder();
-        tmpFolder.create();
         rootdir = makeTempRepoDir(tmpFolder, "rootdir");
         repoStore = new FSGitRepoStore(rootdir.getAbsolutePath());
-        repo = new GitProjectRepo("repo");
-        repo.useExistingRepository(repoStore);
-        badGitignore = new GitProjectRepo("badgitignore");
-        badGitignore.useExistingRepository(repoStore);
+        repo = fromExistingDir("repo");
+        badGitignore = fromExistingDir("badgitignore");
+        incoming = fromExistingDir("incoming");
+        withoutIncoming = fromExistingDir("without_incoming");
+    }
+
+    private GitProjectRepo fromExistingDir(String dir) throws IOException {
+        GitProjectRepo ret = new GitProjectRepo(dir);
+        ret.useExistingRepository(repoStore);
+        return ret;
     }
 
     private GitDirectoryContents makeDirContents(
@@ -88,7 +102,7 @@ public class GitProjectRepoTest {
         );
         repo.commitAndGetMissing(contents);
         repo.resetHard();
-        File dir = repo.getDirectory();
+        File dir = repo.getDotGitDir();
         assertEquals(
                 new HashSet<String>(Arrays.asList(".git", ".gitignore")),
                 new HashSet<String>(Arrays.asList(dir.list()))
@@ -120,7 +134,7 @@ public class GitProjectRepoTest {
                         "file2.txt",
                         "added.ignored"
                 )),
-                new HashSet<String>(Arrays.asList(repo.getDirectory().list()))
+                new HashSet<String>(Arrays.asList(repo.getDotGitDir().list()))
         );
     }
 
@@ -141,4 +155,46 @@ public class GitProjectRepoTest {
         badGitignore.commitAndGetMissing(contents);
     }
 
+    private static long repoSize(ProjectRepo repo) {
+        return FileUtils.sizeOfDirectory(repo.getProjectDir());
+    }
+
+    @Test
+    public void runGCReducesTheSizeOfARepoWithGarbage() throws IOException {
+        long beforeSize = repoSize(repo);
+        repo.runGC();
+        long afterSize = repoSize(repo);
+        assertThat(beforeSize, lessThan(afterSize));
+
+    }
+
+    @Test
+    public void runGCDoesNothingOnARepoWithoutGarbage() throws IOException {
+        repo.runGC();
+        long beforeSize = repoSize(repo);
+        repo.runGC();
+        long afterSize = repoSize(repo);
+        assertThat(beforeSize, equalTo(afterSize));
+    }
+
+    @Test
+    public void deleteIncomingPacksDeletesIncomingPacks() throws IOException {
+        Supplier<Boolean> dirsAreEq = () -> FileUtil.directoryDeepEquals(
+                incoming.getProjectDir(), withoutIncoming.getProjectDir()
+        );
+        assertFalse(dirsAreEq.get());
+        incoming.deleteIncomingPacks();
+        assertTrue(dirsAreEq.get());
+    }
+
+    @Test
+    public void deleteIncomingPacksOnDirWithoutIncomingPacksDoesNothing()
+            throws IOException {
+        File actual = withoutIncoming.getProjectDir();
+        File expected = tmpFolder.newFolder();
+        FileUtils.copyDirectory(actual, expected);
+        withoutIncoming.deleteIncomingPacks();
+        assertTrue(FileUtil.directoryDeepEquals(actual, expected));
+    }
+
 }

+ 10 - 8
services/git-bridge/src/test/java/uk/ac/ic/wlgitbridge/util/TarTest.java

@@ -35,18 +35,20 @@ public class TarTest {
 
     @Test
     public void tarAndUntarProducesTheSameResult() throws IOException {
-        InputStream tar = Tar.tar(testDir);
-        Tar.untar(tar, tmpDir);
-        File untarred = new File(tmpDir, "testdir");
-        assertTrue(Files.contentsAreEqual(testDir, untarred));
+        try (InputStream tar = Tar.tar(testDir)) {
+            Tar.untar(tar, tmpDir);
+            File untarred = new File(tmpDir, "testdir");
+            assertTrue(Files.contentsAreEqual(testDir, untarred));
+        }
     }
 
     @Test
     public void tarbz2AndUntarbz2ProducesTheSameResult() throws IOException {
-        InputStream tarbz2 = Tar.bz2.zip(testDir);
-        Tar.bz2.unzip(tarbz2, tmpDir);
-        File unzipped = new File(tmpDir, "testdir");
-        assertTrue(Files.contentsAreEqual(testDir, unzipped));
+        try (InputStream tarbz2 = Tar.bz2.zip(testDir)) {
+            Tar.bz2.unzip(tarbz2, tmpDir);
+            File unzipped = new File(tmpDir, "testdir");
+            assertTrue(Files.contentsAreEqual(testDir, unzipped));
+        }
     }
 
 }

+ 2 - 2
services/git-bridge/src/test/java/uk/ac/ic/wlgitbridge/util/TimerTest.java → services/git-bridge/src/test/java/uk/ac/ic/wlgitbridge/util/TimerUtilsTest.java

@@ -7,12 +7,12 @@ import static org.junit.Assert.assertEquals;
 /**
  * Created by winston on 23/08/2016.
  */
-public class TimerTest {
+public class TimerUtilsTest {
 
     @Test
     public void testMakeTimerTask() {
         int[] iPtr = new int[] { 3 };
-        Timer.makeTimerTask(() -> iPtr[0] = 5).run();
+        TimerUtils.makeTimerTask(() -> iPtr[0] = 5).run();
         assertEquals(5, iPtr[0]);
     }
 

+ 2 - 0
services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/incoming/.gitignore

@@ -0,0 +1,2 @@
+*.ignored
+

+ 1 - 0
services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/incoming/DOTgit/COMMIT_EDITMSG

@@ -0,0 +1 @@
+Add ignored file

+ 1 - 0
services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/incoming/DOTgit/HEAD

@@ -0,0 +1 @@
+ref: refs/heads/master

+ 7 - 0
services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/incoming/DOTgit/config

@@ -0,0 +1,7 @@
+[core]
+	repositoryformatversion = 0
+	filemode = true
+	bare = false
+	logallrefupdates = true
+	ignorecase = true
+	precomposeunicode = true

+ 1 - 0
services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/incoming/DOTgit/description

@@ -0,0 +1 @@
+Unnamed repository; edit this file 'description' to name the repository.

+ 15 - 0
services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/incoming/DOTgit/hooks/applypatch-msg.sample

@@ -0,0 +1,15 @@
+#!/bin/sh
+#
+# An example hook script to check the commit log message taken by
+# applypatch from an e-mail message.
+#
+# The hook should exit with non-zero status after issuing an
+# appropriate message if it wants to stop the commit.  The hook is
+# allowed to edit the commit message file.
+#
+# To enable this hook, rename this file to "applypatch-msg".
+
+. git-sh-setup
+commitmsg="$(git rev-parse --git-path hooks/commit-msg)"
+test -x "$commitmsg" && exec "$commitmsg" ${1+"$@"}
+:

+ 24 - 0
services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/incoming/DOTgit/hooks/commit-msg.sample

@@ -0,0 +1,24 @@
+#!/bin/sh
+#
+# An example hook script to check the commit log message.
+# Called by "git commit" with one argument, the name of the file
+# that has the commit message.  The hook should exit with non-zero
+# status after issuing an appropriate message if it wants to stop the
+# commit.  The hook is allowed to edit the commit message file.
+#
+# To enable this hook, rename this file to "commit-msg".
+
+# Uncomment the below to add a Signed-off-by line to the message.
+# Doing this in a hook is a bad idea in general, but the prepare-commit-msg
+# hook is more suited to it.
+#
+# SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p')
+# grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1"
+
+# This example catches duplicate Signed-off-by lines.
+
+test "" = "$(grep '^Signed-off-by: ' "$1" |
+	 sort | uniq -c | sed -e '/^[ 	]*1[ 	]/d')" || {
+	echo >&2 Duplicate Signed-off-by lines.
+	exit 1
+}

+ 8 - 0
services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/incoming/DOTgit/hooks/post-update.sample

@@ -0,0 +1,8 @@
+#!/bin/sh
+#
+# An example hook script to prepare a packed repository for use over
+# dumb transports.
+#
+# To enable this hook, rename this file to "post-update".
+
+exec git update-server-info

+ 14 - 0
services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/incoming/DOTgit/hooks/pre-applypatch.sample

@@ -0,0 +1,14 @@
+#!/bin/sh
+#
+# An example hook script to verify what is about to be committed
+# by applypatch from an e-mail message.
+#
+# The hook should exit with non-zero status after issuing an
+# appropriate message if it wants to stop the commit.
+#
+# To enable this hook, rename this file to "pre-applypatch".
+
+. git-sh-setup
+precommit="$(git rev-parse --git-path hooks/pre-commit)"
+test -x "$precommit" && exec "$precommit" ${1+"$@"}
+:

+ 49 - 0
services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/incoming/DOTgit/hooks/pre-commit.sample

@@ -0,0 +1,49 @@
+#!/bin/sh
+#
+# An example hook script to verify what is about to be committed.
+# Called by "git commit" with no arguments.  The hook should
+# exit with non-zero status after issuing an appropriate message if
+# it wants to stop the commit.
+#
+# To enable this hook, rename this file to "pre-commit".
+
+if git rev-parse --verify HEAD >/dev/null 2>&1
+then
+	against=HEAD
+else
+	# Initial commit: diff against an empty tree object
+	against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
+fi
+
+# If you want to allow non-ASCII filenames set this variable to true.
+allownonascii=$(git config --bool hooks.allownonascii)
+
+# Redirect output to stderr.
+exec 1>&2
+
+# Cross platform projects tend to avoid non-ASCII filenames; prevent
+# them from being added to the repository. We exploit the fact that the
+# printable range starts at the space character and ends with tilde.
+if [ "$allownonascii" != "true" ] &&
+	# Note that the use of brackets around a tr range is ok here, (it's
+	# even required, for portability to Solaris 10's /usr/bin/tr), since
+	# the square bracket bytes happen to fall in the designated range.
+	test $(git diff --cached --name-only --diff-filter=A -z $against |
+	  LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0
+then
+	cat <<\EOF
+Error: Attempt to add a non-ASCII file name.
+
+This can cause problems if you want to work with people on other platforms.
+
+To be portable it is advisable to rename the file.
+
+If you know what you are doing you can disable this check using:
+
+  git config hooks.allownonascii true
+EOF
+	exit 1
+fi
+
+# If there are whitespace errors, print the offending file names and fail.
+exec git diff-index --check --cached $against --

+ 53 - 0
services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/incoming/DOTgit/hooks/pre-push.sample

@@ -0,0 +1,53 @@
+#!/bin/sh
+
+# An example hook script to verify what is about to be pushed.  Called by "git
+# push" after it has checked the remote status, but before anything has been
+# pushed.  If this script exits with a non-zero status nothing will be pushed.
+#
+# This hook is called with the following parameters:
+#
+# $1 -- Name of the remote to which the push is being done
+# $2 -- URL to which the push is being done
+#
+# If pushing without using a named remote those arguments will be equal.
+#
+# Information about the commits which are being pushed is supplied as lines to
+# the standard input in the form:
+#
+#   <local ref> <local sha1> <remote ref> <remote sha1>
+#
+# This sample shows how to prevent push of commits where the log message starts
+# with "WIP" (work in progress).
+
+remote="$1"
+url="$2"
+
+z40=0000000000000000000000000000000000000000
+
+while read local_ref local_sha remote_ref remote_sha
+do
+	if [ "$local_sha" = $z40 ]
+	then
+		# Handle delete
+		:
+	else
+		if [ "$remote_sha" = $z40 ]
+		then
+			# New branch, examine all commits
+			range="$local_sha"
+		else
+			# Update to existing branch, examine new commits
+			range="$remote_sha..$local_sha"
+		fi
+
+		# Check for WIP commit
+		commit=`git rev-list -n 1 --grep '^WIP' "$range"`
+		if [ -n "$commit" ]
+		then
+			echo >&2 "Found WIP commit in $local_ref, not pushing"
+			exit 1
+		fi
+	fi
+done
+
+exit 0

+ 169 - 0
services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/incoming/DOTgit/hooks/pre-rebase.sample

@@ -0,0 +1,169 @@
+#!/bin/sh
+#
+# Copyright (c) 2006, 2008 Junio C Hamano
+#
+# The "pre-rebase" hook is run just before "git rebase" starts doing
+# its job, and can prevent the command from running by exiting with
+# non-zero status.
+#
+# The hook is called with the following parameters:
+#
+# $1 -- the upstream the series was forked from.
+# $2 -- the branch being rebased (or empty when rebasing the current branch).
+#
+# This sample shows how to prevent topic branches that are already
+# merged to 'next' branch from getting rebased, because allowing it
+# would result in rebasing already published history.
+
+publish=next
+basebranch="$1"
+if test "$#" = 2
+then
+	topic="refs/heads/$2"
+else
+	topic=`git symbolic-ref HEAD` ||
+	exit 0 ;# we do not interrupt rebasing detached HEAD
+fi
+
+case "$topic" in
+refs/heads/??/*)
+	;;
+*)
+	exit 0 ;# we do not interrupt others.
+	;;
+esac
+
+# Now we are dealing with a topic branch being rebased
+# on top of master.  Is it OK to rebase it?
+
+# Does the topic really exist?
+git show-ref -q "$topic" || {
+	echo >&2 "No such branch $topic"
+	exit 1
+}
+
+# Is topic fully merged to master?
+not_in_master=`git rev-list --pretty=oneline ^master "$topic"`
+if test -z "$not_in_master"
+then
+	echo >&2 "$topic is fully merged to master; better remove it."
+	exit 1 ;# we could allow it, but there is no point.
+fi
+
+# Is topic ever merged to next?  If so you should not be rebasing it.
+only_next_1=`git rev-list ^master "^$topic" ${publish} | sort`
+only_next_2=`git rev-list ^master           ${publish} | sort`
+if test "$only_next_1" = "$only_next_2"
+then
+	not_in_topic=`git rev-list "^$topic" master`
+	if test -z "$not_in_topic"
+	then
+		echo >&2 "$topic is already up-to-date with master"
+		exit 1 ;# we could allow it, but there is no point.
+	else
+		exit 0
+	fi
+else
+	not_in_next=`git rev-list --pretty=oneline ^${publish} "$topic"`
+	/usr/bin/perl -e '
+		my $topic = $ARGV[0];
+		my $msg = "* $topic has commits already merged to public branch:\n";
+		my (%not_in_next) = map {
+			/^([0-9a-f]+) /;
+			($1 => 1);
+		} split(/\n/, $ARGV[1]);
+		for my $elem (map {
+				/^([0-9a-f]+) (.*)$/;
+				[$1 => $2];
+			} split(/\n/, $ARGV[2])) {
+			if (!exists $not_in_next{$elem->[0]}) {
+				if ($msg) {
+					print STDERR $msg;
+					undef $msg;
+				}
+				print STDERR " $elem->[1]\n";
+			}
+		}
+	' "$topic" "$not_in_next" "$not_in_master"
+	exit 1
+fi
+
+exit 0
+
+################################################################
+
+This sample hook safeguards topic branches that have been
+published from being rewound.
+
+The workflow assumed here is:
+
+ * Once a topic branch forks from "master", "master" is never
+   merged into it again (either directly or indirectly).
+
+ * Once a topic branch is fully cooked and merged into "master",
+   it is deleted.  If you need to build on top of it to correct
+   earlier mistakes, a new topic branch is created by forking at
+   the tip of the "master".  This is not strictly necessary, but
+   it makes it easier to keep your history simple.
+
+ * Whenever you need to test or publish your changes to topic
+   branches, merge them into "next" branch.
+
+The script, being an example, hardcodes the publish branch name
+to be "next", but it is trivial to make it configurable via
+$GIT_DIR/config mechanism.
+
+With this workflow, you would want to know:
+
+(1) ... if a topic branch has ever been merged to "next".  Young
+    topic branches can have stupid mistakes you would rather
+    clean up before publishing, and things that have not been
+    merged into other branches can be easily rebased without
+    affecting other people.  But once it is published, you would
+    not want to rewind it.
+
+(2) ... if a topic branch has been fully merged to "master".
+    Then you can delete it.  More importantly, you should not
+    build on top of it -- other people may already want to
+    change things related to the topic as patches against your
+    "master", so if you need further changes, it is better to
+    fork the topic (perhaps with the same name) afresh from the
+    tip of "master".
+
+Let's look at this example:
+
+		   o---o---o---o---o---o---o---o---o---o "next"
+		  /       /           /           /
+		 /   a---a---b A     /           /
+		/   /               /           /
+	       /   /   c---c---c---c B         /
+	      /   /   /             \         /
+	     /   /   /   b---b C     \       /
+	    /   /   /   /             \     /
+    ---o---o---o---o---o---o---o---o---o---o---o "master"
+
+
+A, B and C are topic branches.
+
+ * A has one fix since it was merged up to "next".
+
+ * B has finished.  It has been fully merged up to "master" and "next",
+   and is ready to be deleted.
+
+ * C has not merged to "next" at all.
+
+We would want to allow C to be rebased, refuse A, and encourage
+B to be deleted.
+
+To compute (1):
+
+	git rev-list ^master ^topic next
+	git rev-list ^master        next
+
+	if these match, topic has not merged in next at all.
+
+To compute (2):
+
+	git rev-list master..topic
+
+	if this is empty, it is fully merged to "master".

+ 36 - 0
services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/incoming/DOTgit/hooks/prepare-commit-msg.sample

@@ -0,0 +1,36 @@
+#!/bin/sh
+#
+# An example hook script to prepare the commit log message.
+# Called by "git commit" with the name of the file that has the
+# commit message, followed by the description of the commit
+# message's source.  The hook's purpose is to edit the commit
+# message file.  If the hook fails with a non-zero status,
+# the commit is aborted.
+#
+# To enable this hook, rename this file to "prepare-commit-msg".
+
+# This hook includes three examples.  The first comments out the
+# "Conflicts:" part of a merge commit.
+#
+# The second includes the output of "git diff --name-status -r"
+# into the message, just before the "git status" output.  It is
+# commented because it doesn't cope with --amend or with squashed
+# commits.
+#
+# The third example adds a Signed-off-by line to the message, that can
+# still be edited.  This is rarely a good idea.
+
+case "$2,$3" in
+  merge,)
+    /usr/bin/perl -i.bak -ne 's/^/# /, s/^# #/#/ if /^Conflicts/ .. /#/; print' "$1" ;;
+
+# ,|template,)
+#   /usr/bin/perl -i.bak -pe '
+#      print "\n" . `git diff --cached --name-status -r`
+#	 if /^#/ && $first++ == 0' "$1" ;;
+
+  *) ;;
+esac
+
+# SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p')
+# grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1"

+ 128 - 0
services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/incoming/DOTgit/hooks/update.sample

@@ -0,0 +1,128 @@
+#!/bin/sh
+#
+# An example hook script to block unannotated tags from entering.
+# Called by "git receive-pack" with arguments: refname sha1-old sha1-new
+#
+# To enable this hook, rename this file to "update".
+#
+# Config
+# ------
+# hooks.allowunannotated
+#   This boolean sets whether unannotated tags will be allowed into the
+#   repository.  By default they won't be.
+# hooks.allowdeletetag
+#   This boolean sets whether deleting tags will be allowed in the
+#   repository.  By default they won't be.
+# hooks.allowmodifytag
+#   This boolean sets whether a tag may be modified after creation. By default
+#   it won't be.
+# hooks.allowdeletebranch
+#   This boolean sets whether deleting branches will be allowed in the
+#   repository.  By default they won't be.
+# hooks.denycreatebranch
+#   This boolean sets whether remotely creating branches will be denied
+#   in the repository.  By default this is allowed.
+#
+
+# --- Command line
+refname="$1"
+oldrev="$2"
+newrev="$3"
+
+# --- Safety check
+if [ -z "$GIT_DIR" ]; then
+	echo "Don't run this script from the command line." >&2
+	echo " (if you want, you could supply GIT_DIR then run" >&2
+	echo "  $0 <ref> <oldrev> <newrev>)" >&2
+	exit 1
+fi
+
+if [ -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then
+	echo "usage: $0 <ref> <oldrev> <newrev>" >&2
+	exit 1
+fi
+
+# --- Config
+allowunannotated=$(git config --bool hooks.allowunannotated)
+allowdeletebranch=$(git config --bool hooks.allowdeletebranch)
+denycreatebranch=$(git config --bool hooks.denycreatebranch)
+allowdeletetag=$(git config --bool hooks.allowdeletetag)
+allowmodifytag=$(git config --bool hooks.allowmodifytag)
+
+# check for no description
+projectdesc=$(sed -e '1q' "$GIT_DIR/description")
+case "$projectdesc" in
+"Unnamed repository"* | "")
+	echo "*** Project description file hasn't been set" >&2
+	exit 1
+	;;
+esac
+
+# --- Check types
+# if $newrev is 0000...0000, it's a commit to delete a ref.
+zero="0000000000000000000000000000000000000000"
+if [ "$newrev" = "$zero" ]; then
+	newrev_type=delete
+else
+	newrev_type=$(git cat-file -t $newrev)
+fi
+
+case "$refname","$newrev_type" in
+	refs/tags/*,commit)
+		# un-annotated tag
+		short_refname=${refname##refs/tags/}
+		if [ "$allowunannotated" != "true" ]; then
+			echo "*** The un-annotated tag, $short_refname, is not allowed in this repository" >&2
+			echo "*** Use 'git tag [ -a | -s ]' for tags you want to propagate." >&2
+			exit 1
+		fi
+		;;
+	refs/tags/*,delete)
+		# delete tag
+		if [ "$allowdeletetag" != "true" ]; then
+			echo "*** Deleting a tag is not allowed in this repository" >&2
+			exit 1
+		fi
+		;;
+	refs/tags/*,tag)
+		# annotated tag
+		if [ "$allowmodifytag" != "true" ] && git rev-parse $refname > /dev/null 2>&1
+		then
+			echo "*** Tag '$refname' already exists." >&2
+			echo "*** Modifying a tag is not allowed in this repository." >&2
+			exit 1
+		fi
+		;;
+	refs/heads/*,commit)
+		# branch
+		if [ "$oldrev" = "$zero" -a "$denycreatebranch" = "true" ]; then
+			echo "*** Creating a branch is not allowed in this repository" >&2
+			exit 1
+		fi
+		;;
+	refs/heads/*,delete)
+		# delete branch
+		if [ "$allowdeletebranch" != "true" ]; then
+			echo "*** Deleting a branch is not allowed in this repository" >&2
+			exit 1
+		fi
+		;;
+	refs/remotes/*,commit)
+		# tracking branch
+		;;
+	refs/remotes/*,delete)
+		# delete tracking branch
+		if [ "$allowdeletebranch" != "true" ]; then
+			echo "*** Deleting a tracking branch is not allowed in this repository" >&2
+			exit 1
+		fi
+		;;
+	*)
+		# Anything else (is there anything else?)
+		echo "*** Update hook: unknown type of update to ref $refname of type $newrev_type" >&2
+		exit 1
+		;;
+esac
+
+# --- Finished
+exit 0

BIN
services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/incoming/DOTgit/index


+ 6 - 0
services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/incoming/DOTgit/info/exclude

@@ -0,0 +1,6 @@
+# git ls-files --others --exclude-from=.git/info/exclude
+# Lines that start with '#' are comments.
+# For a project mostly in C, the following would be a good set of
+# exclude patterns (uncomment them if you want to use them):
+# *.[oa]
+# *~

+ 1 - 0
services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/incoming/DOTgit/info/refs

@@ -0,0 +1 @@
+71ebe5d70c8634f7531cc09c1cad5dae951a9052	refs/heads/master

+ 0 - 0
services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/incoming/DOTgit/logs/HEAD


+ 0 - 0
services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/incoming/DOTgit/logs/refs/heads/master


+ 1 - 0
services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/incoming/DOTgit/objects/incoming_4632440628786417060.pack

@@ -0,0 +1 @@
+blah blah blah

+ 1 - 0
services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/incoming/DOTgit/objects/incoming_4635689790689803605.pack

@@ -0,0 +1 @@
+i am a pack

+ 2 - 0
services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/incoming/DOTgit/objects/info/packs

@@ -0,0 +1,2 @@
+P pack-71e0b18bc4675e30d48c891ae9bfc2487ec6e0bb.pack
+

BIN
services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/incoming/DOTgit/objects/pack/pack-71e0b18bc4675e30d48c891ae9bfc2487ec6e0bb.idx


BIN
services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/incoming/DOTgit/objects/pack/pack-71e0b18bc4675e30d48c891ae9bfc2487ec6e0bb.pack


+ 2 - 0
services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/incoming/DOTgit/packed-refs

@@ -0,0 +1,2 @@
+# pack-refs with: peeled fully-peeled 
+71ebe5d70c8634f7531cc09c1cad5dae951a9052 refs/heads/master

+ 0 - 0
services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/incoming/file1.txt


+ 0 - 0
services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/incoming/file2.txt


BIN
services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/repo/DOTgit/index


+ 2 - 0
services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/without_incoming/.gitignore

@@ -0,0 +1,2 @@
+*.ignored
+

+ 1 - 0
services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/without_incoming/DOTgit/COMMIT_EDITMSG

@@ -0,0 +1 @@
+Add ignored file

+ 1 - 0
services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/without_incoming/DOTgit/HEAD

@@ -0,0 +1 @@
+ref: refs/heads/master

+ 7 - 0
services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/without_incoming/DOTgit/config

@@ -0,0 +1,7 @@
+[core]
+	repositoryformatversion = 0
+	filemode = true
+	bare = false
+	logallrefupdates = true
+	ignorecase = true
+	precomposeunicode = true

+ 1 - 0
services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/without_incoming/DOTgit/description

@@ -0,0 +1 @@
+Unnamed repository; edit this file 'description' to name the repository.

+ 15 - 0
services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/without_incoming/DOTgit/hooks/applypatch-msg.sample

@@ -0,0 +1,15 @@
+#!/bin/sh
+#
+# An example hook script to check the commit log message taken by
+# applypatch from an e-mail message.
+#
+# The hook should exit with non-zero status after issuing an
+# appropriate message if it wants to stop the commit.  The hook is
+# allowed to edit the commit message file.
+#
+# To enable this hook, rename this file to "applypatch-msg".
+
+. git-sh-setup
+commitmsg="$(git rev-parse --git-path hooks/commit-msg)"
+test -x "$commitmsg" && exec "$commitmsg" ${1+"$@"}
+:

+ 24 - 0
services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/without_incoming/DOTgit/hooks/commit-msg.sample

@@ -0,0 +1,24 @@
+#!/bin/sh
+#
+# An example hook script to check the commit log message.
+# Called by "git commit" with one argument, the name of the file
+# that has the commit message.  The hook should exit with non-zero
+# status after issuing an appropriate message if it wants to stop the
+# commit.  The hook is allowed to edit the commit message file.
+#
+# To enable this hook, rename this file to "commit-msg".
+
+# Uncomment the below to add a Signed-off-by line to the message.
+# Doing this in a hook is a bad idea in general, but the prepare-commit-msg
+# hook is more suited to it.
+#
+# SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p')
+# grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1"
+
+# This example catches duplicate Signed-off-by lines.
+
+test "" = "$(grep '^Signed-off-by: ' "$1" |
+	 sort | uniq -c | sed -e '/^[ 	]*1[ 	]/d')" || {
+	echo >&2 Duplicate Signed-off-by lines.
+	exit 1
+}

+ 8 - 0
services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/without_incoming/DOTgit/hooks/post-update.sample

@@ -0,0 +1,8 @@
+#!/bin/sh
+#
+# An example hook script to prepare a packed repository for use over
+# dumb transports.
+#
+# To enable this hook, rename this file to "post-update".
+
+exec git update-server-info

+ 14 - 0
services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/without_incoming/DOTgit/hooks/pre-applypatch.sample

@@ -0,0 +1,14 @@
+#!/bin/sh
+#
+# An example hook script to verify what is about to be committed
+# by applypatch from an e-mail message.
+#
+# The hook should exit with non-zero status after issuing an
+# appropriate message if it wants to stop the commit.
+#
+# To enable this hook, rename this file to "pre-applypatch".
+
+. git-sh-setup
+precommit="$(git rev-parse --git-path hooks/pre-commit)"
+test -x "$precommit" && exec "$precommit" ${1+"$@"}
+:

+ 49 - 0
services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/without_incoming/DOTgit/hooks/pre-commit.sample

@@ -0,0 +1,49 @@
+#!/bin/sh
+#
+# An example hook script to verify what is about to be committed.
+# Called by "git commit" with no arguments.  The hook should
+# exit with non-zero status after issuing an appropriate message if
+# it wants to stop the commit.
+#
+# To enable this hook, rename this file to "pre-commit".
+
+if git rev-parse --verify HEAD >/dev/null 2>&1
+then
+	against=HEAD
+else
+	# Initial commit: diff against an empty tree object
+	against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
+fi
+
+# If you want to allow non-ASCII filenames set this variable to true.
+allownonascii=$(git config --bool hooks.allownonascii)
+
+# Redirect output to stderr.
+exec 1>&2
+
+# Cross platform projects tend to avoid non-ASCII filenames; prevent
+# them from being added to the repository. We exploit the fact that the
+# printable range starts at the space character and ends with tilde.
+if [ "$allownonascii" != "true" ] &&
+	# Note that the use of brackets around a tr range is ok here, (it's
+	# even required, for portability to Solaris 10's /usr/bin/tr), since
+	# the square bracket bytes happen to fall in the designated range.
+	test $(git diff --cached --name-only --diff-filter=A -z $against |
+	  LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0
+then
+	cat <<\EOF
+Error: Attempt to add a non-ASCII file name.
+
+This can cause problems if you want to work with people on other platforms.
+
+To be portable it is advisable to rename the file.
+
+If you know what you are doing you can disable this check using:
+
+  git config hooks.allownonascii true
+EOF
+	exit 1
+fi
+
+# If there are whitespace errors, print the offending file names and fail.
+exec git diff-index --check --cached $against --

+ 53 - 0
services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/without_incoming/DOTgit/hooks/pre-push.sample

@@ -0,0 +1,53 @@
+#!/bin/sh
+
+# An example hook script to verify what is about to be pushed.  Called by "git
+# push" after it has checked the remote status, but before anything has been
+# pushed.  If this script exits with a non-zero status nothing will be pushed.
+#
+# This hook is called with the following parameters:
+#
+# $1 -- Name of the remote to which the push is being done
+# $2 -- URL to which the push is being done
+#
+# If pushing without using a named remote those arguments will be equal.
+#
+# Information about the commits which are being pushed is supplied as lines to
+# the standard input in the form:
+#
+#   <local ref> <local sha1> <remote ref> <remote sha1>
+#
+# This sample shows how to prevent push of commits where the log message starts
+# with "WIP" (work in progress).
+
+remote="$1"
+url="$2"
+
+z40=0000000000000000000000000000000000000000
+
+while read local_ref local_sha remote_ref remote_sha
+do
+	if [ "$local_sha" = $z40 ]
+	then
+		# Handle delete
+		:
+	else
+		if [ "$remote_sha" = $z40 ]
+		then
+			# New branch, examine all commits
+			range="$local_sha"
+		else
+			# Update to existing branch, examine new commits
+			range="$remote_sha..$local_sha"
+		fi
+
+		# Check for WIP commit
+		commit=`git rev-list -n 1 --grep '^WIP' "$range"`
+		if [ -n "$commit" ]
+		then
+			echo >&2 "Found WIP commit in $local_ref, not pushing"
+			exit 1
+		fi
+	fi
+done
+
+exit 0

+ 169 - 0
services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/without_incoming/DOTgit/hooks/pre-rebase.sample

@@ -0,0 +1,169 @@
+#!/bin/sh
+#
+# Copyright (c) 2006, 2008 Junio C Hamano
+#
+# The "pre-rebase" hook is run just before "git rebase" starts doing
+# its job, and can prevent the command from running by exiting with
+# non-zero status.
+#
+# The hook is called with the following parameters:
+#
+# $1 -- the upstream the series was forked from.
+# $2 -- the branch being rebased (or empty when rebasing the current branch).
+#
+# This sample shows how to prevent topic branches that are already
+# merged to 'next' branch from getting rebased, because allowing it
+# would result in rebasing already published history.
+
+publish=next
+basebranch="$1"
+if test "$#" = 2
+then
+	topic="refs/heads/$2"
+else
+	topic=`git symbolic-ref HEAD` ||
+	exit 0 ;# we do not interrupt rebasing detached HEAD
+fi
+
+case "$topic" in
+refs/heads/??/*)
+	;;
+*)
+	exit 0 ;# we do not interrupt others.
+	;;
+esac
+
+# Now we are dealing with a topic branch being rebased
+# on top of master.  Is it OK to rebase it?
+
+# Does the topic really exist?
+git show-ref -q "$topic" || {
+	echo >&2 "No such branch $topic"
+	exit 1
+}
+
+# Is topic fully merged to master?
+not_in_master=`git rev-list --pretty=oneline ^master "$topic"`
+if test -z "$not_in_master"
+then
+	echo >&2 "$topic is fully merged to master; better remove it."
+	exit 1 ;# we could allow it, but there is no point.
+fi
+
+# Is topic ever merged to next?  If so you should not be rebasing it.
+only_next_1=`git rev-list ^master "^$topic" ${publish} | sort`
+only_next_2=`git rev-list ^master           ${publish} | sort`
+if test "$only_next_1" = "$only_next_2"
+then
+	not_in_topic=`git rev-list "^$topic" master`
+	if test -z "$not_in_topic"
+	then
+		echo >&2 "$topic is already up-to-date with master"
+		exit 1 ;# we could allow it, but there is no point.
+	else
+		exit 0
+	fi
+else
+	not_in_next=`git rev-list --pretty=oneline ^${publish} "$topic"`
+	/usr/bin/perl -e '
+		my $topic = $ARGV[0];
+		my $msg = "* $topic has commits already merged to public branch:\n";
+		my (%not_in_next) = map {
+			/^([0-9a-f]+) /;
+			($1 => 1);
+		} split(/\n/, $ARGV[1]);
+		for my $elem (map {
+				/^([0-9a-f]+) (.*)$/;
+				[$1 => $2];
+			} split(/\n/, $ARGV[2])) {
+			if (!exists $not_in_next{$elem->[0]}) {
+				if ($msg) {
+					print STDERR $msg;
+					undef $msg;
+				}
+				print STDERR " $elem->[1]\n";
+			}
+		}
+	' "$topic" "$not_in_next" "$not_in_master"
+	exit 1
+fi
+
+exit 0
+
+################################################################
+
+This sample hook safeguards topic branches that have been
+published from being rewound.
+
+The workflow assumed here is:
+
+ * Once a topic branch forks from "master", "master" is never
+   merged into it again (either directly or indirectly).
+
+ * Once a topic branch is fully cooked and merged into "master",
+   it is deleted.  If you need to build on top of it to correct
+   earlier mistakes, a new topic branch is created by forking at
+   the tip of the "master".  This is not strictly necessary, but
+   it makes it easier to keep your history simple.
+
+ * Whenever you need to test or publish your changes to topic
+   branches, merge them into "next" branch.
+
+The script, being an example, hardcodes the publish branch name
+to be "next", but it is trivial to make it configurable via
+$GIT_DIR/config mechanism.
+
+With this workflow, you would want to know:
+
+(1) ... if a topic branch has ever been merged to "next".  Young
+    topic branches can have stupid mistakes you would rather
+    clean up before publishing, and things that have not been
+    merged into other branches can be easily rebased without
+    affecting other people.  But once it is published, you would
+    not want to rewind it.
+
+(2) ... if a topic branch has been fully merged to "master".
+    Then you can delete it.  More importantly, you should not
+    build on top of it -- other people may already want to
+    change things related to the topic as patches against your
+    "master", so if you need further changes, it is better to
+    fork the topic (perhaps with the same name) afresh from the
+    tip of "master".
+
+Let's look at this example:
+
+		   o---o---o---o---o---o---o---o---o---o "next"
+		  /       /           /           /
+		 /   a---a---b A     /           /
+		/   /               /           /
+	       /   /   c---c---c---c B         /
+	      /   /   /             \         /
+	     /   /   /   b---b C     \       /
+	    /   /   /   /             \     /
+    ---o---o---o---o---o---o---o---o---o---o---o "master"
+
+
+A, B and C are topic branches.
+
+ * A has one fix since it was merged up to "next".
+
+ * B has finished.  It has been fully merged up to "master" and "next",
+   and is ready to be deleted.
+
+ * C has not merged to "next" at all.
+
+We would want to allow C to be rebased, refuse A, and encourage
+B to be deleted.
+
+To compute (1):
+
+	git rev-list ^master ^topic next
+	git rev-list ^master        next
+
+	if these match, topic has not merged in next at all.
+
+To compute (2):
+
+	git rev-list master..topic
+
+	if this is empty, it is fully merged to "master".

+ 36 - 0
services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/without_incoming/DOTgit/hooks/prepare-commit-msg.sample

@@ -0,0 +1,36 @@
+#!/bin/sh
+#
+# An example hook script to prepare the commit log message.
+# Called by "git commit" with the name of the file that has the
+# commit message, followed by the description of the commit
+# message's source.  The hook's purpose is to edit the commit
+# message file.  If the hook fails with a non-zero status,
+# the commit is aborted.
+#
+# To enable this hook, rename this file to "prepare-commit-msg".
+
+# This hook includes three examples.  The first comments out the
+# "Conflicts:" part of a merge commit.
+#
+# The second includes the output of "git diff --name-status -r"
+# into the message, just before the "git status" output.  It is
+# commented because it doesn't cope with --amend or with squashed
+# commits.
+#
+# The third example adds a Signed-off-by line to the message, that can
+# still be edited.  This is rarely a good idea.
+
+case "$2,$3" in
+  merge,)
+    /usr/bin/perl -i.bak -ne 's/^/# /, s/^# #/#/ if /^Conflicts/ .. /#/; print' "$1" ;;
+
+# ,|template,)
+#   /usr/bin/perl -i.bak -pe '
+#      print "\n" . `git diff --cached --name-status -r`
+#	 if /^#/ && $first++ == 0' "$1" ;;
+
+  *) ;;
+esac
+
+# SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p')
+# grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1"

+ 128 - 0
services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/without_incoming/DOTgit/hooks/update.sample

@@ -0,0 +1,128 @@
+#!/bin/sh
+#
+# An example hook script to block unannotated tags from entering.
+# Called by "git receive-pack" with arguments: refname sha1-old sha1-new
+#
+# To enable this hook, rename this file to "update".
+#
+# Config
+# ------
+# hooks.allowunannotated
+#   This boolean sets whether unannotated tags will be allowed into the
+#   repository.  By default they won't be.
+# hooks.allowdeletetag
+#   This boolean sets whether deleting tags will be allowed in the
+#   repository.  By default they won't be.
+# hooks.allowmodifytag
+#   This boolean sets whether a tag may be modified after creation. By default
+#   it won't be.
+# hooks.allowdeletebranch
+#   This boolean sets whether deleting branches will be allowed in the
+#   repository.  By default they won't be.
+# hooks.denycreatebranch
+#   This boolean sets whether remotely creating branches will be denied
+#   in the repository.  By default this is allowed.
+#
+
+# --- Command line
+refname="$1"
+oldrev="$2"
+newrev="$3"
+
+# --- Safety check
+if [ -z "$GIT_DIR" ]; then
+	echo "Don't run this script from the command line." >&2
+	echo " (if you want, you could supply GIT_DIR then run" >&2
+	echo "  $0 <ref> <oldrev> <newrev>)" >&2
+	exit 1
+fi
+
+if [ -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then
+	echo "usage: $0 <ref> <oldrev> <newrev>" >&2
+	exit 1
+fi
+
+# --- Config
+allowunannotated=$(git config --bool hooks.allowunannotated)
+allowdeletebranch=$(git config --bool hooks.allowdeletebranch)
+denycreatebranch=$(git config --bool hooks.denycreatebranch)
+allowdeletetag=$(git config --bool hooks.allowdeletetag)
+allowmodifytag=$(git config --bool hooks.allowmodifytag)
+
+# check for no description
+projectdesc=$(sed -e '1q' "$GIT_DIR/description")
+case "$projectdesc" in
+"Unnamed repository"* | "")
+	echo "*** Project description file hasn't been set" >&2
+	exit 1
+	;;
+esac
+
+# --- Check types
+# if $newrev is 0000...0000, it's a commit to delete a ref.
+zero="0000000000000000000000000000000000000000"
+if [ "$newrev" = "$zero" ]; then
+	newrev_type=delete
+else
+	newrev_type=$(git cat-file -t $newrev)
+fi
+
+case "$refname","$newrev_type" in
+	refs/tags/*,commit)
+		# un-annotated tag
+		short_refname=${refname##refs/tags/}
+		if [ "$allowunannotated" != "true" ]; then
+			echo "*** The un-annotated tag, $short_refname, is not allowed in this repository" >&2
+			echo "*** Use 'git tag [ -a | -s ]' for tags you want to propagate." >&2
+			exit 1
+		fi
+		;;
+	refs/tags/*,delete)
+		# delete tag
+		if [ "$allowdeletetag" != "true" ]; then
+			echo "*** Deleting a tag is not allowed in this repository" >&2
+			exit 1
+		fi
+		;;
+	refs/tags/*,tag)
+		# annotated tag
+		if [ "$allowmodifytag" != "true" ] && git rev-parse $refname > /dev/null 2>&1
+		then
+			echo "*** Tag '$refname' already exists." >&2
+			echo "*** Modifying a tag is not allowed in this repository." >&2
+			exit 1
+		fi
+		;;
+	refs/heads/*,commit)
+		# branch
+		if [ "$oldrev" = "$zero" -a "$denycreatebranch" = "true" ]; then
+			echo "*** Creating a branch is not allowed in this repository" >&2
+			exit 1
+		fi
+		;;
+	refs/heads/*,delete)
+		# delete branch
+		if [ "$allowdeletebranch" != "true" ]; then
+			echo "*** Deleting a branch is not allowed in this repository" >&2
+			exit 1
+		fi
+		;;
+	refs/remotes/*,commit)
+		# tracking branch
+		;;
+	refs/remotes/*,delete)
+		# delete tracking branch
+		if [ "$allowdeletebranch" != "true" ]; then
+			echo "*** Deleting a tracking branch is not allowed in this repository" >&2
+			exit 1
+		fi
+		;;
+	*)
+		# Anything else (is there anything else?)
+		echo "*** Update hook: unknown type of update to ref $refname of type $newrev_type" >&2
+		exit 1
+		;;
+esac
+
+# --- Finished
+exit 0

BIN
services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/without_incoming/DOTgit/index


+ 6 - 0
services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/without_incoming/DOTgit/info/exclude

@@ -0,0 +1,6 @@
+# git ls-files --others --exclude-from=.git/info/exclude
+# Lines that start with '#' are comments.
+# For a project mostly in C, the following would be a good set of
+# exclude patterns (uncomment them if you want to use them):
+# *.[oa]
+# *~

+ 1 - 0
services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/without_incoming/DOTgit/info/refs

@@ -0,0 +1 @@
+71ebe5d70c8634f7531cc09c1cad5dae951a9052	refs/heads/master

+ 0 - 0
services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/without_incoming/DOTgit/logs/HEAD


+ 0 - 0
services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/without_incoming/DOTgit/logs/refs/heads/master


+ 2 - 0
services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/without_incoming/DOTgit/objects/info/packs

@@ -0,0 +1,2 @@
+P pack-71e0b18bc4675e30d48c891ae9bfc2487ec6e0bb.pack
+

BIN
services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/without_incoming/DOTgit/objects/pack/pack-71e0b18bc4675e30d48c891ae9bfc2487ec6e0bb.idx


BIN
services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/without_incoming/DOTgit/objects/pack/pack-71e0b18bc4675e30d48c891ae9bfc2487ec6e0bb.pack


+ 2 - 0
services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/without_incoming/DOTgit/packed-refs

@@ -0,0 +1,2 @@
+# pack-refs with: peeled fully-peeled 
+71ebe5d70c8634f7531cc09c1cad5dae951a9052 refs/heads/master

+ 0 - 0
services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/without_incoming/file1.txt


+ 0 - 0
services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepoTest/rootdir/without_incoming/file2.txt