Browse Source

Merge tag '2.3.1'

[maven-release-plugin] copy for tag 2.3.1
pull/60/head
Adrian Gonzalez 7 years ago
parent
commit
a40d8762d6
  1. 4
      pom.xml
  2. 16
      src/main/java/com/englishtown/bitbucket/hook/MirrorRepositoryHook.java
  3. 6
      src/main/resources/i18n/stash-hook-mirror.properties
  4. 6
      src/main/resources/static/mirror-repository-hook.soy
  5. 1
      src/test/java/com/englishtown/bitbucket/hook/MirrorRepositoryHookTest.java

4
pom.xml

@ -5,7 +5,7 @@
<groupId>com.englishtown</groupId> <groupId>com.englishtown</groupId>
<artifactId>stash-hook-mirror</artifactId> <artifactId>stash-hook-mirror</artifactId>
<version>2.3.0</version> <version>2.3.1</version>
<organization> <organization>
<name>Englishtown</name> <name>Englishtown</name>
@ -131,7 +131,7 @@
<connection>scm:git:git@github.com:ef-labs/stash-hook-mirror.git</connection> <connection>scm:git:git@github.com:ef-labs/stash-hook-mirror.git</connection>
<developerConnection>scm:git:git@github.com:ef-labs/stash-hook-mirror.git</developerConnection> <developerConnection>scm:git:git@github.com:ef-labs/stash-hook-mirror.git</developerConnection>
<url>https://github.com/ef-labs/stash-hook-mirror</url> <url>https://github.com/ef-labs/stash-hook-mirror</url>
<tag>2.3.0</tag> <tag>2.3.1</tag>
</scm> </scm>
<distributionManagement> <distributionManagement>

16
src/main/java/com/englishtown/bitbucket/hook/MirrorRepositoryHook.java

@ -38,6 +38,7 @@ public class MirrorRepositoryHook implements AsyncPostReceiveRepositoryHook, Rep
String refspec; String refspec;
boolean tags; boolean tags;
boolean notes; boolean notes;
boolean atomic;
} }
public static final String PLUGIN_SETTINGS_KEY = "com.englishtown.stash.hook.mirror"; public static final String PLUGIN_SETTINGS_KEY = "com.englishtown.stash.hook.mirror";
@ -47,6 +48,7 @@ public class MirrorRepositoryHook implements AsyncPostReceiveRepositoryHook, Rep
static final String SETTING_REFSPEC = "refspec"; static final String SETTING_REFSPEC = "refspec";
static final String SETTING_TAGS = "tags"; static final String SETTING_TAGS = "tags";
static final String SETTING_NOTES = "notes"; static final String SETTING_NOTES = "notes";
static final String SETTING_ATOMIC = "atomic";
static final int MAX_ATTEMPTS = 5; static final int MAX_ATTEMPTS = 5;
static final String DEFAULT_REFSPEC = "+refs/heads/*:refs/heads/*"; static final String DEFAULT_REFSPEC = "+refs/heads/*:refs/heads/*";
@ -139,10 +141,14 @@ public class MirrorRepositoryHook implements AsyncPostReceiveRepositoryHook, Rep
// Do not use the mirror flag as pull-request refs are included // Do not use the mirror flag as pull-request refs are included
builder.command("push") builder.command("push")
.argument("--prune") // this deletes locally deleted branches .argument("--prune") // this deletes locally deleted branches
.argument("--atomic") // use an atomic transaction to have a consistent state
.argument(authenticatedUrl) .argument(authenticatedUrl)
.argument("--force"); .argument("--force");
// Use an atomic transaction to have a consistent state
if (settings.atomic) {
builder.argument("--atomic");
}
// Add refspec args // Add refspec args
String refspecs = Strings.isNullOrEmpty(settings.refspec) ? DEFAULT_REFSPEC : settings.refspec; String refspecs = Strings.isNullOrEmpty(settings.refspec) ? DEFAULT_REFSPEC : settings.refspec;
for (String refspec : refspecs.split("\\s|\\n")) { for (String refspec : refspecs.split("\\s|\\n")) {
@ -218,7 +224,7 @@ public class MirrorRepositoryHook implements AsyncPostReceiveRepositoryHook, Rep
boolean ok = true; boolean ok = true;
logger.debug("MirrorRepositoryHook: validate started."); logger.debug("MirrorRepositoryHook: validate started.");
List<MirrorSettings> mirrorSettings = getMirrorSettings(settings, false, false); List<MirrorSettings> mirrorSettings = getMirrorSettings(settings, false, false, false);
for (MirrorSettings ms : mirrorSettings) { for (MirrorSettings ms : mirrorSettings) {
if (!validate(ms, settings, errors)) { if (!validate(ms, settings, errors)) {
@ -242,10 +248,10 @@ public class MirrorRepositoryHook implements AsyncPostReceiveRepositoryHook, Rep
} }
protected List<MirrorSettings> getMirrorSettings(Settings settings) { protected List<MirrorSettings> getMirrorSettings(Settings settings) {
return getMirrorSettings(settings, true, true); return getMirrorSettings(settings, true, true, true);
} }
protected List<MirrorSettings> getMirrorSettings(Settings settings, boolean defTags, boolean defNotes) { protected List<MirrorSettings> getMirrorSettings(Settings settings, boolean defTags, boolean defNotes, boolean defAtomic) {
List<MirrorSettings> results = new ArrayList<>(); List<MirrorSettings> results = new ArrayList<>();
Map<String, Object> allSettings = settings.asMap(); Map<String, Object> allSettings = settings.asMap();
@ -262,6 +268,7 @@ public class MirrorRepositoryHook implements AsyncPostReceiveRepositoryHook, Rep
ms.refspec = (settings.getString(SETTING_REFSPEC + suffix, "")); ms.refspec = (settings.getString(SETTING_REFSPEC + suffix, ""));
ms.tags = (settings.getBoolean(SETTING_TAGS + suffix, defTags)); ms.tags = (settings.getBoolean(SETTING_TAGS + suffix, defTags));
ms.notes = (settings.getBoolean(SETTING_NOTES + suffix, defNotes)); ms.notes = (settings.getBoolean(SETTING_NOTES + suffix, defNotes));
ms.atomic = (settings.getBoolean(SETTING_ATOMIC + suffix, defAtomic));
ms.suffix = String.valueOf(count++); ms.suffix = String.valueOf(count++);
results.add(ms); results.add(ms);
@ -336,6 +343,7 @@ public class MirrorRepositoryHook implements AsyncPostReceiveRepositoryHook, Rep
values.put(SETTING_REFSPEC + ms.suffix, ms.refspec); values.put(SETTING_REFSPEC + ms.suffix, ms.refspec);
values.put(SETTING_TAGS + ms.suffix, ms.tags); values.put(SETTING_TAGS + ms.suffix, ms.tags);
values.put(SETTING_NOTES + ms.suffix, ms.notes); values.put(SETTING_NOTES + ms.suffix, ms.notes);
values.put(SETTING_ATOMIC + ms.suffix, ms.atomic);
} }
// Unfortunately the settings are stored in an immutable map, so need to cheat with reflection // Unfortunately the settings are stored in an immutable map, so need to cheat with reflection

6
src/main/resources/i18n/stash-hook-mirror.properties

@ -14,6 +14,6 @@ mirror-repository-hook.password.description=The password to use for pushing to t
mirror-repository-hook.refspec.label=Refspecs mirror-repository-hook.refspec.label=Refspecs
mirror-repository-hook.refspec.description=The git refspec(s) to mirror (defaults to +refs/heads/*:refs/heads/*) mirror-repository-hook.refspec.description=The git refspec(s) to mirror (defaults to +refs/heads/*:refs/heads/*)
mirror-repository-hook.tags.label=Tags mirror-repository-hook.tags.label=Tags (ie. +refs/tags/*:refs/tags/*)
mirror-repository-hook.notes.label=Notes mirror-repository-hook.notes.label=Notes (ie. +refs/notes/*:refs/notes/*)
mirror-repository-hook.tags-notes.description=Whether to mirror tags and notes (ie. +refs/tags/*:refs/tags/* and +refs/notes/*:refs/notes/*) mirror-repository-hook.atomic.label=Atomic

6
src/main/resources/static/mirror-repository-hook.soy

@ -93,9 +93,13 @@
'id' : 'notes' + $index, 'id' : 'notes' + $index,
'labelText': getText('mirror-repository-hook.notes.label'), 'labelText': getText('mirror-repository-hook.notes.label'),
'isChecked' : $config['notes' + $index] != false 'isChecked' : $config['notes' + $index] != false
],
[
'id' : 'atomic' + $index,
'labelText': getText('mirror-repository-hook.atomic.label'),
'isChecked' : $config['atomic' + $index] != false
] ]
] /} ] /}
{param descriptionText: getText('mirror-repository-hook.tags-notes.description') /}
{/call} {/call}
</fieldset> </fieldset>

1
src/test/java/com/englishtown/bitbucket/hook/MirrorRepositoryHookTest.java

@ -289,6 +289,7 @@ public class MirrorRepositoryHookTest {
when(settings.getString(eq(MirrorRepositoryHook.SETTING_REFSPEC), eq(""))).thenReturn(refspec); when(settings.getString(eq(MirrorRepositoryHook.SETTING_REFSPEC), eq(""))).thenReturn(refspec);
when(settings.getBoolean(eq(MirrorRepositoryHook.SETTING_TAGS), eq(true))).thenReturn(true); when(settings.getBoolean(eq(MirrorRepositoryHook.SETTING_TAGS), eq(true))).thenReturn(true);
when(settings.getBoolean(eq(MirrorRepositoryHook.SETTING_NOTES), eq(true))).thenReturn(true); when(settings.getBoolean(eq(MirrorRepositoryHook.SETTING_NOTES), eq(true))).thenReturn(true);
when(settings.getBoolean(eq(MirrorRepositoryHook.SETTING_ATOMIC), eq(true))).thenReturn(true);
return settings; return settings;
} }
} }

Loading…
Cancel
Save