diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/api/v2/resources/GitConfigDto.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/api/v2/resources/GitConfigDto.java index 640fadc8e8..a6cd437856 100644 --- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/api/v2/resources/GitConfigDto.java +++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/api/v2/resources/GitConfigDto.java @@ -41,6 +41,8 @@ public class GitConfigDto extends HalRepresentation { private boolean nonFastForwardDisallowed; + private String defaultBranch; + @Override @SuppressWarnings("squid:S1185") // We want to have this method available in this package protected HalRepresentation add(Links links) { diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/GitConfig.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/GitConfig.java index facdcccbbf..f699093f73 100644 --- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/GitConfig.java +++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/GitConfig.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ - + package sonia.scm.repository; //~--- JDK imports ------------------------------------------------------------ @@ -33,7 +33,6 @@ import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlTransient; /** - * * @author Sebastian Sdorra */ @XmlRootElement(name = "config") @@ -49,6 +48,9 @@ public class GitConfig extends RepositoryConfig { @XmlElement(name = "disallow-non-fast-forward") private boolean nonFastForwardDisallowed; + @XmlElement(name = "default-branch") + private String defaultBranch = "main"; + public String getGcExpression() { return gcExpression; } @@ -65,6 +67,14 @@ public class GitConfig extends RepositoryConfig { this.nonFastForwardDisallowed = nonFastForwardDisallowed; } + public String getDefaultBranch() { + return defaultBranch; + } + + public void setDefaultBranch(String defaultBranch) { + this.defaultBranch = defaultBranch; + } + @Override @XmlTransient // Only for permission checks, don't serialize to XML public String getId() { diff --git a/scm-plugins/scm-git-plugin/src/main/js/GitConfigurationForm.tsx b/scm-plugins/scm-git-plugin/src/main/js/GitConfigurationForm.tsx index 036c7f3f40..102141cc18 100644 --- a/scm-plugins/scm-git-plugin/src/main/js/GitConfigurationForm.tsx +++ b/scm-plugins/scm-git-plugin/src/main/js/GitConfigurationForm.tsx @@ -24,12 +24,13 @@ import React from "react"; import { WithTranslation, withTranslation } from "react-i18next"; import { Links } from "@scm-manager/ui-types"; -import { InputField, Checkbox } from "@scm-manager/ui-components"; +import { InputField, Checkbox, validation as validator } from "@scm-manager/ui-components"; type Configuration = { repositoryDirectory?: string; gcExpression?: string; nonFastForwardDisallowed: boolean; + defaultBranch: string; _links: Links; }; @@ -68,8 +69,21 @@ class GitConfigurationForm extends React.Component { ); }; + onDefaultBranchChange = (value: string) => { + this.setState( + { + defaultBranch: value + }, + () => this.props.onConfigurationChange(this.state, this.isValidDefaultBranch()) + ); + }; + + isValidDefaultBranch = () => { + return validator.isNameValid(this.state.defaultBranch); + }; + render() { - const { gcExpression, nonFastForwardDisallowed } = this.state; + const { gcExpression, nonFastForwardDisallowed, defaultBranch } = this.state; const { readOnly, t } = this.props; return ( @@ -90,6 +104,15 @@ class GitConfigurationForm extends React.Component { onChange={this.onNonFastForwardDisallowed} disabled={readOnly} /> + ); } diff --git a/scm-plugins/scm-git-plugin/src/main/resources/locales/de/plugins.json b/scm-plugins/scm-git-plugin/src/main/resources/locales/de/plugins.json index 7553856e57..5d167d548f 100644 --- a/scm-plugins/scm-git-plugin/src/main/resources/locales/de/plugins.json +++ b/scm-plugins/scm-git-plugin/src/main/resources/locales/de/plugins.json @@ -24,6 +24,8 @@ "gcExpressionHelpText": "Benutze Quartz Cron Ausdrücke (SECOND MINUTE HOUR DAYOFMONTH MONTH DAYOFWEEK), um git GC regelmäßig auszuführen.", "nonFastForwardDisallowed": "Deaktiviere \"Non Fast-Forward\"", "nonFastForwardDisallowedHelpText": "Git Pushes ablehnen, die nicht \"fast-forward\" sind, wie \"--force\".", + "defaultBranch": "Default Branch", + "defaultBranchValidationError": "Dies ist kein valider Branchname", "disabled": "Deaktiviert", "disabledHelpText": "Aktiviere oder deaktiviere das Git Plugin", "submit": "Speichern" diff --git a/scm-plugins/scm-git-plugin/src/main/resources/locales/en/plugins.json b/scm-plugins/scm-git-plugin/src/main/resources/locales/en/plugins.json index 23ab1ffce0..1368fed7d9 100644 --- a/scm-plugins/scm-git-plugin/src/main/resources/locales/en/plugins.json +++ b/scm-plugins/scm-git-plugin/src/main/resources/locales/en/plugins.json @@ -24,6 +24,8 @@ "gcExpressionHelpText": "Use Quartz Cron Expressions (SECOND MINUTE HOUR DAYOFMONTH MONTH DAYOFWEEK) to run git gc in intervals.", "nonFastForwardDisallowed": "Disallow Non Fast-Forward", "nonFastForwardDisallowedHelpText": "Reject git pushes which are non fast-forward such as --force.", + "defaultBranch": "Default Branch", + "defaultBranchValidationError": "This is not a valid branch name", "disabled": "Disabled", "disabledHelpText": "Enable or disable the Git plugin", "submit": "Submit"