Browse Source

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)

pull/21/head
Adrian Gonzalez 11 years ago
parent
commit
c845d276c7
  1. 2
      pom.xml
  2. 7
      src/main/java/com/englishtown/stash/hook/MirrorRepositoryHook.java
  3. 4
      src/test/java/com/englishtown/stash/hook/MirrorRepositoryHookTest.java

2
pom.xml

@ -29,7 +29,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<stash.version>2.4.1</stash.version>
<stash.data.version>2.4.1</stash.data.version>
<amps.version>4.2.0</amps.version>
<amps.version>4.2.3</amps.version>
<plugin.testrunner.version>1.1.1</plugin.testrunner.version>
<junit.version>4.10</junit.version>

7
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)

4
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();
}

Loading…
Cancel
Save