summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
authorIvan Frade <ifrade@google.com>2018-10-30 11:51:49 -0700
committerIvan Frade <ifrade@google.com>2018-10-31 16:40:06 -0700
commitf648a3bd8133a1fe0668a6f969e293a24e85c88d (patch)
tree15590d4503e6bfce5aad99669b9eda251d26cccf /org.eclipse.jgit.test
parent17dbaa4fdd06524da18c37299842832c5d00e24b (diff)
downloadjgit-f648a3bd8133a1fe0668a6f969e293a24e85c88d.tar.gz
jgit-f648a3bd8133a1fe0668a6f969e293a24e85c88d.zip
RepoCommand.RemoteReader: Add method to read contents and mode of file
The RepoCommand.RemoteReader interface doesn't offer access to the mode of a file. Caller can only default to mark the copied objects as regular files, losing e.g. the executable bit (if set). Add a new method readFileWithMode that returns the contents and mode of the remote file. It supersedes the readFile method, that is marked as deprecated. Now callers can set correctly the file mode of the copied file. Change-Id: I8fce01e4bc5707434c0cbc4aebbae1b6b64756f0 Signed-off-by: Ivan Frade <ifrade@google.com>
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java31
1 files changed, 19 insertions, 12 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java
index 022f6433d2..c170ac1b35 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java
@@ -56,13 +56,16 @@ import java.io.IOException;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
+import java.text.MessageFormat;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException;
+import org.eclipse.jgit.api.errors.InvalidRefNameException;
import org.eclipse.jgit.api.errors.InvalidRemoteException;
-import org.eclipse.jgit.api.errors.RefNotFoundException;
+import org.eclipse.jgit.gitrepo.RepoCommand.RemoteFile;
+import org.eclipse.jgit.internal.JGitText;
import org.eclipse.jgit.junit.JGitTestUtil;
import org.eclipse.jgit.junit.RepositoryTestCase;
import org.eclipse.jgit.lib.BlobBasedConfig;
@@ -74,6 +77,7 @@ import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.storage.file.FileBasedConfig;
+import org.eclipse.jgit.treewalk.TreeWalk;
import org.eclipse.jgit.util.FS;
import org.junit.Test;
@@ -142,6 +146,7 @@ public class RepoCommandTest extends RepositoryTestCase {
static class IndexedRepos implements RepoCommand.RemoteReader {
Map<String, Repository> uriRepoMap;
+
IndexedRepos() {
uriRepoMap = new HashMap<>();
}
@@ -170,19 +175,21 @@ public class RepoCommandTest extends RepositoryTestCase {
}
@Override
- public byte[] readFile(String uri, String refName, String path)
- throws GitAPIException, IOException {
+ public RemoteFile readFileWithMode(String uri, String ref, String path)
+ throws GitAPIException, IOException {
Repository repo = uriRepoMap.get(uri);
-
- String idStr = refName + ":" + path;
- ObjectId id = repo.resolve(idStr);
- if (id == null) {
- throw new RefNotFoundException(
- String.format("repo %s does not have %s", repo.toString(), idStr));
- }
- try (ObjectReader reader = repo.newObjectReader()) {
- return reader.open(id).getCachedBytes(Integer.MAX_VALUE);
+ ObjectId refCommitId = sha1(uri, ref);
+ if (refCommitId == null) {
+ throw new InvalidRefNameException(MessageFormat
+ .format(JGitText.get().refNotResolved, ref));
}
+ RevCommit commit = repo.parseCommit(refCommitId);
+ TreeWalk tw = TreeWalk.forPath(repo, path, commit.getTree());
+
+ // TODO(ifrade): Cope better with big files (e.g. using InputStream
+ // instead of byte[])
+ return new RemoteFile(tw.getObjectReader().open(tw.getObjectId(0))
+ .getCachedBytes(Integer.MAX_VALUE), tw.getFileMode(0));
}
}