Skip to content

Commit

Permalink
Merge pull request #56 from liquibase/feature/fetch-depth
Browse files Browse the repository at this point in the history
set fetch depth
  • Loading branch information
mcred authored Dec 13, 2024
2 parents 822e35e + c6584e7 commit f4264f2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class GitConfiguration implements AutoloadedConfigurations {
public static final ConfigurationDefinition<String> GIT_PATH;
public static final ConfigurationDefinition<String> GIT_BRANCH;
public static final ConfigurationDefinition<Boolean> GIT_CLEANUP;
public static final ConfigurationDefinition<Integer> GIT_FETCH_DEPTH;

static {
ConfigurationDefinition.Builder builder = new ConfigurationDefinition.Builder("liquibase.git");
Expand All @@ -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();
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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;
}
Expand Down

0 comments on commit f4264f2

Please sign in to comment.