Skip to content

Commit ac81c94

Browse files
committed
getFileContent() on a certain revision: reset added
1 parent 7662cba commit ac81c94

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/main/java/org/scm4j/vcs/GitVCS.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ public String getFileContent(String branchName, String fileRelativePath, String
285285
Git git = getLocalGit(wc);
286286
Repository gitRepo = git.getRepository();
287287
RevWalk revWalk = new RevWalk(gitRepo);
288-
TreeWalk treeWalk = new TreeWalk(gitRepo);) {
288+
TreeWalk treeWalk = new TreeWalk(gitRepo)) {
289289

290290
git
291291
.fetch()
@@ -314,8 +314,14 @@ public String getFileContent(String branchName, String fileRelativePath, String
314314

315315
ObjectLoader loader = gitRepo.open(objectId);
316316
InputStream in = loader.openStream();
317-
return IOUtils.toString(in, StandardCharsets.UTF_8);
318-
317+
String res = IOUtils.toString(in, StandardCharsets.UTF_8);
318+
if (revision != null) {
319+
git
320+
.reset()
321+
.setMode(ResetType.HARD)
322+
.call();
323+
}
324+
return res;
319325
} catch(EVCSFileNotFound | EVCSBranchNotFound e) {
320326
throw e;
321327
} catch (GitAPIException e) {

0 commit comments

Comments
 (0)