From c6584e7a7455090ae224633cae8c6d5d080d6a3a Mon Sep 17 00:00:00 2001 From: Derek Smart Date: Fri, 13 Dec 2024 15:34:39 -0500 Subject: [PATCH] set fetch depth --- .../org/liquibase/ext/resource/git/GitConfiguration.java | 5 +++++ .../java/org/liquibase/ext/resource/git/GitPathHandler.java | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/liquibase/ext/resource/git/GitConfiguration.java b/src/main/java/org/liquibase/ext/resource/git/GitConfiguration.java index ff310c9..4e3aea3 100644 --- a/src/main/java/org/liquibase/ext/resource/git/GitConfiguration.java +++ b/src/main/java/org/liquibase/ext/resource/git/GitConfiguration.java @@ -11,6 +11,7 @@ public class GitConfiguration implements AutoloadedConfigurations { public static final ConfigurationDefinition GIT_PATH; public static final ConfigurationDefinition GIT_BRANCH; public static final ConfigurationDefinition GIT_CLEANUP; + public static final ConfigurationDefinition GIT_FETCH_DEPTH; static { ConfigurationDefinition.Builder builder = new ConfigurationDefinition.Builder("liquibase.git"); @@ -37,6 +38,10 @@ public class GitConfiguration implements AutoloadedConfigurations { .setDescription("Remove local repository path after run") .setDefaultValue(true) .build(); + GIT_FETCH_DEPTH = builder.define("fetch_depth", Integer.class) + .addAliasKey("git.fetch_depth") + .setDescription("Creates a shallow clone with a history truncated to the specified number of commits") + .build(); } diff --git a/src/main/java/org/liquibase/ext/resource/git/GitPathHandler.java b/src/main/java/org/liquibase/ext/resource/git/GitPathHandler.java index d54ded3..22b2d20 100644 --- a/src/main/java/org/liquibase/ext/resource/git/GitPathHandler.java +++ b/src/main/java/org/liquibase/ext/resource/git/GitPathHandler.java @@ -108,7 +108,8 @@ private boolean hasGitCredentials(String username, String password) throws IOExc private CloneCommand getCloneCommand(String root, File path, String branch) throws IOException { String username = GitConfiguration.GIT_USERNAME.getCurrentValue(); String password = GitConfiguration.GIT_PASSWORD.getCurrentValue(); - + Integer depth = GitConfiguration.GIT_FETCH_DEPTH.getCurrentValue(); + CloneCommand cloneCommand = Git.cloneRepository().setURI(root); cloneCommand.setDirectory(path); if (this.hasGitCredentials(username, password)) { @@ -117,6 +118,9 @@ private CloneCommand getCloneCommand(String root, File path, String branch) thro if (branch != null && !branch.equals("")) { cloneCommand.setBranch(branch); } + if (depth != null && depth > 0) { + cloneCommand.setDepth(depth); + } return cloneCommand; }