Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/github_actions/liquibase/build-lo…
Browse files Browse the repository at this point in the history
…gic-0.7.8
  • Loading branch information
jandroav authored Jun 10, 2024
2 parents 0011150 + 6be7040 commit 8d6dcb8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import liquibase.configuration.AutoloadedConfigurations;
import liquibase.configuration.ConfigurationDefinition;
import liquibase.configuration.ConfigurationValueObfuscator;

public class GitConfiguration implements AutoloadedConfigurations {

Expand All @@ -20,6 +21,7 @@ public class GitConfiguration implements AutoloadedConfigurations {
GIT_PASSWORD = builder.define("password", String.class)
.addAliasKey("git.password")
.setDescription("Git password for searchPath repository URL")
.setValueObfuscator(ConfigurationValueObfuscator.STANDARD)
.build();
GIT_PATH = builder.define("path", String.class)
.addAliasKey("git.path")
Expand Down
23 changes: 8 additions & 15 deletions src/main/java/org/liquibase/ext/resource/git/GitPathHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,30 +52,23 @@ public ResourceAccessor getResourceAccessor(String root) throws IOException {
if (!path.exists()) {
path.mkdirs();
}
Repository repository = null;
try {
RepositoryBuilder repositoryBuilder = new RepositoryBuilder().setGitDir(gitPath);
repository = repositoryBuilder.build();
try (Repository repository = new RepositoryBuilder().setGitDir(gitPath).build()) {
if (repository.getObjectDatabase().exists()) {
Git git = Git.open(path);
if (branch != null && !branch.isEmpty()) {
git.checkout().setName(branch).call();
} else {
git.pull().call();
try (Git git = Git.open(path)) {
if (branch != null && !branch.isEmpty()) {
git.checkout().setName(branch).call();
} else {
git.pull().call();
}
Scope.getCurrentScope().getLog(GitPathHandler.class).fine("Repository updated: " + path);
}
Scope.getCurrentScope().getLog(GitPathHandler.class).fine("Repository updated: " + path);
} else {
CloneCommand cloneCommand = this.getCloneCommand(root, path, branch);
cloneCommand.call();
Scope.getCurrentScope().getLog(GitPathHandler.class).fine("Repository cloned: " + path);
}
} catch (GitAPIException | JGitInternalException e) {
throw new IOException(e.getMessage());
} finally {
if (repository != null) {
repository.close();
}
Git.shutdown();
}
Scope.getCurrentScope().getLog(GitPathHandler.class).fine("Return DirectoryResourceAccessor for root path " + path);
return new DirectoryResourceAccessor(path);
Expand Down

0 comments on commit 8d6dcb8

Please sign in to comment.