|
|
@ -39,6 +39,8 @@ public class MirrorRepositoryHook implements AsyncPostReceiveRepositoryHook, Rep |
|
|
|
boolean tags; |
|
|
|
boolean tags; |
|
|
|
boolean notes; |
|
|
|
boolean notes; |
|
|
|
boolean atomic; |
|
|
|
boolean atomic; |
|
|
|
|
|
|
|
boolean prune; |
|
|
|
|
|
|
|
boolean force; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static final String PLUGIN_SETTINGS_KEY = "com.englishtown.stash.hook.mirror"; |
|
|
|
public static final String PLUGIN_SETTINGS_KEY = "com.englishtown.stash.hook.mirror"; |
|
|
@ -49,6 +51,8 @@ public class MirrorRepositoryHook implements AsyncPostReceiveRepositoryHook, Rep |
|
|
|
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 String SETTING_ATOMIC = "atomic"; |
|
|
|
|
|
|
|
static final String SETTING_PRUNE = "prune"; |
|
|
|
|
|
|
|
static final String SETTING_FORCE = "force"; |
|
|
|
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/*"; |
|
|
|
|
|
|
|
|
|
|
@ -137,18 +141,26 @@ public class MirrorRepositoryHook implements AsyncPostReceiveRepositoryHook, Rep |
|
|
|
GitScmCommandBuilder builder = (GitScmCommandBuilder) obj; |
|
|
|
GitScmCommandBuilder builder = (GitScmCommandBuilder) obj; |
|
|
|
PasswordHandler passwordHandler = getPasswordHandler(builder, password); |
|
|
|
PasswordHandler passwordHandler = getPasswordHandler(builder, password); |
|
|
|
|
|
|
|
|
|
|
|
// Call push command with the prune flag and refspecs for heads and tags
|
|
|
|
// Call push command with the refspecs for heads and tags
|
|
|
|
// 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(authenticatedUrl) |
|
|
|
// this deletes locally deleted branches
|
|
|
|
.argument("--force"); |
|
|
|
if (settings.prune) { |
|
|
|
|
|
|
|
builder.argument("--prune"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Use an atomic transaction to have a consistent state
|
|
|
|
// Use an atomic transaction to have a consistent state
|
|
|
|
if (settings.atomic) { |
|
|
|
if (settings.atomic) { |
|
|
|
builder.argument("--atomic"); |
|
|
|
builder.argument("--atomic"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
builder.argument(authenticatedUrl); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (settings.force) { |
|
|
|
|
|
|
|
builder.argument("--force"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 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")) { |
|
|
@ -224,7 +236,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, false); |
|
|
|
List<MirrorSettings> mirrorSettings = getMirrorSettings(settings, false, false, false, false, false); |
|
|
|
|
|
|
|
|
|
|
|
for (MirrorSettings ms : mirrorSettings) { |
|
|
|
for (MirrorSettings ms : mirrorSettings) { |
|
|
|
if (!validate(ms, settings, errors)) { |
|
|
|
if (!validate(ms, settings, errors)) { |
|
|
@ -248,10 +260,10 @@ public class MirrorRepositoryHook implements AsyncPostReceiveRepositoryHook, Rep |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected List<MirrorSettings> getMirrorSettings(Settings settings) { |
|
|
|
protected List<MirrorSettings> getMirrorSettings(Settings settings) { |
|
|
|
return getMirrorSettings(settings, true, true, true); |
|
|
|
return getMirrorSettings(settings, true, true, true, true, true); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected List<MirrorSettings> getMirrorSettings(Settings settings, boolean defTags, boolean defNotes, boolean defAtomic) { |
|
|
|
protected List<MirrorSettings> getMirrorSettings(Settings settings, boolean defTags, boolean defNotes, boolean defAtomic, boolean defPrune, boolean defForce) { |
|
|
|
|
|
|
|
|
|
|
|
List<MirrorSettings> results = new ArrayList<>(); |
|
|
|
List<MirrorSettings> results = new ArrayList<>(); |
|
|
|
Map<String, Object> allSettings = settings.asMap(); |
|
|
|
Map<String, Object> allSettings = settings.asMap(); |
|
|
@ -269,6 +281,8 @@ public class MirrorRepositoryHook implements AsyncPostReceiveRepositoryHook, Rep |
|
|
|
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.atomic = (settings.getBoolean(SETTING_ATOMIC + suffix, defAtomic)); |
|
|
|
|
|
|
|
ms.prune = (settings.getBoolean(SETTING_PRUNE + suffix, defPrune)); |
|
|
|
|
|
|
|
ms.force = (settings.getBoolean(SETTING_FORCE + suffix, defForce)); |
|
|
|
ms.suffix = String.valueOf(count++); |
|
|
|
ms.suffix = String.valueOf(count++); |
|
|
|
|
|
|
|
|
|
|
|
results.add(ms); |
|
|
|
results.add(ms); |
|
|
@ -344,6 +358,8 @@ public class MirrorRepositoryHook implements AsyncPostReceiveRepositoryHook, Rep |
|
|
|
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); |
|
|
|
values.put(SETTING_ATOMIC + ms.suffix, ms.atomic); |
|
|
|
|
|
|
|
values.put(SETTING_PRUNE + ms.suffix, ms.prune); |
|
|
|
|
|
|
|
values.put(SETTING_FORCE + ms.suffix, ms.force); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|