From c845d276c759b606c9d8c9b20ae663a928b507df Mon Sep 17 00:00:00 2001 From: Adrian Gonzalez Date: Wed, 17 Jul 2013 13:54:13 -0400 Subject: [PATCH] Changed git command to use --prune with refspecs +refs/heads/*:refs/heads/* +refs/tags/*:refs/tags/* instead of --mirror to avoid mirroring pull-request refspecs. (fixes #11) --- pom.xml | 2 +- .../com/englishtown/stash/hook/MirrorRepositoryHook.java | 7 +++++-- .../englishtown/stash/hook/MirrorRepositoryHookTest.java | 4 +++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index f84aa20..b121acd 100644 --- a/pom.xml +++ b/pom.xml @@ -29,7 +29,7 @@ UTF-8 2.4.1 2.4.1 - 4.2.0 + 4.2.3 1.1.1 4.10 diff --git a/src/main/java/com/englishtown/stash/hook/MirrorRepositoryHook.java b/src/main/java/com/englishtown/stash/hook/MirrorRepositoryHook.java index 7cd9636..19b2fa1 100644 --- a/src/main/java/com/englishtown/stash/hook/MirrorRepositoryHook.java +++ b/src/main/java/com/englishtown/stash/hook/MirrorRepositoryHook.java @@ -114,11 +114,14 @@ public class MirrorRepositoryHook implements AsyncPostReceiveRepositoryHook, Rep CommandExitHandler exitHandler = new GitCommandExitHandler(i18nService, repository); PasswordHandler passwordHandler = new PasswordHandler(password, exitHandler); - // Call push command with the mirror flag set + // Call push command with the prune flag and refspecs for heads and tags + // Do not use the mirror flag as pull-request refs are included String result = builder .command("push") - .argument("--mirror") + .argument("--prune") // this deletes locally deleted branches .argument(authenticatedUrl.toString()) + .argument("+refs/heads/*:refs/heads/*") // Only mirror heads + .argument("+refs/tags/*:refs/tags/*") // and tags .errorHandler(passwordHandler) .exitHandler(passwordHandler) .build(passwordHandler) diff --git a/src/test/java/com/englishtown/stash/hook/MirrorRepositoryHookTest.java b/src/test/java/com/englishtown/stash/hook/MirrorRepositoryHookTest.java index 1a4bdb6..7683de6 100644 --- a/src/test/java/com/englishtown/stash/hook/MirrorRepositoryHookTest.java +++ b/src/test/java/com/englishtown/stash/hook/MirrorRepositoryHookTest.java @@ -164,8 +164,10 @@ public class MirrorRepositoryHookTest { callable.call(); verify(builder, times(1)).command(eq("push")); - verify(builder, times(1)).argument(eq("--mirror")); + verify(builder, times(1)).argument(eq("--prune")); verify(builder, times(1)).argument(eq(repository)); + verify(builder, times(1)).argument(eq("+refs/heads/*:refs/heads/*")); + verify(builder, times(1)).argument(eq("+refs/tags/*:refs/tags/*")); verify(cmd, times(1)).call(); }