Skip to content

Commit 6ce6c76

Browse files
committed
Support Git when .git dir is up in the file system
1 parent a147003 commit 6ce6c76

File tree

1 file changed

+6
-8
lines changed
  • components/sbm-core/src/main/java/org/springframework/sbm/engine/git

1 file changed

+6
-8
lines changed

components/sbm-core/src/main/java/org/springframework/sbm/engine/git/GitSupport.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,10 @@ public Optional<Commit> getLatestCommit(File repo) {
128128
*
129129
* @param repo the location of the repo to search for. {@code .git} is added to file location if not contained
130130
*/
131-
public Repository getRepository(File repo) {
131+
public static Repository findRepository(File repo) {
132132
try {
133-
FileRepositoryBuilder builder = new FileRepositoryBuilder();
134-
if (!repo.toString().endsWith(".git")) {
135-
repo = repo.toPath().resolve(".git").toFile();
136-
}
137-
return builder
138-
.setGitDir(repo)
133+
return new FileRepositoryBuilder()
134+
.findGitDir(repo)
139135
.setMustExist(true)
140136
.build();
141137
} catch (IOException e) {
@@ -150,6 +146,8 @@ public Repository getRepository(File repo) {
150146
*/
151147
public static Git initGit(File repo) {
152148
try {
149+
Repository repository = findRepository(repo);
150+
repo = repository.getDirectory();
153151
if(repo.toPath().toString().endsWith(".git")) {
154152
repo = repo.toPath().getParent().toAbsolutePath().normalize().toFile();
155153
}
@@ -225,7 +223,7 @@ public Commit addAllAndCommit(File repo, String commitMessage, List<String> modi
225223
public boolean repoExists(File repoDir) {
226224
if (repoDir == null) return false;
227225
try {
228-
getRepository(repoDir);
226+
findRepository(repoDir);
229227
return true;
230228
} catch (RepositoryNotFoundException e) {
231229
return false;

0 commit comments

Comments
 (0)