Skip to content

Commit 936b074

Browse files
committed
check git repository path exists
1 parent 2cc4773 commit 936b074

File tree

1 file changed

+5
-16
lines changed

1 file changed

+5
-16
lines changed

git-as-svn/src/main/java/svnserver/repository/git/GitRepository.java

+5-16
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import svnserver.repository.VcsRepository;
2222

2323
import java.io.File;
24+
import java.io.FileNotFoundException;
2425
import java.io.IOException;
2526
import java.io.InputStream;
2627
import java.nio.charset.StandardCharsets;
@@ -60,8 +61,11 @@ public class GitRepository implements VcsRepository {
6061
private final Map<String, String> cacheMd5 = new ConcurrentHashMap<>();
6162

6263
public GitRepository(@NotNull RepositoryConfig config) throws IOException, SVNException {
63-
this.repository = new FileRepository(new File(config.getPath()).getAbsolutePath());
64+
this.repository = new FileRepository(new File(config.getPath()).getAbsoluteFile());
6465
log.info("Repository path: {}", repository.getDirectory());
66+
if (!repository.getDirectory().exists()) {
67+
throw new FileNotFoundException(repository.getDirectory().getPath());
68+
}
6569
final Ref branchRef = repository.getRef(config.getBranch());
6670
if (branchRef == null) {
6771
throw new IOException("Branch not found: " + config.getBranch());
@@ -144,21 +148,6 @@ private void collectChanges(@NotNull Map<String, GitLogEntry> changes, @NotNull
144148
}
145149
}
146150

147-
private File findGitPath() {
148-
final File root = new File(".").getAbsoluteFile();
149-
File path = root;
150-
while (true) {
151-
final File repo = new File(path, ".git");
152-
if (repo.exists()) {
153-
return repo;
154-
}
155-
path = path.getParentFile();
156-
if (path == null) {
157-
throw new IllegalStateException("Repository not found from directiry: " + root.getAbsolutePath());
158-
}
159-
}
160-
}
161-
162151
@Override
163152
public int getLatestRevision() throws IOException {
164153
lock.readLock().lock();

0 commit comments

Comments
 (0)