summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/META-INF/MANIFEST.MF92
-rw-r--r--org.eclipse.jgit.test/exttst/org/eclipse/jgit/ignore/CGitVsJGitRandomIgnorePatternTest.java6
-rw-r--r--org.eclipse.jgit.test/exttst/org/eclipse/jgit/patch/EGitPatchHistoryTest.java12
-rw-r--r--org.eclipse.jgit.test/exttst/org/eclipse/jgit/treewalk/FileTreeIteratorPerformanceTest.java93
-rw-r--r--org.eclipse.jgit.test/pom.xml6
-rw-r--r--org.eclipse.jgit.test/tests.bzl5
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ApplyCommandTest.java6
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ArchiveCommandTest.java5
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BlameCommandTest.java2
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BranchCommandTest.java12
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CherryPickCommandTest.java2
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitCommandTest.java6
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitOnlyTest.java2
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/DescribeCommandTest.java181
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/EolStreamTypeUtilTest.java10
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/FetchCommandTest.java63
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/LogCommandTest.java2
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java74
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/NotesCommandTest.java4
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandTest.java6
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandWithRebaseTest.java6
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PushCommandTest.java2
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java8
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ResetCommandTest.java54
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RevertCommandTest.java2
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StashCreateCommandTest.java8
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/TagCommandTest.java26
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/AbstractDiffTestCase.java4
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffFormatterReflowTest.java8
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RawTextTest.java35
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/SimilarityIndexTest.java8
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBuilderIteratorTest.java2
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheCGitCompatabilityTest.java16
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheEntryTest.java2
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheIteratorTest.java14
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheLargePathTest.java4
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/ManifestParserTest.java6
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandSymlinkTest.java70
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java772
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/CGitIgnoreTest.java4
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/IgnoreNodeTest.java22
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/indexdiff/IndexDiffWithSymlinkTest.java4
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ConcurrentRepackTest.java18
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackFileTest.java81
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackWriterTest.java29
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefDirectoryTest.java6
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefUpdateTest.java61
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/T0003_BasicTest.java101
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/UnpackedObjectTest.java130
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/WindowCacheGetTest.java13
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/XInputStream.java4
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/reftree/RefTreeDatabaseTest.java4
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/junit/TestRepositoryTest.java4
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/BranchConfigTest.java2
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java4
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutTest.java113
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffTest.java5
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectCheckerTest.java14
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RacyGitTests.java5
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefTest.java33
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryCacheTest.java35
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryResolveTest.java2
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/SquashCommitMsgTest.java7
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ValidRefNameTest.java4
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/CherryPickTest.java2
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/CrissCrossMergeTest.java (renamed from org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/RecursiveMergerTest.java)4
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergerTest.java (renamed from org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/ResolveMergerTest.java)52
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/SimpleMergeTest.java2
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/EditListTest.java2
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/FileHeaderTest.java12
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/GetTextTest.java8
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchCcErrorTest.java13
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchCcTest.java13
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchErrorTest.java13
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchTest.java13
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/FooterLineTest.java2
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevCommitParseTest.java106
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevObjectTest.java2
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevTagParseTest.java108
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkFollowFilterTest.java2
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkPathFilter1Test.java2
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkPathFilter6012Test.java8
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkTestCase.java26
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkUtilsReachableTest.java2
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/FileBasedConfigTest.java8
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleAddTest.java35
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleSyncTest.java28
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleUpdateTest.java8
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BundleWriterTest.java4
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/NetRCTest.java11
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/OpenSshConfigTest.java5
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PackParserTest.java10
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PacketLineInTest.java20
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PacketLineOutTest.java8
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushConnectionTest.java60
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushProcessTest.java4
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ReceivePackAdvertiseRefsHookTest.java38
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/RemoteConfigTest.java4
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/SideBandOutputStreamTest.java2
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/TransportTest.java6
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java914
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/WalkEncryptionTest.java67
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/CanonicalTreeParserTest.java4
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorTest.java2
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorWithTimeControl.java2
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/PostOrderTreeWalkTest.java14
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/AlwaysCloneTreeFilter.java2
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/NotTreeFilterTest.java13
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/PathFilterGroupTest.java4
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/PathSuffixFilterTest.java2
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/TreeFilterTest.java6
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/util/ChangeIdUtilTest.java6
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/util/HookTest.java2
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/util/NBTest.java8
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/util/QuotedStringBourneStyleTest.java4
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/util/QuotedStringBourneUserPathStyleTest.java4
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/util/QuotedStringGitPathStyleTest.java4
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawParseUtils_HexParseTest.java2
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawParseUtils_LineMapTest.java18
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawSubStringPatternTest.java4
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RefListTest.java2
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/util/TemporaryBufferTest.java68
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoCRLFOutputStreamTest.java47
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoLFInputStreamTest.java57
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/UnionInputStreamTest.java48
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/util/sha1/SHA1Test.java14
126 files changed, 2846 insertions, 1456 deletions
diff --git a/org.eclipse.jgit.test/META-INF/MANIFEST.MF b/org.eclipse.jgit.test/META-INF/MANIFEST.MF
index 49f5cc0008..890215e01c 100644
--- a/org.eclipse.jgit.test/META-INF/MANIFEST.MF
+++ b/org.eclipse.jgit.test/META-INF/MANIFEST.MF
@@ -3,58 +3,58 @@ Bundle-ManifestVersion: 2
Bundle-Name: %plugin_name
Automatic-Module-Name: org.eclipse.jgit.test
Bundle-SymbolicName: org.eclipse.jgit.test
-Bundle-Version: 4.11.1.qualifier
+Bundle-Version: 5.0.2.qualifier
Bundle-Localization: plugin
Bundle-Vendor: %provider_name
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Import-Package: com.googlecode.javaewah;version="[1.1.6,2.0.0)",
com.jcraft.jsch;version="[0.1.54,0.2.0)",
- org.eclipse.jgit.api;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.api.errors;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.attributes;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.awtui;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.blame;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.diff;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.dircache;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.errors;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.events;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.fnmatch;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.gitrepo;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.hooks;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.ignore;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.ignore.internal;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.internal;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.internal.fsck;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.internal.storage.dfs;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.internal.storage.file;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.internal.storage.io;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.internal.storage.pack;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.internal.storage.reftable;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.internal.storage.reftree;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.junit;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.lfs;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.lib;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.merge;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.nls;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.notes;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.patch;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.pgm;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.pgm.internal;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.revplot;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.revwalk;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.revwalk.filter;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.storage.file;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.storage.pack;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.submodule;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.transport;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.transport.http;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.transport.resolver;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.treewalk;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.treewalk.filter;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.util;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.util.io;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.util.sha1;version="[4.11.1,4.12.0)",
+ org.eclipse.jgit.api;version="[5.0.2,5.1.0)",
+ org.eclipse.jgit.api.errors;version="[5.0.2,5.1.0)",
+ org.eclipse.jgit.attributes;version="[5.0.2,5.1.0)",
+ org.eclipse.jgit.awtui;version="[5.0.2,5.1.0)",
+ org.eclipse.jgit.blame;version="[5.0.2,5.1.0)",
+ org.eclipse.jgit.diff;version="[5.0.2,5.1.0)",
+ org.eclipse.jgit.dircache;version="[5.0.2,5.1.0)",
+ org.eclipse.jgit.errors;version="[5.0.2,5.1.0)",
+ org.eclipse.jgit.events;version="[5.0.2,5.1.0)",
+ org.eclipse.jgit.fnmatch;version="[5.0.2,5.1.0)",
+ org.eclipse.jgit.gitrepo;version="[5.0.2,5.1.0)",
+ org.eclipse.jgit.hooks;version="[5.0.2,5.1.0)",
+ org.eclipse.jgit.ignore;version="[5.0.2,5.1.0)",
+ org.eclipse.jgit.ignore.internal;version="[5.0.2,5.1.0)",
+ org.eclipse.jgit.internal;version="[5.0.2,5.1.0)",
+ org.eclipse.jgit.internal.fsck;version="[5.0.2,5.1.0)",
+ org.eclipse.jgit.internal.storage.dfs;version="[5.0.2,5.1.0)",
+ org.eclipse.jgit.internal.storage.file;version="[5.0.2,5.1.0)",
+ org.eclipse.jgit.internal.storage.io;version="[5.0.2,5.1.0)",
+ org.eclipse.jgit.internal.storage.pack;version="[5.0.2,5.1.0)",
+ org.eclipse.jgit.internal.storage.reftable;version="[5.0.2,5.1.0)",
+ org.eclipse.jgit.internal.storage.reftree;version="[5.0.2,5.1.0)",
+ org.eclipse.jgit.junit;version="[5.0.2,5.1.0)",
+ org.eclipse.jgit.lfs;version="[5.0.2,5.1.0)",
+ org.eclipse.jgit.lib;version="[5.0.2,5.1.0)",
+ org.eclipse.jgit.merge;version="[5.0.2,5.1.0)",
+ org.eclipse.jgit.nls;version="[5.0.2,5.1.0)",
+ org.eclipse.jgit.notes;version="[5.0.2,5.1.0)",
+ org.eclipse.jgit.patch;version="[5.0.2,5.1.0)",
+ org.eclipse.jgit.pgm;version="[5.0.2,5.1.0)",
+ org.eclipse.jgit.pgm.internal;version="[5.0.2,5.1.0)",
+ org.eclipse.jgit.revplot;version="[5.0.2,5.1.0)",
+ org.eclipse.jgit.revwalk;version="[5.0.2,5.1.0)",
+ org.eclipse.jgit.revwalk.filter;version="[5.0.2,5.1.0)",
+ org.eclipse.jgit.storage.file;version="[5.0.2,5.1.0)",
+ org.eclipse.jgit.storage.pack;version="[5.0.2,5.1.0)",
+ org.eclipse.jgit.submodule;version="[5.0.2,5.1.0)",
+ org.eclipse.jgit.transport;version="[5.0.2,5.1.0)",
+ org.eclipse.jgit.transport.http;version="[5.0.2,5.1.0)",
+ org.eclipse.jgit.transport.resolver;version="[5.0.2,5.1.0)",
+ org.eclipse.jgit.treewalk;version="[5.0.2,5.1.0)",
+ org.eclipse.jgit.treewalk.filter;version="[5.0.2,5.1.0)",
+ org.eclipse.jgit.util;version="[5.0.2,5.1.0)",
+ org.eclipse.jgit.util.io;version="[5.0.2,5.1.0)",
+ org.eclipse.jgit.util.sha1;version="[5.0.2,5.1.0)",
org.junit;version="[4.12,5.0.0)",
org.junit.experimental.theories;version="[4.12,5.0.0)",
org.junit.rules;version="[4.12,5.0.0)",
diff --git a/org.eclipse.jgit.test/exttst/org/eclipse/jgit/ignore/CGitVsJGitRandomIgnorePatternTest.java b/org.eclipse.jgit.test/exttst/org/eclipse/jgit/ignore/CGitVsJGitRandomIgnorePatternTest.java
index 438d2d625b..4d9e864227 100644
--- a/org.eclipse.jgit.test/exttst/org/eclipse/jgit/ignore/CGitVsJGitRandomIgnorePatternTest.java
+++ b/org.eclipse.jgit.test/exttst/org/eclipse/jgit/ignore/CGitVsJGitRandomIgnorePatternTest.java
@@ -42,7 +42,7 @@
*/
package org.eclipse.jgit.ignore;
-import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
import java.io.BufferedReader;
import java.io.File;
@@ -158,7 +158,7 @@ public class CGitVsJGitRandomIgnorePatternTest {
this.gitDir = gitDir;
this.pattern = pattern;
Files.write(FileUtils.toPath(new File(gitDir, ".gitignore")),
- (pattern + "\n").getBytes(UTF_8), StandardOpenOption.CREATE,
+ (pattern + "\n").getBytes(CHARSET), StandardOpenOption.CREATE,
StandardOpenOption.TRUNCATE_EXISTING,
StandardOpenOption.WRITE);
}
@@ -188,7 +188,7 @@ public class CGitVsJGitRandomIgnorePatternTest {
Process proc = Runtime.getRuntime().exec(command, new String[0],
gitDir);
try (OutputStream out = proc.getOutputStream()) {
- out.write((path + "\n").getBytes(UTF_8));
+ out.write((path + "\n").getBytes(CHARSET));
out.flush();
}
return proc;
diff --git a/org.eclipse.jgit.test/exttst/org/eclipse/jgit/patch/EGitPatchHistoryTest.java b/org.eclipse.jgit.test/exttst/org/eclipse/jgit/patch/EGitPatchHistoryTest.java
index 3f9ef12507..79d8d0e10b 100644
--- a/org.eclipse.jgit.test/exttst/org/eclipse/jgit/patch/EGitPatchHistoryTest.java
+++ b/org.eclipse.jgit.test/exttst/org/eclipse/jgit/patch/EGitPatchHistoryTest.java
@@ -85,7 +85,7 @@ public class EGitPatchHistoryTest {
int errors;
- PatchReader(final HashMap<String, HashMap<String, StatInfo>> s)
+ PatchReader(HashMap<String, HashMap<String, StatInfo>> s)
throws IOException {
super(new String[] { "-p" });
stats = s;
@@ -103,7 +103,7 @@ public class EGitPatchHistoryTest {
p.parse(buf, 0, buf.length - 1);
assertEquals("File count " + cid, files.size(), p.getFiles().size());
if (!p.getErrors().isEmpty()) {
- for (final FormatError e : p.getErrors()) {
+ for (FormatError e : p.getErrors()) {
System.out.println("error " + e.getMessage());
System.out.println(" at " + e.getLineText());
}
@@ -111,7 +111,7 @@ public class EGitPatchHistoryTest {
fail("Unexpected error in " + cid);
}
- for (final FileHeader fh : p.getFiles()) {
+ for (FileHeader fh : p.getFiles()) {
final String fileName;
if (fh.getChangeType() != FileHeader.ChangeType.DELETE)
fileName = fh.getNewPath();
@@ -121,7 +121,7 @@ public class EGitPatchHistoryTest {
final String nid = fileName + " in " + cid;
assertNotNull("No " + nid, s);
int added = 0, deleted = 0;
- for (final HunkHeader h : fh.getHunks()) {
+ for (HunkHeader h : fh.getHunks()) {
added += h.getOldImage().getLinesAdded();
deleted += h.getOldImage().getLinesDeleted();
}
@@ -147,7 +147,7 @@ public class EGitPatchHistoryTest {
assertTrue("Missed files in " + cid, files.isEmpty());
}
- private static void dump(final byte[] buf) {
+ private static void dump(byte[] buf) {
String str;
try {
str = new String(buf, 0, buf.length - 1, "ISO-8859-1");
@@ -188,7 +188,7 @@ public class EGitPatchHistoryTest {
static abstract class CommitReader {
private Process proc;
- CommitReader(final String[] args) throws IOException {
+ CommitReader(String[] args) throws IOException {
final String[] realArgs = new String[3 + args.length + 1];
realArgs[0] = "git";
realArgs[1] = "log";
diff --git a/org.eclipse.jgit.test/exttst/org/eclipse/jgit/treewalk/FileTreeIteratorPerformanceTest.java b/org.eclipse.jgit.test/exttst/org/eclipse/jgit/treewalk/FileTreeIteratorPerformanceTest.java
new file mode 100644
index 0000000000..b238389847
--- /dev/null
+++ b/org.eclipse.jgit.test/exttst/org/eclipse/jgit/treewalk/FileTreeIteratorPerformanceTest.java
@@ -0,0 +1,93 @@
+/*
+ * Copyright (C) 2018, Thomas Wolf <thomas.wolf@paranor.ch>
+ * and other copyright owners as documented in the project's IP log.
+ *
+ * This program and the accompanying materials are made available
+ * under the terms of the Eclipse Distribution License v1.0 which
+ * accompanies this distribution, is reproduced below, and is
+ * available at http://www.eclipse.org/org/documents/edl-v10.php
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * - Neither the name of the Eclipse Foundation, Inc. nor the
+ * names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.eclipse.jgit.treewalk;
+
+import static org.junit.Assert.fail;
+
+import org.eclipse.jgit.api.Git;
+import org.eclipse.jgit.junit.RepositoryTestCase;
+import org.eclipse.jgit.treewalk.filter.PathFilter;
+import org.junit.Test;
+
+/**
+ * Simple performance test for git add / FileTreeIterator.
+ */
+public class FileTreeIteratorPerformanceTest extends RepositoryTestCase {
+
+ private static int N_OF_FILES = 501;
+
+ @Test
+ public void testPerformance() throws Exception {
+ try (Git git = new Git(db)) {
+ long times[] = new long[N_OF_FILES];
+ long sum = 0;
+ String lastName = null;
+ for (int i = 0; i < N_OF_FILES; i++) {
+ lastName = "a" + (i + 100000) + ".txt";
+ writeTrashFile(lastName, "");
+ long start = System.nanoTime();
+ git.add().addFilepattern(lastName).call();
+ long elapsed = System.nanoTime() - start;
+ times[i] = elapsed;
+ sum += elapsed;
+ }
+ System.out.println("Total (µs) " + sum / 1000.0);
+ for (int i = 0; i < times.length; i++) {
+ System.out
+ .println("Time " + i + " (µs) = " + times[i] / 1000.0);
+ }
+ FileTreeIterator iter = new FileTreeIterator(db);
+ try (TreeWalk walk = new TreeWalk(db)) {
+ walk.setFilter(PathFilter.create(lastName));
+ walk.addTree(iter);
+ long start = System.nanoTime();
+ if (walk.next()) {
+ System.out.println("Walk time (µs) = "
+ + (System.nanoTime() - start) / 1000.0);
+ } else {
+ fail("File not found");
+ }
+ }
+ }
+ }
+}
diff --git a/org.eclipse.jgit.test/pom.xml b/org.eclipse.jgit.test/pom.xml
index af4056c36f..3afe8e03ae 100644
--- a/org.eclipse.jgit.test/pom.xml
+++ b/org.eclipse.jgit.test/pom.xml
@@ -52,7 +52,7 @@
<parent>
<groupId>org.eclipse.jgit</groupId>
<artifactId>org.eclipse.jgit-parent</artifactId>
- <version>4.11.1-SNAPSHOT</version>
+ <version>5.0.2-SNAPSHOT</version>
</parent>
<artifactId>org.eclipse.jgit.test</artifactId>
@@ -62,6 +62,10 @@
JUnit tests for the core library.
</description>
+ <properties>
+ <maven.javadoc.skip>true</maven.javadoc.skip>
+ </properties>
+
<dependencies>
<dependency>
<groupId>junit</groupId>
diff --git a/org.eclipse.jgit.test/tests.bzl b/org.eclipse.jgit.test/tests.bzl
index 637fe0c9c3..b1b7b7a9de 100644
--- a/org.eclipse.jgit.test/tests.bzl
+++ b/org.eclipse.jgit.test/tests.bzl
@@ -19,6 +19,10 @@ def tests(tests):
if 'lib' not in labels:
labels.append('lib')
+ # TODO(http://eclip.se/534285): Make this test pass reliably
+ # and remove the flaky attribute.
+ flaky = src.endswith("CrissCrossMergeTest.java")
+
additional_deps = []
if src.endswith("RootLocaleTest.java"):
additional_deps = [
@@ -52,5 +56,6 @@ def tests(tests):
'//org.eclipse.jgit.junit:junit',
'//org.eclipse.jgit.lfs:jgit-lfs',
],
+ flaky = flaky,
jvm_flags = ["-Xmx256m", "-Dfile.encoding=UTF-8"],
)
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ApplyCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ApplyCommandTest.java
index 172807c43d..1dd329a9e7 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ApplyCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ApplyCommandTest.java
@@ -64,7 +64,7 @@ public class ApplyCommandTest extends RepositoryTestCase {
private RawText b;
- private ApplyResult init(final String name) throws Exception {
+ private ApplyResult init(String name) throws Exception {
return init(name, true, true);
}
@@ -273,7 +273,7 @@ public class ApplyCommandTest extends RepositoryTestCase {
assertFalse(new File(db.getWorkTree(), "NonASCIIDel").exists());
}
- private static byte[] readFile(final String patchFile) throws IOException {
+ private static byte[] readFile(String patchFile) throws IOException {
final InputStream in = getTestResource(patchFile);
if (in == null) {
fail("No " + patchFile + " test vector");
@@ -291,7 +291,7 @@ public class ApplyCommandTest extends RepositoryTestCase {
}
}
- private static InputStream getTestResource(final String patchFile) {
+ private static InputStream getTestResource(String patchFile) {
return ApplyCommandTest.class.getClassLoader()
.getResourceAsStream("org/eclipse/jgit/diff/" + patchFile);
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ArchiveCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ArchiveCommandTest.java
index edab96b971..1300f98d8a 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ArchiveCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ArchiveCommandTest.java
@@ -229,11 +229,6 @@ public class ArchiveCommandTest extends RepositoryTestCase {
}
@Override
- public void putEntry(MockOutputStream out, String path, FileMode mode, ObjectLoader loader) {
- putEntry(out, null, path, mode, loader);
- }
-
- @Override
public void putEntry(MockOutputStream out, ObjectId tree, String path, FileMode mode, ObjectLoader loader) {
String content = mode != FileMode.TREE ? new String(loader.getBytes()) : null;
entries.put(path, content);
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BlameCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BlameCommandTest.java
index f37aa13d6d..7a1d222ca0 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BlameCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BlameCommandTest.java
@@ -136,7 +136,7 @@ public class BlameCommandTest extends RepositoryTestCase {
testRename("subdir/file1.txt", "otherdir/file1.txt");
}
- private void testRename(final String sourcePath, final String destPath)
+ private void testRename(String sourcePath, String destPath)
throws Exception {
try (Git git = new Git(db)) {
String[] content1 = new String[] { "a", "b", "c" };
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BranchCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BranchCommandTest.java
index 2fe40b99ed..08f1fdfacf 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BranchCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BranchCommandTest.java
@@ -191,6 +191,18 @@ public class BranchCommandTest extends RepositoryTestCase {
- allBefore);
}
+ @Test(expected = InvalidRefNameException.class)
+ public void testInvalidBranchHEAD() throws Exception {
+ git.branchCreate().setName("HEAD").call();
+ fail("Create branch with invalid ref name should fail");
+ }
+
+ @Test(expected = InvalidRefNameException.class)
+ public void testInvalidBranchDash() throws Exception {
+ git.branchCreate().setName("-x").call();
+ fail("Create branch with invalid ref name should fail");
+ }
+
@Test
public void testListAllBranchesShouldNotDie() throws Exception {
setUpRepoWithRemote().branchList().setListMode(ListMode.ALL).call();
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CherryPickCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CherryPickCommandTest.java
index 354b9c6a6f..fbc2cf67e1 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CherryPickCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CherryPickCommandTest.java
@@ -338,7 +338,7 @@ public class CherryPickCommandTest extends RepositoryTestCase {
}
}
- private RevCommit prepareCherryPick(final Git git) throws Exception {
+ private RevCommit prepareCherryPick(Git git) throws Exception {
// create, add and commit file a
writeTrashFile("a", "a");
git.add().addFilepattern("a").call();
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitCommandTest.java
index 0dd3749337..3a13aa5a41 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitCommandTest.java
@@ -54,7 +54,7 @@ import java.util.Date;
import java.util.List;
import java.util.TimeZone;
-import org.eclipse.jgit.api.errors.EmtpyCommitException;
+import org.eclipse.jgit.api.errors.EmptyCommitException;
import org.eclipse.jgit.api.errors.WrongRepositoryStateException;
import org.eclipse.jgit.diff.DiffEntry;
import org.eclipse.jgit.dircache.DirCache;
@@ -553,8 +553,8 @@ public class CommitCommandTest extends RepositoryTestCase {
git.commit().setAuthor("New Author", "newauthor@example.org")
.setMessage("again no change").setAllowEmpty(false)
.call();
- fail("Didn't get the expected EmtpyCommitException");
- } catch (EmtpyCommitException e) {
+ fail("Didn't get the expected EmptyCommitException");
+ } catch (EmptyCommitException e) {
// expect this exception
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitOnlyTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitOnlyTest.java
index cc21b473ec..bbd6ec0bde 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitOnlyTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitOnlyTest.java
@@ -1289,7 +1289,7 @@ public class CommitOnlyTest extends RepositoryTestCase {
return null;
}
- static private String getHead(final Git git, final String path)
+ static private String getHead(Git git, String path)
throws Exception {
try {
final Repository repo = git.getRepository();
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/DescribeCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/DescribeCommandTest.java
index 79da2da7ea..a422ef91cb 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/DescribeCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/DescribeCommandTest.java
@@ -54,7 +54,6 @@ import java.util.Collection;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.RefNotFoundException;
-import org.eclipse.jgit.errors.InvalidPatternException;
import org.eclipse.jgit.junit.RepositoryTestCase;
import org.eclipse.jgit.lib.ObjectId;
import org.junit.Test;
@@ -68,13 +67,18 @@ public class DescribeCommandTest extends RepositoryTestCase {
private Git git;
- @Parameter
+ @Parameter(0)
public boolean useAnnotatedTags;
- @Parameters
+ @Parameter(1)
+ public boolean describeUseAllTags;
+
+ @Parameters(name = "git tag -a {0}?-a: with git describe {1}?--tags:")
public static Collection<Boolean[]> getUseAnnotatedTagsValues() {
- return Arrays.asList(new Boolean[][] { { Boolean.TRUE },
- { Boolean.FALSE } });
+ return Arrays.asList(new Boolean[][] { { Boolean.TRUE, Boolean.FALSE },
+ { Boolean.FALSE, Boolean.FALSE },
+ { Boolean.TRUE, Boolean.TRUE },
+ { Boolean.FALSE, Boolean.TRUE } });
}
@Override
@@ -99,35 +103,52 @@ public class DescribeCommandTest extends RepositoryTestCase {
tag("bob-t2");
ObjectId c4 = modify("ddd");
+ assertNameStartsWith(c4, "3e563c5");
assertNull(describe(c1));
assertNull(describe(c1, true));
assertNull(describe(c1, "a*", "b*", "c*"));
-
- assertEquals("alice-t1", describe(c2));
- assertEquals("alice-t1", describe(c2, "alice*"));
assertNull(describe(c2, "bob*"));
assertNull(describe(c2, "?ob*"));
- assertEquals("alice-t1", describe(c2, "a*", "b*", "c*"));
- assertEquals("bob-t2", describe(c3));
- assertEquals("bob-t2-0-g44579eb", describe(c3, true));
- assertEquals("alice-t1-1-g44579eb", describe(c3, "alice*"));
- assertEquals("alice-t1-1-g44579eb", describe(c3, "a??c?-t*"));
- assertEquals("bob-t2", describe(c3, "bob*"));
- assertEquals("bob-t2", describe(c3, "?ob*"));
- assertEquals("bob-t2", describe(c3, "a*", "b*", "c*"));
-
- assertNameStartsWith(c4, "3e563c5");
- // the value verified with git-describe(1)
- assertEquals("bob-t2-1-g3e563c5", describe(c4));
- assertEquals("bob-t2-1-g3e563c5", describe(c4, true));
- assertEquals("alice-t1-2-g3e563c5", describe(c4, "alice*"));
- assertEquals("bob-t2-1-g3e563c5", describe(c4, "bob*"));
- assertEquals("bob-t2-1-g3e563c5", describe(c4, "a*", "b*", "c*"));
+ if (useAnnotatedTags || describeUseAllTags) {
+ assertEquals("alice-t1", describe(c2));
+ assertEquals("alice-t1", describe(c2, "alice*"));
+ assertEquals("alice-t1", describe(c2, "a*", "b*", "c*"));
+
+ assertEquals("bob-t2", describe(c3));
+ assertEquals("bob-t2-0-g44579eb", describe(c3, true));
+ assertEquals("alice-t1-1-g44579eb", describe(c3, "alice*"));
+ assertEquals("alice-t1-1-g44579eb", describe(c3, "a??c?-t*"));
+ assertEquals("bob-t2", describe(c3, "bob*"));
+ assertEquals("bob-t2", describe(c3, "?ob*"));
+ assertEquals("bob-t2", describe(c3, "a*", "b*", "c*"));
+
+ // the value verified with git-describe(1)
+ assertEquals("bob-t2-1-g3e563c5", describe(c4));
+ assertEquals("bob-t2-1-g3e563c5", describe(c4, true));
+ assertEquals("alice-t1-2-g3e563c5", describe(c4, "alice*"));
+ assertEquals("bob-t2-1-g3e563c5", describe(c4, "bob*"));
+ assertEquals("bob-t2-1-g3e563c5", describe(c4, "a*", "b*", "c*"));
+ } else {
+ assertEquals(null, describe(c2));
+ assertEquals(null, describe(c3));
+ assertEquals(null, describe(c4));
+ }
// test default target
- assertEquals("bob-t2-1-g3e563c5", git.describe().call());
+ if (useAnnotatedTags) {
+ assertEquals("bob-t2-1-g3e563c5", git.describe().call());
+ assertEquals("bob-t2-1-g3e563c5",
+ git.describe().setTags(false).call());
+ assertEquals("bob-t2-1-g3e563c5",
+ git.describe().setTags(true).call());
+ } else {
+ assertEquals(null, git.describe().call());
+ assertEquals(null, git.describe().setTags(false).call());
+ assertEquals("bob-t2-1-g3e563c5",
+ git.describe().setTags(true).call());
+ }
}
@Test
@@ -137,7 +158,14 @@ public class DescribeCommandTest extends RepositoryTestCase {
tag("v1.1.1");
ObjectId c2 = modify("bbb");
- // Ensure that if we're interested in any tags, we get the first match as per Git behaviour
+ if (!useAnnotatedTags && !describeUseAllTags) {
+ assertEquals(null, describe(c1));
+ assertEquals(null, describe(c2));
+ return;
+ }
+
+ // Ensure that if we're interested in any tags, we get the first match
+ // as per Git behaviour
assertEquals("v1.0.0", describe(c1));
assertEquals("v1.0.0-1-g3747db3", describe(c2));
@@ -179,7 +207,11 @@ public class DescribeCommandTest extends RepositoryTestCase {
ObjectId c4 = merge(c2);
assertNameStartsWith(c4, "119892b");
- assertEquals("t-2-g119892b", describe(c4)); // 2 commits: c4 and c3
+ if (useAnnotatedTags || describeUseAllTags) {
+ assertEquals("2 commits: c4 and c3", "t-2-g119892b", describe(c4));
+ } else {
+ assertEquals(null, describe(c4));
+ }
assertNull(describe(c3));
assertNull(describe(c3, true));
}
@@ -211,14 +243,76 @@ public class DescribeCommandTest extends RepositoryTestCase {
branch("b", c1);
ObjectId c3 = modify("ccc");
+ assertNameStartsWith(c3, "0244e7f");
ObjectId c4 = merge(c2);
assertNameStartsWith(c4, "119892b");
- assertEquals("t2-2-g119892b", describe(c4)); // 2 commits: c4 and c3
+
+ if (useAnnotatedTags || describeUseAllTags) {
+ assertEquals("t2-2-g119892b", describe(c4)); // 2 commits: c4 and c3
+ assertEquals("t1-1-g0244e7f", describe(c3));
+ } else {
+ assertEquals(null, describe(c4));
+ assertEquals(null, describe(c3));
+ }
+ }
+
+ /**
+ * When t1 annotated dominates t2 lightweight tag
+ *
+ * <pre>
+ * t1 -+-> t2 -
+ * | |
+ * +-> c3 -+-> c4
+ * </pre>
+ *
+ * @throws Exception
+ */
+ @Test
+ public void t1AnnotatedDominatesT2lightweight() throws Exception {
+ ObjectId c1 = modify("aaa");
+ tag("t1", useAnnotatedTags);
+
+ ObjectId c2 = modify("bbb");
+ tag("t2", false);
+
+ assertNameStartsWith(c2, "3747db3");
+ if (useAnnotatedTags && !describeUseAllTags) {
+ assertEquals(
+ "only annotated tag t1 expected to be used for describe",
+ "t1-1-g3747db3", describe(c2)); // 1 commits: t2 overridden
+ // by t1
+ } else if (!useAnnotatedTags && !describeUseAllTags) {
+ assertEquals("no commits to describe expected", null, describe(c2));
+ } else {
+ assertEquals("lightweight tag t2 expected in describe", "t2",
+ describe(c2));
+ }
+
+ branch("b", c1);
+
+ ObjectId c3 = modify("ccc");
assertNameStartsWith(c3, "0244e7f");
- assertEquals("t1-1-g0244e7f", describe(c3));
+ if (useAnnotatedTags || describeUseAllTags) {
+ assertEquals("t1-1-g0244e7f", describe(c3));
+ }
+
+ ObjectId c4 = merge(c2);
+
+ assertNameStartsWith(c4, "119892b");
+ if (describeUseAllTags) {
+ assertEquals(
+ "2 commits for describe commit increment expected since lightweight tag: c4 and c3",
+ "t2-2-g119892b", describe(c4)); // 2 commits: c4 and c3
+ } else if (!useAnnotatedTags && !describeUseAllTags) {
+ assertEquals("no matching commits expected", null, describe(c4));
+ } else {
+ assertEquals(
+ "3 commits for describe commit increment expected since annotated tag: c4 and c3 and c2",
+ "t1-3-g119892b", describe(c4)); //
+ }
}
/**
@@ -246,7 +340,11 @@ public class DescribeCommandTest extends RepositoryTestCase {
ObjectId c4 = merge(t1);
assertNameStartsWith(c4, "bb389a4");
- assertEquals("t1-3-gbb389a4", describe(c4));
+ if (useAnnotatedTags || describeUseAllTags) {
+ assertEquals("t1-3-gbb389a4", describe(c4));
+ } else {
+ assertEquals(null, describe(c4));
+ }
}
/**
@@ -275,7 +373,11 @@ public class DescribeCommandTest extends RepositoryTestCase {
ObjectId c4 = merge(c2);
assertNameStartsWith(c4, "bb389a4");
- assertEquals("t2-4-gbb389a4", describe(c4));
+ if (useAnnotatedTags || describeUseAllTags) {
+ assertEquals("t2-4-gbb389a4", describe(c4));
+ } else {
+ assertEquals(null, describe(c4));
+ }
}
private ObjectId merge(ObjectId c2) throws GitAPIException {
@@ -289,10 +391,15 @@ public class DescribeCommandTest extends RepositoryTestCase {
}
private void tag(String tag) throws GitAPIException {
+ tag(tag, this.useAnnotatedTags);
+ }
+
+ private void tag(String tag, boolean annotatedTag) throws GitAPIException {
TagCommand tagCommand = git.tag().setName(tag)
- .setAnnotated(useAnnotatedTags);
- if (useAnnotatedTags)
+ .setAnnotated(annotatedTag);
+ if (annotatedTag) {
tagCommand.setMessage(tag);
+ }
tagCommand.call();
}
@@ -304,15 +411,17 @@ public class DescribeCommandTest extends RepositoryTestCase {
private String describe(ObjectId c1, boolean longDesc)
throws GitAPIException, IOException {
- return git.describe().setTarget(c1).setLong(longDesc).call();
+ return git.describe().setTarget(c1).setTags(describeUseAllTags)
+ .setLong(longDesc).call();
}
private String describe(ObjectId c1) throws GitAPIException, IOException {
return describe(c1, false);
}
- private String describe(ObjectId c1, String... patterns) throws GitAPIException, IOException, InvalidPatternException {
- return git.describe().setTarget(c1).setMatch(patterns).call();
+ private String describe(ObjectId c1, String... patterns) throws Exception {
+ return git.describe().setTarget(c1).setTags(describeUseAllTags)
+ .setMatch(patterns).call();
}
private static void assertNameStartsWith(ObjectId c4, String prefix) {
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/EolStreamTypeUtilTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/EolStreamTypeUtilTest.java
index 1e3a39aad8..bb303cc411 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/EolStreamTypeUtilTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/EolStreamTypeUtilTest.java
@@ -42,7 +42,7 @@
package org.eclipse.jgit.api;
-import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
import static org.eclipse.jgit.lib.CoreConfig.EolStreamType.AUTO_CRLF;
import static org.eclipse.jgit.lib.CoreConfig.EolStreamType.AUTO_LF;
import static org.eclipse.jgit.lib.CoreConfig.EolStreamType.DIRECT;
@@ -150,8 +150,8 @@ public class EolStreamTypeUtilTest {
EolStreamType streamTypeWithBinaryCheck, String output,
String expectedConversion) throws Exception {
ByteArrayOutputStream b;
- byte[] outputBytes = output.getBytes(UTF_8);
- byte[] expectedConversionBytes = expectedConversion.getBytes(UTF_8);
+ byte[] outputBytes = output.getBytes(CHARSET);
+ byte[] expectedConversionBytes = expectedConversion.getBytes(CHARSET);
// test using output text and assuming it was declared TEXT
b = new ByteArrayOutputStream();
@@ -277,8 +277,8 @@ public class EolStreamTypeUtilTest {
private void testCheckin(EolStreamType streamTypeText,
EolStreamType streamTypeWithBinaryCheck, String input,
String expectedConversion) throws Exception {
- byte[] inputBytes = input.getBytes(UTF_8);
- byte[] expectedConversionBytes = expectedConversion.getBytes(UTF_8);
+ byte[] inputBytes = input.getBytes(CHARSET);
+ byte[] expectedConversionBytes = expectedConversion.getBytes(CHARSET);
// test using input text and assuming it was declared TEXT
try (InputStream in = EolStreamTypeUtil.wrapInputStream(
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/FetchCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/FetchCommandTest.java
index 83a0564c77..4c2c0e8d1f 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/FetchCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/FetchCommandTest.java
@@ -43,10 +43,15 @@
package org.eclipse.jgit.api;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import java.io.File;
import java.util.Collection;
+import org.eclipse.jgit.junit.JGitTestUtil;
import org.eclipse.jgit.junit.RepositoryTestCase;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
@@ -102,6 +107,25 @@ public class FetchCommandTest extends RepositoryTestCase {
}
@Test
+ public void testForcedFetch() throws Exception {
+ remoteGit.commit().setMessage("commit").call();
+ remoteGit.commit().setMessage("commit2").call();
+ git.fetch().setRemote("test")
+ .setRefSpecs("refs/heads/master:refs/heads/master").call();
+
+ remoteGit.commit().setAmend(true).setMessage("amended").call();
+ FetchResult res = git.fetch().setRemote("test")
+ .setRefSpecs("refs/heads/master:refs/heads/master").call();
+ assertEquals(RefUpdate.Result.REJECTED,
+ res.getTrackingRefUpdate("refs/heads/master").getResult());
+ res = git.fetch().setRemote("test")
+ .setRefSpecs("refs/heads/master:refs/heads/master")
+ .setForceUpdate(true).call();
+ assertEquals(RefUpdate.Result.FORCED,
+ res.getTrackingRefUpdate("refs/heads/master").getResult());
+ }
+
+ @Test
public void fetchShouldAutoFollowTag() throws Exception {
remoteGit.commit().setMessage("commit").call();
Ref tagRef = remoteGit.tag().setName("foo").call();
@@ -185,4 +209,43 @@ public class FetchCommandTest extends RepositoryTestCase {
assertEquals(RefUpdate.Result.FORCED, update.getResult());
assertEquals(tagRef2.getObjectId(), db.resolve(tagName));
}
+
+ @Test
+ public void testFetchWithPruneShouldKeepOriginHead() throws Exception {
+ // Create a commit in the test repo.
+ commitFile("foo", "foo", "master");
+ // Produce a real clone of the git repo
+ Git cloned = Git.cloneRepository()
+ .setDirectory(createTempDirectory("testCloneRepository"))
+ .setURI("file://"
+ + git.getRepository().getWorkTree().getAbsolutePath())
+ .call();
+ assertNotNull(cloned);
+ Repository clonedRepo = cloned.getRepository();
+ addRepoToClose(clonedRepo);
+ ObjectId originMasterId = clonedRepo
+ .resolve("refs/remotes/origin/master");
+ assertNotNull("Should have origin/master", originMasterId);
+ assertNotEquals("origin/master should not be zero ID",
+ ObjectId.zeroId(), originMasterId);
+ // Canonical git creates origin/HEAD; JGit (for now) doesn't. Let's
+ // pretend we did the clone via command-line git.
+ ObjectId originHeadId = clonedRepo.resolve("refs/remotes/origin/HEAD");
+ if (originHeadId == null) {
+ JGitTestUtil.write(
+ new File(clonedRepo.getDirectory(),
+ "refs/remotes/origin/HEAD"),
+ "ref: refs/remotes/origin/master\n");
+ originHeadId = clonedRepo.resolve("refs/remotes/origin/HEAD");
+ }
+ assertEquals("Should have origin/HEAD", originMasterId, originHeadId);
+ FetchResult result = cloned.fetch().setRemote("origin")
+ .setRemoveDeletedRefs(true).call();
+ assertTrue("Fetch after clone should be up-to-date",
+ result.getTrackingRefUpdates().isEmpty());
+ assertEquals("origin/master should still exist", originMasterId,
+ clonedRepo.resolve("refs/remotes/origin/master"));
+ assertEquals("origin/HEAD should be unchanged", originHeadId,
+ clonedRepo.resolve("refs/remotes/origin/HEAD"));
+ }
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/LogCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/LogCommandTest.java
index bd0efad016..4ef511e43d 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/LogCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/LogCommandTest.java
@@ -116,7 +116,7 @@ public class LogCommandTest extends RepositoryTestCase {
Iterator<RevCommit> log = git.log().all().call().iterator();
assertTrue(log.hasNext());
RevCommit commit = log.next();
- tag = db.peel(tag);
+ tag = db.getRefDatabase().peel(tag);
assertEquals(commit.getName(), tag.getPeeledObjectId().getName());
assertTrue(commits.contains(commit));
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java
index 4b23349fa6..9af003d424 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java
@@ -54,6 +54,7 @@ import static org.junit.Assume.assumeTrue;
import java.io.File;
import java.util.Iterator;
+import java.util.regex.Pattern;
import org.eclipse.jgit.api.MergeCommand.FastForwardMode;
import org.eclipse.jgit.api.MergeResult.MergeStatus;
@@ -1584,36 +1585,77 @@ public class MergeCommandTest extends RepositoryTestCase {
assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus());
}
+ private Ref prepareSuccessfulMerge(Git git) throws Exception {
+ writeTrashFile("a", "1\na\n3\n");
+ git.add().addFilepattern("a").call();
+ RevCommit initialCommit = git.commit().setMessage("initial").call();
+
+ createBranch(initialCommit, "refs/heads/side");
+ checkoutBranch("refs/heads/side");
+
+ writeTrashFile("b", "1\nb\n3\n");
+ git.add().addFilepattern("b").call();
+ git.commit().setMessage("side").call();
+
+ checkoutBranch("refs/heads/master");
+
+ writeTrashFile("c", "1\nc\n3\n");
+ git.add().addFilepattern("c").call();
+ git.commit().setMessage("main").call();
+
+ return db.exactRef("refs/heads/side");
+ }
+
@Test
public void testMergeWithMessageOption() throws Exception {
try (Git git = new Git(db)) {
- writeTrashFile("a", "1\na\n3\n");
- git.add().addFilepattern("a").call();
- RevCommit initialCommit = git.commit().setMessage("initial").call();
+ Ref sideBranch = prepareSuccessfulMerge(git);
- createBranch(initialCommit, "refs/heads/side");
- checkoutBranch("refs/heads/side");
+ git.merge().include(sideBranch).setStrategy(MergeStrategy.RESOLVE)
+ .setMessage("user message").call();
- writeTrashFile("b", "1\nb\n3\n");
- git.add().addFilepattern("b").call();
- git.commit().setMessage("side").call();
+ assertNull(db.readMergeCommitMsg());
- checkoutBranch("refs/heads/master");
+ Iterator<RevCommit> it = git.log().call().iterator();
+ RevCommit newHead = it.next();
+ assertEquals("user message", newHead.getFullMessage());
+ }
+ }
- writeTrashFile("c", "1\nc\n3\n");
- git.add().addFilepattern("c").call();
- git.commit().setMessage("main").call();
+ @Test
+ public void testMergeWithChangeId() throws Exception {
+ try (Git git = new Git(db)) {
+ Ref sideBranch = prepareSuccessfulMerge(git);
- Ref sideBranch = db.exactRef("refs/heads/side");
+ git.merge().include(sideBranch).setStrategy(MergeStrategy.RESOLVE)
+ .setInsertChangeId(true).call();
+
+ assertNull(db.readMergeCommitMsg());
+
+ Iterator<RevCommit> it = git.log().call().iterator();
+ RevCommit newHead = it.next();
+ String commitMessage = newHead.getFullMessage();
+ assertTrue(Pattern.compile("\nChange-Id: I[0-9a-fA-F]{40}\n")
+ .matcher(commitMessage).find());
+ }
+ }
+
+ @Test
+ public void testMergeWithMessageAndChangeId() throws Exception {
+ try (Git git = new Git(db)) {
+ Ref sideBranch = prepareSuccessfulMerge(git);
git.merge().include(sideBranch).setStrategy(MergeStrategy.RESOLVE)
- .setMessage("user message").call();
+ .setMessage("user message").setInsertChangeId(true).call();
assertNull(db.readMergeCommitMsg());
Iterator<RevCommit> it = git.log().call().iterator();
RevCommit newHead = it.next();
- assertEquals("user message", newHead.getFullMessage());
+ String commitMessage = newHead.getFullMessage();
+ assertTrue(commitMessage.startsWith("user message\n\n"));
+ assertTrue(Pattern.compile("\nChange-Id: I[0-9a-fA-F]{40}\n")
+ .matcher(commitMessage).find());
}
}
@@ -1657,7 +1699,7 @@ public class MergeCommandTest extends RepositoryTestCase {
.getWorkTree(), path));
}
- private static RevCommit addAllAndCommit(final Git git) throws Exception {
+ private static RevCommit addAllAndCommit(Git git) throws Exception {
git.add().addFilepattern(".").call();
return git.commit().setMessage("message").call();
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/NotesCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/NotesCommandTest.java
index 6e06e9545a..e234aa339c 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/NotesCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/NotesCommandTest.java
@@ -42,7 +42,7 @@
*/
package org.eclipse.jgit.api;
-import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
import static org.junit.Assert.assertEquals;
import java.util.List;
@@ -88,7 +88,7 @@ public class NotesCommandTest extends RepositoryTestCase {
git.notesAdd().setObjectId(commit2).setMessage("data").call();
Note note = git.notesShow().setObjectId(commit2).call();
String content = new String(db.open(note.getData()).getCachedBytes(),
- UTF_8);
+ CHARSET);
assertEquals(content, "data");
git.notesRemove().setObjectId(commit2).call();
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandTest.java
index 9461c42500..0b0e3bf3ea 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandTest.java
@@ -42,7 +42,7 @@
*/
package org.eclipse.jgit.api;
-import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@@ -592,7 +592,7 @@ public class PullCommandTest extends RepositoryTestCase {
private static void writeToFile(File actFile, String string)
throws IOException {
try (FileOutputStream fos = new FileOutputStream(actFile)) {
- fos.write(string.getBytes(UTF_8));
+ fos.write(string.getBytes(CHARSET));
}
}
@@ -606,7 +606,7 @@ public class PullCommandTest extends RepositoryTestCase {
bos.write(buffer, 0, read);
read = fis.read(buffer);
}
- String content = new String(bos.toByteArray(), UTF_8);
+ String content = new String(bos.toByteArray(), CHARSET);
assertEquals(string, content);
}
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandWithRebaseTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandWithRebaseTest.java
index 913b4ac434..b349c66cab 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandWithRebaseTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandWithRebaseTest.java
@@ -42,7 +42,7 @@
*/
package org.eclipse.jgit.api;
-import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@@ -396,7 +396,7 @@ public class PullCommandWithRebaseTest extends RepositoryTestCase {
private static void writeToFile(File actFile, String string)
throws IOException {
try (FileOutputStream fos = new FileOutputStream(actFile)) {
- fos.write(string.getBytes(UTF_8));
+ fos.write(string.getBytes(CHARSET));
}
}
@@ -410,7 +410,7 @@ public class PullCommandWithRebaseTest extends RepositoryTestCase {
bos.write(buffer, 0, read);
read = fis.read(buffer);
}
- String content = new String(bos.toByteArray(), UTF_8);
+ String content = new String(bos.toByteArray(), CHARSET);
assertEquals(string, content);
}
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PushCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PushCommandTest.java
index e0c1499030..1af37e25f5 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PushCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PushCommandTest.java
@@ -152,7 +152,7 @@ public class PushCommandTest extends RepositoryTestCase {
}
}
- private File writeHookFile(final String name, final String data)
+ private File writeHookFile(String name, String data)
throws IOException {
File path = new File(db.getWorkTree() + "/.git/hooks/", name);
JGitTestUtil.write(path, data);
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java
index 2bf91aeed8..96e7091ae1 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java
@@ -42,7 +42,7 @@
*/
package org.eclipse.jgit.api;
-import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -1464,7 +1464,7 @@ public class RebaseCommandTest extends RepositoryTestCase {
assertEquals("GIT_AUTHOR_DATE='@123456789 -0100'", lines[2]);
PersonIdent parsedIdent = git.rebase().parseAuthor(
- convertedAuthor.getBytes(UTF_8));
+ convertedAuthor.getBytes(CHARSET));
assertEquals(ident.getName(), parsedIdent.getName());
assertEquals(ident.getEmailAddress(), parsedIdent.getEmailAddress());
// this is rounded to the last second
@@ -1481,7 +1481,7 @@ public class RebaseCommandTest extends RepositoryTestCase {
assertEquals("GIT_AUTHOR_DATE='@123456789 +0930'", lines[2]);
parsedIdent = git.rebase().parseAuthor(
- convertedAuthor.getBytes(UTF_8));
+ convertedAuthor.getBytes(CHARSET));
assertEquals(ident.getName(), parsedIdent.getName());
assertEquals(ident.getEmailAddress(), parsedIdent.getEmailAddress());
assertEquals(123456789000L, parsedIdent.getWhen().getTime());
@@ -2104,7 +2104,7 @@ public class RebaseCommandTest extends RepositoryTestCase {
int count = 0;
File todoFile = getTodoFile();
try (BufferedReader br = new BufferedReader(new InputStreamReader(
- new FileInputStream(todoFile), UTF_8))) {
+ new FileInputStream(todoFile), CHARSET))) {
String line = br.readLine();
while (line != null) {
int firstBlank = line.indexOf(' ');
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ResetCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ResetCommandTest.java
index ba51881ffd..8f56a9270e 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ResetCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ResetCommandTest.java
@@ -100,39 +100,39 @@ public class ResetCommandTest extends RepositoryTestCase {
File nestedFile = new File(dir, "b.txt");
FileUtils.createNewFile(nestedFile);
- PrintWriter nesterFileWriter = new PrintWriter(nestedFile);
- nesterFileWriter.print("content");
- nesterFileWriter.flush();
-
- // create file
- indexFile = new File(db.getWorkTree(), "a.txt");
- FileUtils.createNewFile(indexFile);
- PrintWriter writer = new PrintWriter(indexFile);
- writer.print("content");
- writer.flush();
-
- // add file and commit it
- git.add().addFilepattern("dir").addFilepattern("a.txt").call();
- secondCommit = git.commit().setMessage("adding a.txt and dir/b.txt")
- .call();
-
- prestage = DirCache.read(db.getIndexFile(), db.getFS()).getEntry(
- indexFile.getName());
-
- // modify file and add to index
- writer.print("new content");
- writer.close();
- nesterFileWriter.print("new content");
- nesterFileWriter.close();
+ try (PrintWriter nestedFileWriter = new PrintWriter(nestedFile)) {
+ nestedFileWriter.print("content");
+ nestedFileWriter.flush();
+
+ // create file
+ indexFile = new File(db.getWorkTree(), "a.txt");
+ FileUtils.createNewFile(indexFile);
+ try (PrintWriter writer = new PrintWriter(indexFile)) {
+ writer.print("content");
+ writer.flush();
+
+ // add file and commit it
+ git.add().addFilepattern("dir").addFilepattern("a.txt").call();
+ secondCommit = git.commit()
+ .setMessage("adding a.txt and dir/b.txt").call();
+
+ prestage = DirCache.read(db.getIndexFile(), db.getFS())
+ .getEntry(indexFile.getName());
+
+ // modify file and add to index
+ writer.print("new content");
+ }
+ nestedFileWriter.print("new content");
+ }
git.add().addFilepattern("a.txt").addFilepattern("dir").call();
// create a file not added to the index
untrackedFile = new File(db.getWorkTree(),
"notAddedToIndex.txt");
FileUtils.createNewFile(untrackedFile);
- PrintWriter writer2 = new PrintWriter(untrackedFile);
- writer2.print("content");
- writer2.close();
+ try (PrintWriter writer2 = new PrintWriter(untrackedFile)) {
+ writer2.print("content");
+ }
}
@Test
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RevertCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RevertCommandTest.java
index ea631045cc..d77c4e131e 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RevertCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RevertCommandTest.java
@@ -379,7 +379,7 @@ public class RevertCommandTest extends RepositoryTestCase {
}
}
- private RevCommit prepareRevert(final Git git) throws Exception {
+ private RevCommit prepareRevert(Git git) throws Exception {
// create, add and commit file a
writeTrashFile("a", "a");
git.add().addFilepattern("a").call();
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StashCreateCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StashCreateCommandTest.java
index b9f9f5b499..3b582d714d 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StashCreateCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StashCreateCommandTest.java
@@ -94,7 +94,7 @@ public class StashCreateCommandTest extends RepositoryTestCase {
untrackedFile = writeTrashFile("untracked.txt", "content");
}
- private void validateStashedCommit(final RevCommit commit)
+ private void validateStashedCommit(RevCommit commit)
throws IOException {
validateStashedCommit(commit, 2);
}
@@ -140,7 +140,7 @@ public class StashCreateCommandTest extends RepositoryTestCase {
return walk;
}
- private List<DiffEntry> diffWorkingAgainstHead(final RevCommit commit)
+ private List<DiffEntry> diffWorkingAgainstHead(RevCommit commit)
throws IOException {
try (TreeWalk walk = createTreeWalk()) {
walk.addTree(commit.getParent(0).getTree());
@@ -149,7 +149,7 @@ public class StashCreateCommandTest extends RepositoryTestCase {
}
}
- private List<DiffEntry> diffIndexAgainstHead(final RevCommit commit)
+ private List<DiffEntry> diffIndexAgainstHead(RevCommit commit)
throws IOException {
try (TreeWalk walk = createTreeWalk()) {
walk.addTree(commit.getParent(0).getTree());
@@ -158,7 +158,7 @@ public class StashCreateCommandTest extends RepositoryTestCase {
}
}
- private List<DiffEntry> diffIndexAgainstWorking(final RevCommit commit)
+ private List<DiffEntry> diffIndexAgainstWorking(RevCommit commit)
throws IOException {
try (TreeWalk walk = createTreeWalk()) {
walk.addTree(commit.getParent(1).getTree());
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/TagCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/TagCommandTest.java
index 87098b65f4..a220e77e0e 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/TagCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/TagCommandTest.java
@@ -42,6 +42,7 @@
*/
package org.eclipse.jgit.api;
+import static org.eclipse.jgit.lib.Constants.R_TAGS;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
@@ -66,19 +67,22 @@ public class TagCommandTest extends RepositoryTestCase {
RevWalk walk = new RevWalk(db)) {
RevCommit commit = git.commit().setMessage("initial commit").call();
Ref tagRef = git.tag().setName("tag").call();
- assertEquals(commit.getId(), db.peel(tagRef).getPeeledObjectId());
+ assertEquals(commit.getId(),
+ db.getRefDatabase().peel(tagRef).getPeeledObjectId());
assertEquals("tag", walk.parseTag(tagRef.getObjectId()).getTagName());
}
}
@Test
- public void testTagging() throws GitAPIException, JGitInternalException {
+ public void testTagging()
+ throws GitAPIException, JGitInternalException, IOException {
try (Git git = new Git(db)) {
git.commit().setMessage("initial commit").call();
RevCommit commit = git.commit().setMessage("second commit").call();
git.commit().setMessage("third commit").call();
Ref tagRef = git.tag().setObjectId(commit).setName("tag").call();
- assertEquals(commit.getId(), db.peel(tagRef).getPeeledObjectId());
+ assertEquals(commit.getId(),
+ db.getRefDatabase().peel(tagRef).getPeeledObjectId());
}
}
@@ -135,26 +139,30 @@ public class TagCommandTest extends RepositoryTestCase {
}
}
+ private List<Ref> getTags() throws Exception {
+ return db.getRefDatabase().getRefsByPrefix(R_TAGS);
+ }
+
@Test
public void testDelete() throws Exception {
try (Git git = new Git(db)) {
git.commit().setMessage("initial commit").call();
Ref tagRef = git.tag().setName("tag").call();
- assertEquals(1, db.getTags().size());
+ assertEquals(1, getTags().size());
List<String> deleted = git.tagDelete().setTags(tagRef.getName())
.call();
assertEquals(1, deleted.size());
assertEquals(tagRef.getName(), deleted.get(0));
- assertEquals(0, db.getTags().size());
+ assertEquals(0, getTags().size());
Ref tagRef1 = git.tag().setName("tag1").call();
Ref tagRef2 = git.tag().setName("tag2").call();
- assertEquals(2, db.getTags().size());
+ assertEquals(2, getTags().size());
deleted = git.tagDelete().setTags(tagRef1.getName(), tagRef2.getName())
.call();
assertEquals(2, deleted.size());
- assertEquals(0, db.getTags().size());
+ assertEquals(0, getTags().size());
}
}
@@ -163,13 +171,13 @@ public class TagCommandTest extends RepositoryTestCase {
try (Git git = new Git(db)) {
git.commit().setMessage("initial commit").call();
Ref tagRef = git.tag().setName("tag").call();
- assertEquals(1, db.getTags().size());
+ assertEquals(1, getTags().size());
List<String> deleted = git.tagDelete()
.setTags(Repository.shortenRefName(tagRef.getName())).call();
assertEquals(1, deleted.size());
assertEquals(tagRef.getName(), deleted.get(0));
- assertEquals(0, db.getTags().size());
+ assertEquals(0, getTags().size());
}
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/AbstractDiffTestCase.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/AbstractDiffTestCase.java
index 0f13a68b25..32f34213ec 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/AbstractDiffTestCase.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/AbstractDiffTestCase.java
@@ -43,7 +43,7 @@
package org.eclipse.jgit.diff;
-import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -240,6 +240,6 @@ public abstract class AbstractDiffTestCase {
r.append(text.charAt(i));
r.append('\n');
}
- return new RawText(r.toString().getBytes(UTF_8));
+ return new RawText(r.toString().getBytes(CHARSET));
}
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffFormatterReflowTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffFormatterReflowTest.java
index 49e5d1b3d4..0e344f5f28 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffFormatterReflowTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffFormatterReflowTest.java
@@ -146,7 +146,7 @@ public class DiffFormatterReflowTest {
assertFormatted("Z.patch");
}
- private void init(final String name) throws IOException {
+ private void init(String name) throws IOException {
a = new RawText(readFile(name + "_PreImage"));
b = new RawText(readFile(name + "_PostImage"));
file = parseTestPatchFile(name + ".patch").getFiles().get(0);
@@ -156,13 +156,13 @@ public class DiffFormatterReflowTest {
assertFormatted(JGitTestUtil.getName() + ".out");
}
- private void assertFormatted(final String name) throws IOException {
+ private void assertFormatted(String name) throws IOException {
fmt.format(file, a, b);
final String exp = RawParseUtils.decode(readFile(name));
assertEquals(exp, RawParseUtils.decode(out.toByteArray()));
}
- private byte[] readFile(final String patchFile) throws IOException {
+ private byte[] readFile(String patchFile) throws IOException {
final InputStream in = getClass().getResourceAsStream(patchFile);
if (in == null) {
fail("No " + patchFile + " test vector");
@@ -180,7 +180,7 @@ public class DiffFormatterReflowTest {
}
}
- private Patch parseTestPatchFile(final String patchFile) throws IOException {
+ private Patch parseTestPatchFile(String patchFile) throws IOException {
try (InputStream in = getClass().getResourceAsStream(patchFile)) {
if (in == null) {
fail("No " + patchFile + " test vector");
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RawTextTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RawTextTest.java
index 6ad59b9e56..58a8b2d468 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RawTextTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RawTextTest.java
@@ -44,7 +44,8 @@
package org.eclipse.jgit.diff;
-import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
+import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
@@ -65,6 +66,16 @@ public class RawTextTest {
}
@Test
+ public void testBinary() {
+ String input = "foo-a\nf\0o-b\n";
+ byte[] data = Constants.encodeASCII(input);
+ final RawText a = new RawText(data);
+ assertArrayEquals(a.content, data);
+ assertEquals(a.size(), 1);
+ assertEquals(a.getString(0, 1, false), input);
+ }
+
+ @Test
public void testEquals() {
final RawText a = new RawText(Constants.encodeASCII("foo-a\nfoo-b\n"));
final RawText b = new RawText(Constants.encodeASCII("foo-b\nfoo-c\n"));
@@ -136,8 +147,8 @@ public class RawTextTest {
e = c.reduceCommonStartEnd(t("abQxy"), t("abRxy"), e);
assertEquals(new Edit(2, 3, 2, 3), e);
- RawText a = new RawText("p\na b\nQ\nc d\n".getBytes(UTF_8));
- RawText b = new RawText("p\na b \nR\n c d \n".getBytes(UTF_8));
+ RawText a = new RawText("p\na b\nQ\nc d\n".getBytes(CHARSET));
+ RawText b = new RawText("p\na b \nR\n c d \n".getBytes(CHARSET));
e = new Edit(0, 4, 0, 4);
e = RawTextComparator.WS_IGNORE_ALL.reduceCommonStartEnd(a, b, e);
assertEquals(new Edit(2, 3, 2, 3), e);
@@ -149,14 +160,14 @@ public class RawTextTest {
RawText b;
Edit e;
- a = new RawText("R\n y\n".getBytes(UTF_8));
- b = new RawText("S\n\n y\n".getBytes(UTF_8));
+ a = new RawText("R\n y\n".getBytes(CHARSET));
+ b = new RawText("S\n\n y\n".getBytes(CHARSET));
e = new Edit(0, 2, 0, 3);
e = RawTextComparator.DEFAULT.reduceCommonStartEnd(a, b, e);
assertEquals(new Edit(0, 1, 0, 2), e);
- a = new RawText("S\n\n y\n".getBytes(UTF_8));
- b = new RawText("R\n y\n".getBytes(UTF_8));
+ a = new RawText("S\n\n y\n".getBytes(CHARSET));
+ b = new RawText("R\n y\n".getBytes(CHARSET));
e = new Edit(0, 3, 0, 2);
e = RawTextComparator.DEFAULT.reduceCommonStartEnd(a, b, e);
assertEquals(new Edit(0, 2, 0, 1), e);
@@ -167,8 +178,8 @@ public class RawTextTest {
RawText a;
RawText b;
Edit e;
- a = new RawText("start".getBytes(UTF_8));
- b = new RawText("start of line".getBytes(UTF_8));
+ a = new RawText("start".getBytes(CHARSET));
+ b = new RawText("start of line".getBytes(CHARSET));
e = new Edit(0, 1, 0, 1);
e = RawTextComparator.DEFAULT.reduceCommonStartEnd(a, b, e);
assertEquals(new Edit(0, 1, 0, 1), e);
@@ -179,8 +190,8 @@ public class RawTextTest {
RawText a;
RawText b;
Edit e;
- a = new RawText("start".getBytes(UTF_8));
- b = new RawText("start of\nlastline".getBytes(UTF_8));
+ a = new RawText("start".getBytes(CHARSET));
+ b = new RawText("start of\nlastline".getBytes(CHARSET));
e = new Edit(0, 1, 0, 2);
e = RawTextComparator.DEFAULT.reduceCommonStartEnd(a, b, e);
assertEquals(new Edit(0, 1, 0, 2), e);
@@ -239,6 +250,6 @@ public class RawTextTest {
r.append(text.charAt(i));
r.append('\n');
}
- return new RawText(r.toString().getBytes(UTF_8));
+ return new RawText(r.toString().getBytes(CHARSET));
}
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/SimilarityIndexTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/SimilarityIndexTest.java
index f168e83284..51a6f8121c 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/SimilarityIndexTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/SimilarityIndexTest.java
@@ -43,7 +43,7 @@
package org.eclipse.jgit.diff;
-import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -82,7 +82,7 @@ public class SimilarityIndexTest {
+ "A\n" //
+ "B\n" //
+ "B\n" //
- + "B\n").getBytes(UTF_8);
+ + "B\n").getBytes(CHARSET);
SimilarityIndex si = new SimilarityIndex();
si.hash(new ByteArrayInputStream(in), in.length, false);
assertEquals(2, si.size());
@@ -130,12 +130,12 @@ public class SimilarityIndexTest {
+ "D\r\n" //
+ "B\r\n";
SimilarityIndex src = new SimilarityIndex();
- byte[] bytes1 = text.getBytes(UTF_8);
+ byte[] bytes1 = text.getBytes(CHARSET);
src.hash(new ByteArrayInputStream(bytes1), bytes1.length, true);
src.sort();
SimilarityIndex dst = new SimilarityIndex();
- byte[] bytes2 = text.replace("\r", "").getBytes(UTF_8);
+ byte[] bytes2 = text.replace("\r", "").getBytes(CHARSET);
dst.hash(new ByteArrayInputStream(bytes2), bytes2.length, true);
dst.sort();
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBuilderIteratorTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBuilderIteratorTest.java
index 2b108870f9..3598f3a4a1 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBuilderIteratorTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBuilderIteratorTest.java
@@ -78,7 +78,7 @@ public class DirCacheBuilderIteratorTest extends RepositoryTestCase {
final int expIdx = 2;
final DirCacheBuilder b = dc.builder();
- try (final TreeWalk tw = new TreeWalk(db)) {
+ try (TreeWalk tw = new TreeWalk(db)) {
tw.addTree(new DirCacheBuildIterator(b));
tw.setRecursive(true);
tw.setFilter(PathFilterGroup.createFromStrings(Collections
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheCGitCompatabilityTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheCGitCompatabilityTest.java
index dec17623fc..c362e7497c 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheCGitCompatabilityTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheCGitCompatabilityTest.java
@@ -43,7 +43,7 @@
package org.eclipse.jgit.dircache;
-import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
import static org.eclipse.jgit.junit.Assert.assertEquals;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
@@ -99,7 +99,7 @@ public class DirCacheCGitCompatabilityTest extends LocalDiskRepositoryTestCase {
assertEquals(ls.size(), dc.getEntryCount());
{
final Iterator<CGitIndexRecord> rItr = ls.values().iterator();
- try (final TreeWalk tw = new TreeWalk(db)) {
+ try (TreeWalk tw = new TreeWalk(db)) {
tw.setRecursive(true);
tw.addTree(new DirCacheIterator(dc));
while (rItr.hasNext()) {
@@ -180,7 +180,7 @@ public class DirCacheCGitCompatabilityTest extends LocalDiskRepositoryTestCase {
assertEquals(cList.size(), jTree.getEntrySpan());
final ArrayList<CGitLsTreeRecord> subtrees = new ArrayList<>();
- for (final CGitLsTreeRecord r : cTree.values()) {
+ for (CGitLsTreeRecord r : cTree.values()) {
if (FileMode.TREE.equals(r.mode))
subtrees.add(r);
}
@@ -229,14 +229,14 @@ public class DirCacheCGitCompatabilityTest extends LocalDiskRepositoryTestCase {
assertEquals(intentToAdd, entry.isIntentToAdd());
}
- private static File pathOf(final String name) {
+ private static File pathOf(String name) {
return JGitTestUtil.getTestResourceFile(name);
}
private static Map<String, CGitIndexRecord> readLsFiles() throws Exception {
final LinkedHashMap<String, CGitIndexRecord> r = new LinkedHashMap<>();
try (BufferedReader br = new BufferedReader(new InputStreamReader(
- new FileInputStream(pathOf("gitgit.lsfiles")), UTF_8))) {
+ new FileInputStream(pathOf("gitgit.lsfiles")), CHARSET))) {
String line;
while ((line = br.readLine()) != null) {
final CGitIndexRecord cr = new CGitIndexRecord(line);
@@ -249,7 +249,7 @@ public class DirCacheCGitCompatabilityTest extends LocalDiskRepositoryTestCase {
private static Map<String, CGitLsTreeRecord> readLsTree() throws Exception {
final LinkedHashMap<String, CGitLsTreeRecord> r = new LinkedHashMap<>();
try (BufferedReader br = new BufferedReader(new InputStreamReader(
- new FileInputStream(pathOf("gitgit.lstree")), UTF_8))) {
+ new FileInputStream(pathOf("gitgit.lstree")), CHARSET))) {
String line;
while ((line = br.readLine()) != null) {
final CGitLsTreeRecord cr = new CGitLsTreeRecord(line);
@@ -268,7 +268,7 @@ public class DirCacheCGitCompatabilityTest extends LocalDiskRepositoryTestCase {
final String path;
- CGitIndexRecord(final String line) {
+ CGitIndexRecord(String line) {
final int tab = line.indexOf('\t');
final int sp1 = line.indexOf(' ');
final int sp2 = line.indexOf(' ', sp1 + 1);
@@ -286,7 +286,7 @@ public class DirCacheCGitCompatabilityTest extends LocalDiskRepositoryTestCase {
final String path;
- CGitLsTreeRecord(final String line) {
+ CGitLsTreeRecord(String line) {
final int tab = line.indexOf('\t');
final int sp1 = line.indexOf(' ');
final int sp2 = line.indexOf(' ', sp1 + 1);
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheEntryTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheEntryTest.java
index 05fa007904..86e2852872 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheEntryTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheEntryTest.java
@@ -183,7 +183,7 @@ public class DirCacheEntryTest {
copyMetaDataHelper(true);
}
- private static void copyMetaDataHelper(final boolean keepStage) {
+ private static void copyMetaDataHelper(boolean keepStage) {
DirCacheEntry e = new DirCacheEntry("some/path", DirCacheEntry.STAGE_2);
e.setAssumeValid(false);
e.setCreationTime(2L);
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheIteratorTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheIteratorTest.java
index dd242e5a1a..82565fceec 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheIteratorTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheIteratorTest.java
@@ -76,7 +76,7 @@ public class DirCacheIteratorTest extends RepositoryTestCase {
final DirCache dc = DirCache.newInCore();
assertEquals(0, dc.getEntryCount());
- try (final TreeWalk tw = new TreeWalk(db)) {
+ try (TreeWalk tw = new TreeWalk(db)) {
tw.addTree(new DirCacheIterator(dc));
assertFalse(tw.next());
}
@@ -126,7 +126,7 @@ public class DirCacheIteratorTest extends RepositoryTestCase {
b.finish();
final DirCacheIterator i = new DirCacheIterator(dc);
- try (final TreeWalk tw = new TreeWalk(db)) {
+ try (TreeWalk tw = new TreeWalk(db)) {
tw.addTree(i);
int pathIdx = 0;
while (tw.next()) {
@@ -164,7 +164,7 @@ public class DirCacheIteratorTest extends RepositoryTestCase {
final int expPos[] = { 0, -1, 4 };
final DirCacheIterator i = new DirCacheIterator(dc);
- try (final TreeWalk tw = new TreeWalk(db)) {
+ try (TreeWalk tw = new TreeWalk(db)) {
tw.addTree(i);
tw.setRecursive(false);
int pathIdx = 0;
@@ -205,7 +205,7 @@ public class DirCacheIteratorTest extends RepositoryTestCase {
b.finish();
final DirCacheIterator i = new DirCacheIterator(dc);
- try (final TreeWalk tw = new TreeWalk(db)) {
+ try (TreeWalk tw = new TreeWalk(db)) {
tw.addTree(i);
tw.setRecursive(true);
int pathIdx = 0;
@@ -240,7 +240,7 @@ public class DirCacheIteratorTest extends RepositoryTestCase {
b.add(ents[i]);
b.finish();
- try (final TreeWalk tw = new TreeWalk(db)) {
+ try (TreeWalk tw = new TreeWalk(db)) {
tw.addTree(new DirCacheIterator(dc));
tw.setRecursive(true);
int pathIdx = 0;
@@ -402,7 +402,7 @@ public class DirCacheIteratorTest extends RepositoryTestCase {
b.add(ents[i]);
b.finish();
- try (final TreeWalk tw = new TreeWalk(db)) {
+ try (TreeWalk tw = new TreeWalk(db)) {
for (int victimIdx = 0; victimIdx < paths.length; victimIdx++) {
tw.reset();
tw.addTree(new DirCacheIterator(dc));
@@ -430,7 +430,7 @@ public class DirCacheIteratorTest extends RepositoryTestCase {
final DirCache dc = DirCache.read(path, FS.DETECTED);
assertEquals(2, dc.getEntryCount());
- try (final TreeWalk tw = new TreeWalk(db)) {
+ try (TreeWalk tw = new TreeWalk(db)) {
tw.setRecursive(true);
tw.addTree(new DirCacheIterator(dc));
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheLargePathTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheLargePathTest.java
index ef3e61144d..dfc136ce26 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheLargePathTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheLargePathTest.java
@@ -81,7 +81,7 @@ public class DirCacheLargePathTest extends RepositoryTestCase {
testLongPath(16384);
}
- private void testLongPath(final int len) throws CorruptObjectException,
+ private void testLongPath(int len) throws CorruptObjectException,
IOException {
final String longPath = makeLongPath(len);
final String shortPath = "~~~ shorter-path";
@@ -119,7 +119,7 @@ public class DirCacheLargePathTest extends RepositoryTestCase {
}
}
- private static String makeLongPath(final int len) {
+ private static String makeLongPath(int len) {
final StringBuilder r = new StringBuilder(len);
for (int i = 0; i < len; i++)
r.append('a' + (i % 26));
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/ManifestParserTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/ManifestParserTest.java
index c9673a6882..69a48cc4b5 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/ManifestParserTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/ManifestParserTest.java
@@ -42,7 +42,7 @@
*/
package org.eclipse.jgit.gitrepo;
-import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -82,7 +82,7 @@ public class ManifestParserTest {
ManifestParser parser = new ManifestParser(
null, null, "master", baseUrl, null, null);
- parser.read(new ByteArrayInputStream(xmlContent.toString().getBytes(UTF_8)));
+ parser.read(new ByteArrayInputStream(xmlContent.toString().getBytes(CHARSET)));
// Unfiltered projects should have them all.
results.clear();
results.add("foo");
@@ -136,7 +136,7 @@ public class ManifestParserTest {
baseUrl, null, null);
try {
parser.read(new ByteArrayInputStream(
- xmlContent.toString().getBytes(UTF_8)));
+ xmlContent.toString().getBytes(CHARSET)));
fail("ManifestParser did not throw exception for missing fetch");
} catch (IOException e) {
assertTrue(e.getCause() instanceof SAXException);
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandSymlinkTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandSymlinkTest.java
index 341cc4f215..548b9033bc 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandSymlinkTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandSymlinkTest.java
@@ -119,45 +119,47 @@ public class RepoCommandSymlinkTest extends RepositoryTestCase {
.setURI(rootUri).call();
// Clone it
File directory = createTempDirectory("testCopyFileBare");
- Repository localDb = Git.cloneRepository().setDirectory(directory)
+ try (Repository localDb = Git.cloneRepository()
+ .setDirectory(directory)
.setURI(remoteDb.getDirectory().toURI().toString()).call()
- .getRepository();
+ .getRepository()) {
- // The LinkedHello symlink should exist.
- File linkedhello = new File(localDb.getWorkTree(), "LinkedHello");
- assertTrue("The LinkedHello file should exist",
- localDb.getFS().exists(linkedhello));
- assertTrue("The LinkedHello file should be a symlink",
- localDb.getFS().isSymLink(linkedhello));
- assertEquals("foo/hello.txt",
- localDb.getFS().readSymLink(linkedhello));
+ // The LinkedHello symlink should exist.
+ File linkedhello = new File(localDb.getWorkTree(),
+ "LinkedHello");
+ assertTrue("The LinkedHello file should exist",
+ localDb.getFS().exists(linkedhello));
+ assertTrue("The LinkedHello file should be a symlink",
+ localDb.getFS().isSymLink(linkedhello));
+ assertEquals("foo/hello.txt",
+ localDb.getFS().readSymLink(linkedhello));
- // The foo/LinkedHello file should be skipped.
- File linkedfoohello = new File(localDb.getWorkTree(), "foo/LinkedHello");
- assertFalse("The foo/LinkedHello file should be skipped",
- localDb.getFS().exists(linkedfoohello));
+ // The foo/LinkedHello file should be skipped.
+ File linkedfoohello = new File(localDb.getWorkTree(),
+ "foo/LinkedHello");
+ assertFalse("The foo/LinkedHello file should be skipped",
+ localDb.getFS().exists(linkedfoohello));
- // The subdir/LinkedHello file should use a relative ../
- File linkedsubdirhello = new File(localDb.getWorkTree(),
- "subdir/LinkedHello");
- assertTrue("The subdir/LinkedHello file should exist",
- localDb.getFS().exists(linkedsubdirhello));
- assertTrue("The subdir/LinkedHello file should be a symlink",
- localDb.getFS().isSymLink(linkedsubdirhello));
- assertEquals("../foo/hello.txt",
- localDb.getFS().readSymLink(linkedsubdirhello));
+ // The subdir/LinkedHello file should use a relative ../
+ File linkedsubdirhello = new File(localDb.getWorkTree(),
+ "subdir/LinkedHello");
+ assertTrue("The subdir/LinkedHello file should exist",
+ localDb.getFS().exists(linkedsubdirhello));
+ assertTrue("The subdir/LinkedHello file should be a symlink",
+ localDb.getFS().isSymLink(linkedsubdirhello));
+ assertEquals("../foo/hello.txt",
+ localDb.getFS().readSymLink(linkedsubdirhello));
- // The bar/foo/LinkedHello file should use a single relative ../
- File linkedbarfoohello = new File(localDb.getWorkTree(),
- "bar/foo/LinkedHello");
- assertTrue("The bar/foo/LinkedHello file should exist",
- localDb.getFS().exists(linkedbarfoohello));
- assertTrue("The bar/foo/LinkedHello file should be a symlink",
- localDb.getFS().isSymLink(linkedbarfoohello));
- assertEquals("../baz/hello.txt",
- localDb.getFS().readSymLink(linkedbarfoohello));
-
- localDb.close();
+ // The bar/foo/LinkedHello file should use a single relative ../
+ File linkedbarfoohello = new File(localDb.getWorkTree(),
+ "bar/foo/LinkedHello");
+ assertTrue("The bar/foo/LinkedHello file should exist",
+ localDb.getFS().exists(linkedbarfoohello));
+ assertTrue("The bar/foo/LinkedHello file should be a symlink",
+ localDb.getFS().isSymLink(linkedbarfoohello));
+ assertEquals("../baz/hello.txt",
+ localDb.getFS().readSymLink(linkedbarfoohello));
+ }
}
}
}
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 2253a0421f..df31ab0869 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
@@ -42,7 +42,7 @@
*/
package org.eclipse.jgit.gitrepo;
-import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
@@ -160,7 +160,7 @@ public class RepoCommandTest extends RepositoryTestCase {
Ref ref = r.findRef(refname);
if (ref == null) return null;
- ref = r.peel(ref);
+ ref = r.getRefDatabase().peel(ref);
ObjectId id = ref.getObjectId();
return id;
} catch (IOException e) {
@@ -185,108 +185,93 @@ public class RepoCommandTest extends RepositoryTestCase {
}
}
+ private Repository cloneRepository(Repository repo, boolean bare)
+ throws Exception {
+ Repository r = Git.cloneRepository()
+ .setURI(repo.getDirectory().toURI().toString())
+ .setDirectory(createUniqueTestGitDir(true)).setBare(bare).call()
+ .getRepository();
+ if (bare) {
+ assertTrue(r.isBare());
+ } else {
+ assertFalse(r.isBare());
+ }
+ return r;
+ }
+
@Test
public void runTwiceIsNOP() throws Exception {
- Repository child = Git.cloneRepository()
- .setURI(groupADb.getDirectory().toURI().toString())
- .setDirectory(createUniqueTestGitDir(true)).setBare(true).call()
- .getRepository();
-
- Repository dest = Git.cloneRepository()
- .setURI(db.getDirectory().toURI().toString())
- .setDirectory(createUniqueTestGitDir(true)).setBare(true).call()
- .getRepository();
+ try (Repository child = cloneRepository(groupADb, true);
+ Repository dest = cloneRepository(db, true)) {
+ StringBuilder xmlContent = new StringBuilder();
+ xmlContent.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
+ .append("<manifest>")
+ .append("<remote name=\"remote1\" fetch=\"..\" />")
+ .append("<default revision=\"master\" remote=\"remote1\" />")
+ .append("<project path=\"base\" name=\"platform/base\" />")
+ .append("</manifest>");
+ RepoCommand cmd = new RepoCommand(dest);
- assertTrue(dest.isBare());
- assertTrue(child.isBare());
+ IndexedRepos repos = new IndexedRepos();
+ repos.put("platform/base", child);
- StringBuilder xmlContent = new StringBuilder();
- xmlContent.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
- .append("<manifest>")
- .append("<remote name=\"remote1\" fetch=\"..\" />")
- .append("<default revision=\"master\" remote=\"remote1\" />")
- .append("<project path=\"base\" name=\"platform/base\" />")
- .append("</manifest>");
- RepoCommand cmd = new RepoCommand(dest);
-
- IndexedRepos repos = new IndexedRepos();
- repos.put("platform/base", child);
-
- RevCommit commit = cmd
- .setInputStream(new ByteArrayInputStream(
- xmlContent.toString().getBytes(UTF_8)))
- .setRemoteReader(repos)
- .setURI("platform/")
- .setTargetURI("platform/superproject")
- .setRecordRemoteBranch(true)
- .setRecordSubmoduleLabels(true)
- .call();
+ RevCommit commit = cmd
+ .setInputStream(new ByteArrayInputStream(
+ xmlContent.toString().getBytes(CHARSET)))
+ .setRemoteReader(repos).setURI("platform/")
+ .setTargetURI("platform/superproject")
+ .setRecordRemoteBranch(true).setRecordSubmoduleLabels(true)
+ .call();
- String firstIdStr = commit.getId().name() + ":" + ".gitmodules";
- commit = new RepoCommand(dest)
- .setInputStream(new ByteArrayInputStream(
- xmlContent.toString().getBytes(UTF_8)))
- .setRemoteReader(repos)
- .setURI("platform/")
- .setTargetURI("platform/superproject")
- .setRecordRemoteBranch(true)
- .setRecordSubmoduleLabels(true)
- .call();
- String idStr = commit.getId().name() + ":" + ".gitmodules";
- assertEquals(firstIdStr, idStr);
- child.close();
- dest.close();
+ String firstIdStr = commit.getId().name() + ":" + ".gitmodules";
+ commit = new RepoCommand(dest)
+ .setInputStream(new ByteArrayInputStream(
+ xmlContent.toString().getBytes(CHARSET)))
+ .setRemoteReader(repos).setURI("platform/")
+ .setTargetURI("platform/superproject")
+ .setRecordRemoteBranch(true).setRecordSubmoduleLabels(true)
+ .call();
+ String idStr = commit.getId().name() + ":" + ".gitmodules";
+ assertEquals(firstIdStr, idStr);
+ }
}
@Test
public void androidSetup() throws Exception {
- Repository child = Git.cloneRepository()
- .setURI(groupADb.getDirectory().toURI().toString())
- .setDirectory(createUniqueTestGitDir(true)).setBare(true).call()
- .getRepository();
-
- Repository dest = Git.cloneRepository()
- .setURI(db.getDirectory().toURI().toString())
- .setDirectory(createUniqueTestGitDir(true)).setBare(true).call()
- .getRepository();
+ try (Repository child = cloneRepository(groupADb, true);
+ Repository dest = cloneRepository(db, true)) {
+ StringBuilder xmlContent = new StringBuilder();
+ xmlContent.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
+ .append("<manifest>")
+ .append("<remote name=\"remote1\" fetch=\"..\" />")
+ .append("<default revision=\"master\" remote=\"remote1\" />")
+ .append("<project path=\"base\" name=\"platform/base\" />")
+ .append("</manifest>");
+ RepoCommand cmd = new RepoCommand(dest);
- assertTrue(dest.isBare());
- assertTrue(child.isBare());
+ IndexedRepos repos = new IndexedRepos();
+ repos.put("platform/base", child);
- StringBuilder xmlContent = new StringBuilder();
- xmlContent.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
- .append("<manifest>")
- .append("<remote name=\"remote1\" fetch=\"..\" />")
- .append("<default revision=\"master\" remote=\"remote1\" />")
- .append("<project path=\"base\" name=\"platform/base\" />")
- .append("</manifest>");
- RepoCommand cmd = new RepoCommand(dest);
-
- IndexedRepos repos = new IndexedRepos();
- repos.put("platform/base", child);
-
- RevCommit commit = cmd
- .setInputStream(new ByteArrayInputStream(xmlContent.toString().getBytes(UTF_8)))
- .setRemoteReader(repos)
- .setURI("platform/")
- .setTargetURI("platform/superproject")
- .setRecordRemoteBranch(true)
- .setRecordSubmoduleLabels(true)
- .call();
+ RevCommit commit = cmd
+ .setInputStream(new ByteArrayInputStream(
+ xmlContent.toString().getBytes(CHARSET)))
+ .setRemoteReader(repos).setURI("platform/")
+ .setTargetURI("platform/superproject")
+ .setRecordRemoteBranch(true).setRecordSubmoduleLabels(true)
+ .call();
- String idStr = commit.getId().name() + ":" + ".gitmodules";
- ObjectId modId = dest.resolve(idStr);
+ String idStr = commit.getId().name() + ":" + ".gitmodules";
+ ObjectId modId = dest.resolve(idStr);
- try (ObjectReader reader = dest.newObjectReader()) {
- byte[] bytes = reader.open(modId).getCachedBytes(Integer.MAX_VALUE);
- Config base = new Config();
- BlobBasedConfig cfg = new BlobBasedConfig(base, bytes);
- String subUrl = cfg.getString("submodule", "base", "url");
- assertEquals(subUrl, "../base");
+ try (ObjectReader reader = dest.newObjectReader()) {
+ byte[] bytes = reader.open(modId)
+ .getCachedBytes(Integer.MAX_VALUE);
+ Config base = new Config();
+ BlobBasedConfig cfg = new BlobBasedConfig(base, bytes);
+ String subUrl = cfg.getString("submodule", "base", "url");
+ assertEquals(subUrl, "../base");
+ }
}
-
- child.close();
- dest.close();
}
@Test
@@ -299,200 +284,174 @@ public class RepoCommandTest extends RepositoryTestCase {
.append("<project path=\"base\" name=\"platform/base\" />")
.append("</manifest>");
- Repository dest = Git.cloneRepository()
- .setURI(db.getDirectory().toURI().toString())
- .setDirectory(createUniqueTestGitDir(true)).setBare(true).call()
- .getRepository();
-
- assertTrue(dest.isBare());
-
- RevCommit commit = new RepoCommand(dest)
- .setInputStream(new ByteArrayInputStream(
- xmlContent.toString().getBytes(UTF_8)))
- .setRemoteReader(new IndexedRepos())
- .setURI("platform/")
- .setTargetURI("platform/superproject")
- .setRecordRemoteBranch(true)
- .setIgnoreRemoteFailures(true)
- .setRecordSubmoduleLabels(true)
- .call();
-
- String idStr = commit.getId().name() + ":" + ".gitmodules";
- ObjectId modId = dest.resolve(idStr);
-
- try (ObjectReader reader = dest.newObjectReader()) {
- byte[] bytes = reader.open(modId).getCachedBytes(Integer.MAX_VALUE);
- Config base = new Config();
- BlobBasedConfig cfg = new BlobBasedConfig(base, bytes);
- String subUrl = cfg.getString("submodule", "base", "url");
- assertEquals(subUrl, "https://host.com/platform/base");
+ try (Repository dest = cloneRepository(db, true)) {
+ RevCommit commit = new RepoCommand(dest)
+ .setInputStream(new ByteArrayInputStream(
+ xmlContent.toString().getBytes(CHARSET)))
+ .setRemoteReader(new IndexedRepos()).setURI("platform/")
+ .setTargetURI("platform/superproject")
+ .setRecordRemoteBranch(true).setIgnoreRemoteFailures(true)
+ .setRecordSubmoduleLabels(true).call();
+
+ String idStr = commit.getId().name() + ":" + ".gitmodules";
+ ObjectId modId = dest.resolve(idStr);
+
+ try (ObjectReader reader = dest.newObjectReader()) {
+ byte[] bytes = reader.open(modId)
+ .getCachedBytes(Integer.MAX_VALUE);
+ Config base = new Config();
+ BlobBasedConfig cfg = new BlobBasedConfig(base, bytes);
+ String subUrl = cfg.getString("submodule", "base", "url");
+ assertEquals(subUrl, "https://host.com/platform/base");
+ }
}
-
- dest.close();
}
@Test
public void gerritSetup() throws Exception {
- Repository child =
- Git.cloneRepository().setURI(groupADb.getDirectory().toURI().toString())
- .setDirectory(createUniqueTestGitDir(true))
- .setBare(true).call().getRepository();
-
- Repository dest = Git.cloneRepository()
- .setURI(db.getDirectory().toURI().toString()).setDirectory(createUniqueTestGitDir(true))
- .setBare(true).call().getRepository();
+ try (Repository child = cloneRepository(groupADb, true);
+ Repository dest = cloneRepository(db, true)) {
+ StringBuilder xmlContent = new StringBuilder();
+ xmlContent.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
+ .append("<manifest>")
+ .append("<remote name=\"remote1\" fetch=\".\" />")
+ .append("<default revision=\"master\" remote=\"remote1\" />")
+ .append("<project path=\"plugins/cookbook\" name=\"plugins/cookbook\" />")
+ .append("</manifest>");
+ RepoCommand cmd = new RepoCommand(dest);
- assertTrue(dest.isBare());
- assertTrue(child.isBare());
+ IndexedRepos repos = new IndexedRepos();
+ repos.put("plugins/cookbook", child);
- StringBuilder xmlContent = new StringBuilder();
- xmlContent.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
- .append("<manifest>")
- .append("<remote name=\"remote1\" fetch=\".\" />")
- .append("<default revision=\"master\" remote=\"remote1\" />")
- .append("<project path=\"plugins/cookbook\" name=\"plugins/cookbook\" />")
- .append("</manifest>");
- RepoCommand cmd = new RepoCommand(dest);
-
- IndexedRepos repos = new IndexedRepos();
- repos.put("plugins/cookbook", child);
-
- RevCommit commit = cmd
- .setInputStream(new ByteArrayInputStream(xmlContent.toString().getBytes(UTF_8)))
- .setRemoteReader(repos)
- .setURI("")
- .setTargetURI("gerrit")
- .setRecordRemoteBranch(true)
- .setRecordSubmoduleLabels(true)
- .call();
-
- String idStr = commit.getId().name() + ":" + ".gitmodules";
- ObjectId modId = dest.resolve(idStr);
+ RevCommit commit = cmd
+ .setInputStream(new ByteArrayInputStream(
+ xmlContent.toString().getBytes(CHARSET)))
+ .setRemoteReader(repos).setURI("").setTargetURI("gerrit")
+ .setRecordRemoteBranch(true).setRecordSubmoduleLabels(true)
+ .call();
- try (ObjectReader reader = dest.newObjectReader()) {
- byte[] bytes = reader.open(modId).getCachedBytes(Integer.MAX_VALUE);
- Config base = new Config();
- BlobBasedConfig cfg = new BlobBasedConfig(base, bytes);
- String subUrl = cfg.getString("submodule", "plugins/cookbook", "url");
- assertEquals(subUrl, "../plugins/cookbook");
+ String idStr = commit.getId().name() + ":" + ".gitmodules";
+ ObjectId modId = dest.resolve(idStr);
+
+ try (ObjectReader reader = dest.newObjectReader()) {
+ byte[] bytes = reader.open(modId)
+ .getCachedBytes(Integer.MAX_VALUE);
+ Config base = new Config();
+ BlobBasedConfig cfg = new BlobBasedConfig(base, bytes);
+ String subUrl = cfg.getString("submodule", "plugins/cookbook",
+ "url");
+ assertEquals(subUrl, "../plugins/cookbook");
+ }
}
-
- child.close();
- dest.close();
}
@Test
public void absoluteRemoteURL() throws Exception {
- Repository child =
- Git.cloneRepository().setURI(groupADb.getDirectory().toURI().toString())
- .setDirectory(createUniqueTestGitDir(true))
- .setBare(true).call().getRepository();
- Repository dest = Git.cloneRepository()
- .setURI(db.getDirectory().toURI().toString()).setDirectory(createUniqueTestGitDir(true))
- .setBare(true).call().getRepository();
- String abs = "https://chromium.googlesource.com";
- String repoUrl = "https://chromium.googlesource.com/chromium/src";
- boolean fetchSlash = false;
- boolean baseSlash = false;
- do {
+ try (Repository child = cloneRepository(groupADb, true);
+ Repository dest = cloneRepository(db, true)) {
+ String abs = "https://chromium.googlesource.com";
+ String repoUrl = "https://chromium.googlesource.com/chromium/src";
+ boolean fetchSlash = false;
+ boolean baseSlash = false;
do {
- String fetchUrl = fetchSlash ? abs + "/" : abs;
- String baseUrl = baseSlash ? abs + "/" : abs;
-
- StringBuilder xmlContent = new StringBuilder();
- xmlContent.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
- .append("<manifest>")
- .append("<remote name=\"origin\" fetch=\"" + fetchUrl + "\" />")
- .append("<default revision=\"master\" remote=\"origin\" />")
- .append("<project path=\"src\" name=\"chromium/src\" />")
- .append("</manifest>");
- RepoCommand cmd = new RepoCommand(dest);
-
- IndexedRepos repos = new IndexedRepos();
- repos.put(repoUrl, child);
-
- RevCommit commit = cmd
- .setInputStream(new ByteArrayInputStream(xmlContent.toString().getBytes(UTF_8)))
- .setRemoteReader(repos)
- .setURI(baseUrl)
- .setTargetURI("gerrit")
- .setRecordRemoteBranch(true)
- .setRecordSubmoduleLabels(true)
- .call();
-
- String idStr = commit.getId().name() + ":" + ".gitmodules";
- ObjectId modId = dest.resolve(idStr);
-
- try (ObjectReader reader = dest.newObjectReader()) {
- byte[] bytes = reader.open(modId).getCachedBytes(Integer.MAX_VALUE);
- Config base = new Config();
- BlobBasedConfig cfg = new BlobBasedConfig(base, bytes);
- String subUrl = cfg.getString("submodule", "src", "url");
- assertEquals("https://chromium.googlesource.com/chromium/src", subUrl);
- }
- fetchSlash = !fetchSlash;
- } while (fetchSlash);
- baseSlash = !baseSlash;
- } while (baseSlash);
- child.close();
- dest.close();
+ do {
+ String fetchUrl = fetchSlash ? abs + "/" : abs;
+ String baseUrl = baseSlash ? abs + "/" : abs;
+
+ StringBuilder xmlContent = new StringBuilder();
+ xmlContent.append(
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
+ .append("<manifest>")
+ .append("<remote name=\"origin\" fetch=\""
+ + fetchUrl + "\" />")
+ .append("<default revision=\"master\" remote=\"origin\" />")
+ .append("<project path=\"src\" name=\"chromium/src\" />")
+ .append("</manifest>");
+ RepoCommand cmd = new RepoCommand(dest);
+
+ IndexedRepos repos = new IndexedRepos();
+ repos.put(repoUrl, child);
+
+ RevCommit commit = cmd
+ .setInputStream(new ByteArrayInputStream(
+ xmlContent.toString().getBytes(CHARSET)))
+ .setRemoteReader(repos).setURI(baseUrl)
+ .setTargetURI("gerrit").setRecordRemoteBranch(true)
+ .setRecordSubmoduleLabels(true).call();
+
+ String idStr = commit.getId().name() + ":" + ".gitmodules";
+ ObjectId modId = dest.resolve(idStr);
+
+ try (ObjectReader reader = dest.newObjectReader()) {
+ byte[] bytes = reader.open(modId)
+ .getCachedBytes(Integer.MAX_VALUE);
+ Config base = new Config();
+ BlobBasedConfig cfg = new BlobBasedConfig(base, bytes);
+ String subUrl = cfg.getString("submodule", "src",
+ "url");
+ assertEquals(
+ "https://chromium.googlesource.com/chromium/src",
+ subUrl);
+ }
+ fetchSlash = !fetchSlash;
+ } while (fetchSlash);
+ baseSlash = !baseSlash;
+ } while (baseSlash);
+ }
}
@Test
public void absoluteRemoteURLAbsoluteTargetURL() throws Exception {
- Repository child =
- Git.cloneRepository().setURI(groupADb.getDirectory().toURI().toString())
- .setDirectory(createUniqueTestGitDir(true))
- .setBare(true).call().getRepository();
- Repository dest = Git.cloneRepository()
- .setURI(db.getDirectory().toURI().toString()).setDirectory(createUniqueTestGitDir(true))
- .setBare(true).call().getRepository();
- String abs = "https://chromium.googlesource.com";
- String repoUrl = "https://chromium.googlesource.com/chromium/src";
- boolean fetchSlash = false;
- boolean baseSlash = false;
- do {
+ try (Repository child = cloneRepository(groupADb, true);
+ Repository dest = cloneRepository(db, true)) {
+ String abs = "https://chromium.googlesource.com";
+ String repoUrl = "https://chromium.googlesource.com/chromium/src";
+ boolean fetchSlash = false;
+ boolean baseSlash = false;
do {
- String fetchUrl = fetchSlash ? abs + "/" : abs;
- String baseUrl = baseSlash ? abs + "/" : abs;
-
- StringBuilder xmlContent = new StringBuilder();
- xmlContent.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
- .append("<manifest>")
- .append("<remote name=\"origin\" fetch=\"" + fetchUrl + "\" />")
- .append("<default revision=\"master\" remote=\"origin\" />")
- .append("<project path=\"src\" name=\"chromium/src\" />")
- .append("</manifest>");
- RepoCommand cmd = new RepoCommand(dest);
-
- IndexedRepos repos = new IndexedRepos();
- repos.put(repoUrl, child);
-
- RevCommit commit = cmd
- .setInputStream(new ByteArrayInputStream(xmlContent.toString().getBytes(UTF_8)))
- .setRemoteReader(repos)
- .setURI(baseUrl)
- .setTargetURI(abs + "/superproject")
- .setRecordRemoteBranch(true)
- .setRecordSubmoduleLabels(true)
- .call();
-
- String idStr = commit.getId().name() + ":" + ".gitmodules";
- ObjectId modId = dest.resolve(idStr);
-
- try (ObjectReader reader = dest.newObjectReader()) {
- byte[] bytes = reader.open(modId).getCachedBytes(Integer.MAX_VALUE);
- Config base = new Config();
- BlobBasedConfig cfg = new BlobBasedConfig(base, bytes);
- String subUrl = cfg.getString("submodule", "src", "url");
- assertEquals("../chromium/src", subUrl);
- }
- fetchSlash = !fetchSlash;
- } while (fetchSlash);
- baseSlash = !baseSlash;
- } while (baseSlash);
- child.close();
- dest.close();
+ do {
+ String fetchUrl = fetchSlash ? abs + "/" : abs;
+ String baseUrl = baseSlash ? abs + "/" : abs;
+
+ StringBuilder xmlContent = new StringBuilder();
+ xmlContent.append(
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
+ .append("<manifest>")
+ .append("<remote name=\"origin\" fetch=\""
+ + fetchUrl + "\" />")
+ .append("<default revision=\"master\" remote=\"origin\" />")
+ .append("<project path=\"src\" name=\"chromium/src\" />")
+ .append("</manifest>");
+ RepoCommand cmd = new RepoCommand(dest);
+
+ IndexedRepos repos = new IndexedRepos();
+ repos.put(repoUrl, child);
+
+ RevCommit commit = cmd
+ .setInputStream(new ByteArrayInputStream(
+ xmlContent.toString().getBytes(CHARSET)))
+ .setRemoteReader(repos).setURI(baseUrl)
+ .setTargetURI(abs + "/superproject")
+ .setRecordRemoteBranch(true)
+ .setRecordSubmoduleLabels(true).call();
+
+ String idStr = commit.getId().name() + ":" + ".gitmodules";
+ ObjectId modId = dest.resolve(idStr);
+
+ try (ObjectReader reader = dest.newObjectReader()) {
+ byte[] bytes = reader.open(modId)
+ .getCachedBytes(Integer.MAX_VALUE);
+ Config base = new Config();
+ BlobBasedConfig cfg = new BlobBasedConfig(base, bytes);
+ String subUrl = cfg.getString("submodule", "src",
+ "url");
+ assertEquals("../chromium/src", subUrl);
+ }
+ fetchSlash = !fetchSlash;
+ } while (fetchSlash);
+ baseSlash = !baseSlash;
+ } while (baseSlash);
+ }
}
@Test
@@ -513,11 +472,12 @@ public class RepoCommandTest extends RepositoryTestCase {
.call();
File hello = new File(db.getWorkTree(), "foo/hello.txt");
assertTrue("submodule should be checked out", hello.exists());
- BufferedReader reader = new BufferedReader(new FileReader(hello));
- String content = reader.readLine();
- reader.close();
- assertEquals("submodule content should be as expected",
- "master world", content);
+ try (BufferedReader reader = new BufferedReader(
+ new FileReader(hello))) {
+ String content = reader.readLine();
+ assertEquals("submodule content should be as expected",
+ "master world", content);
+ }
}
@Test
@@ -603,19 +563,21 @@ public class RepoCommandTest extends RepositoryTestCase {
// The original file should exist
File hello = new File(localDb.getWorkTree(), "foo/hello.txt");
assertTrue("The original file should exist", hello.exists());
- BufferedReader reader = new BufferedReader(new FileReader(hello));
- String content = reader.readLine();
- reader.close();
- assertEquals("The original file should have expected content",
- "master world", content);
+ try (BufferedReader reader = new BufferedReader(
+ new FileReader(hello))) {
+ String content = reader.readLine();
+ assertEquals("The original file should have expected content",
+ "master world", content);
+ }
// The dest file should also exist
hello = new File(localDb.getWorkTree(), "Hello");
assertTrue("The destination file should exist", hello.exists());
- reader = new BufferedReader(new FileReader(hello));
- content = reader.readLine();
- reader.close();
- assertEquals("The destination file should have expected content",
- "master world", content);
+ try (BufferedReader reader = new BufferedReader(
+ new FileReader(hello))) {
+ String content = reader.readLine();
+ assertEquals("The destination file should have expected content",
+ "master world", content);
+ }
}
@Test
@@ -638,24 +600,27 @@ public class RepoCommandTest extends RepositoryTestCase {
.setURI(rootUri).call();
// Clone it
File directory = createTempDirectory("testBareRepo");
- Repository localDb = Git.cloneRepository().setDirectory(directory)
+ try (Repository localDb = Git.cloneRepository().setDirectory(directory)
.setURI(remoteDb.getDirectory().toURI().toString()).call()
- .getRepository();
- // The .gitmodules file should exist
- File gitmodules = new File(localDb.getWorkTree(), ".gitmodules");
- assertTrue("The .gitmodules file should exist", gitmodules.exists());
- // The first line of .gitmodules file should be expected
- BufferedReader reader = new BufferedReader(new FileReader(gitmodules));
- String content = reader.readLine();
- reader.close();
- assertEquals("The first line of .gitmodules file should be as expected",
- "[submodule \"foo\"]", content);
- // The gitlink should be the same as remote head sha1
- String gitlink = localDb.resolve(Constants.HEAD + ":foo").name();
- localDb.close();
- String remote = defaultDb.resolve(Constants.HEAD).name();
- assertEquals("The gitlink should be the same as remote head", remote,
- gitlink);
+ .getRepository()) {
+ // The .gitmodules file should exist
+ File gitmodules = new File(localDb.getWorkTree(), ".gitmodules");
+ assertTrue("The .gitmodules file should exist",
+ gitmodules.exists());
+ // The first line of .gitmodules file should be expected
+ try (BufferedReader reader = new BufferedReader(
+ new FileReader(gitmodules))) {
+ String content = reader.readLine();
+ assertEquals(
+ "The first line of .gitmodules file should be as expected",
+ "[submodule \"foo\"]", content);
+ }
+ // The gitlink should be the same as remote head sha1
+ String gitlink = localDb.resolve(Constants.HEAD + ":foo").name();
+ String remote = defaultDb.resolve(Constants.HEAD).name();
+ assertEquals("The gitlink should be the same as remote head",
+ remote, gitlink);
+ }
}
@Test
@@ -677,11 +642,12 @@ public class RepoCommandTest extends RepositoryTestCase {
.setURI(rootUri)
.call();
File hello = new File(db.getWorkTree(), "foo/hello.txt");
- BufferedReader reader = new BufferedReader(new FileReader(hello));
- String content = reader.readLine();
- reader.close();
- assertEquals("submodule content should be as expected",
- "branch world", content);
+ try (BufferedReader reader = new BufferedReader(
+ new FileReader(hello))) {
+ String content = reader.readLine();
+ assertEquals("submodule content should be as expected",
+ "branch world", content);
+ }
}
@Test
@@ -703,11 +669,12 @@ public class RepoCommandTest extends RepositoryTestCase {
.setURI(rootUri)
.call();
File hello = new File(db.getWorkTree(), "foo/hello.txt");
- BufferedReader reader = new BufferedReader(new FileReader(hello));
- String content = reader.readLine();
- reader.close();
- assertEquals("submodule content should be as expected",
- "branch world", content);
+ try (BufferedReader reader = new BufferedReader(
+ new FileReader(hello))) {
+ String content = reader.readLine();
+ assertEquals("submodule content should be as expected",
+ "branch world", content);
+ }
}
@Test
@@ -729,11 +696,12 @@ public class RepoCommandTest extends RepositoryTestCase {
.setURI(rootUri)
.call();
File hello = new File(db.getWorkTree(), "foo/hello.txt");
- BufferedReader reader = new BufferedReader(new FileReader(hello));
- String content = reader.readLine();
- reader.close();
- assertEquals("submodule content should be as expected",
- "branch world", content);
+ try (BufferedReader reader = new BufferedReader(
+ new FileReader(hello))) {
+ String content = reader.readLine();
+ assertEquals("submodule content should be as expected",
+ "branch world", content);
+ }
}
@Test
@@ -757,14 +725,14 @@ public class RepoCommandTest extends RepositoryTestCase {
.setURI(rootUri).call();
// Clone it
File directory = createTempDirectory("testRevisionBare");
- Repository localDb = Git.cloneRepository().setDirectory(directory)
+ try (Repository localDb = Git.cloneRepository().setDirectory(directory)
.setURI(remoteDb.getDirectory().toURI().toString()).call()
- .getRepository();
- // The gitlink should be the same as oldCommitId
- String gitlink = localDb.resolve(Constants.HEAD + ":foo").name();
- localDb.close();
- assertEquals("The gitlink is same as remote head", oldCommitId.name(),
- gitlink);
+ .getRepository()) {
+ // The gitlink should be the same as oldCommitId
+ String gitlink = localDb.resolve(Constants.HEAD + ":foo").name();
+ assertEquals("The gitlink is same as remote head",
+ oldCommitId.name(), gitlink);
+ }
}
@Test
@@ -790,22 +758,24 @@ public class RepoCommandTest extends RepositoryTestCase {
.setURI(rootUri).call();
// Clone it
File directory = createTempDirectory("testCopyFileBare");
- Repository localDb = Git.cloneRepository().setDirectory(directory)
+ try (Repository localDb = Git.cloneRepository().setDirectory(directory)
.setURI(remoteDb.getDirectory().toURI().toString()).call()
- .getRepository();
- // The Hello file should exist
- File hello = new File(localDb.getWorkTree(), "Hello");
- assertTrue("The Hello file should exist", hello.exists());
- // The foo/Hello file should be skipped.
- File foohello = new File(localDb.getWorkTree(), "foo/Hello");
- assertFalse("The foo/Hello file should be skipped", foohello.exists());
- localDb.close();
- // The content of Hello file should be expected
- BufferedReader reader = new BufferedReader(new FileReader(hello));
- String content = reader.readLine();
- reader.close();
- assertEquals("The Hello file should have expected content",
- "branch world", content);
+ .getRepository()) {
+ // The Hello file should exist
+ File hello = new File(localDb.getWorkTree(), "Hello");
+ assertTrue("The Hello file should exist", hello.exists());
+ // The foo/Hello file should be skipped.
+ File foohello = new File(localDb.getWorkTree(), "foo/Hello");
+ assertFalse("The foo/Hello file should be skipped",
+ foohello.exists());
+ // The content of Hello file should be expected
+ try (BufferedReader reader = new BufferedReader(
+ new FileReader(hello))) {
+ String content = reader.readLine();
+ assertEquals("The Hello file should have expected content",
+ "branch world", content);
+ }
+ }
}
@Test
@@ -841,36 +811,38 @@ public class RepoCommandTest extends RepositoryTestCase {
.setURI(rootUri).call();
// Clone it
File directory = createTempDirectory("testReplaceManifestBare");
- Repository localDb = Git.cloneRepository().setDirectory(directory)
+ File dotmodules;
+ try (Repository localDb = Git.cloneRepository().setDirectory(directory)
.setURI(remoteDb.getDirectory().toURI().toString()).call()
- .getRepository();
- // The Hello file should not exist
- File hello = new File(localDb.getWorkTree(), "Hello");
- assertFalse("The Hello file shouldn't exist", hello.exists());
- // The Hello.txt file should exist
- File hellotxt = new File(localDb.getWorkTree(), "Hello.txt");
- assertTrue("The Hello.txt file should exist", hellotxt.exists());
+ .getRepository()) {
+ // The Hello file should not exist
+ File hello = new File(localDb.getWorkTree(), "Hello");
+ assertFalse("The Hello file shouldn't exist", hello.exists());
+ // The Hello.txt file should exist
+ File hellotxt = new File(localDb.getWorkTree(), "Hello.txt");
+ assertTrue("The Hello.txt file should exist", hellotxt.exists());
+ dotmodules = new File(localDb.getWorkTree(),
+ Constants.DOT_GIT_MODULES);
+ }
// The .gitmodules file should have 'submodule "bar"' and shouldn't
// have
// 'submodule "foo"' lines.
- File dotmodules = new File(localDb.getWorkTree(),
- Constants.DOT_GIT_MODULES);
- localDb.close();
- BufferedReader reader = new BufferedReader(new FileReader(dotmodules));
- boolean foo = false;
- boolean bar = false;
- while (true) {
- String line = reader.readLine();
- if (line == null)
- break;
- if (line.contains("submodule \"foo\""))
- foo = true;
- if (line.contains("submodule \"bar\""))
- bar = true;
+ try (BufferedReader reader = new BufferedReader(
+ new FileReader(dotmodules))) {
+ boolean foo = false;
+ boolean bar = false;
+ while (true) {
+ String line = reader.readLine();
+ if (line == null)
+ break;
+ if (line.contains("submodule \"foo\""))
+ foo = true;
+ if (line.contains("submodule \"bar\""))
+ bar = true;
+ }
+ assertTrue("The bar submodule should exist", bar);
+ assertFalse("The foo submodule shouldn't exist", foo);
}
- reader.close();
- assertTrue("The bar submodule should exist", bar);
- assertFalse("The foo submodule shouldn't exist", foo);
}
@Test
@@ -896,34 +868,37 @@ public class RepoCommandTest extends RepositoryTestCase {
.setURI(rootUri).call();
// Clone it
File directory = createTempDirectory("testRemoveOverlappingBare");
- Repository localDb = Git.cloneRepository().setDirectory(directory)
+ File dotmodules;
+ try (Repository localDb = Git.cloneRepository().setDirectory(directory)
.setURI(remoteDb.getDirectory().toURI().toString()).call()
- .getRepository();
+ .getRepository()) {
+ dotmodules = new File(localDb.getWorkTree(),
+ Constants.DOT_GIT_MODULES);
+ }
+
// The .gitmodules file should have 'submodule "foo"' and shouldn't
// have
// 'submodule "foo/bar"' lines.
- File dotmodules = new File(localDb.getWorkTree(),
- Constants.DOT_GIT_MODULES);
- localDb.close();
- BufferedReader reader = new BufferedReader(new FileReader(dotmodules));
- boolean foo = false;
- boolean foobar = false;
- boolean a = false;
- while (true) {
- String line = reader.readLine();
- if (line == null)
- break;
- if (line.contains("submodule \"foo\""))
- foo = true;
- if (line.contains("submodule \"foo/bar\""))
- foobar = true;
- if (line.contains("submodule \"a\""))
- a = true;
+ try (BufferedReader reader = new BufferedReader(
+ new FileReader(dotmodules))) {
+ boolean foo = false;
+ boolean foobar = false;
+ boolean a = false;
+ while (true) {
+ String line = reader.readLine();
+ if (line == null)
+ break;
+ if (line.contains("submodule \"foo\""))
+ foo = true;
+ if (line.contains("submodule \"foo/bar\""))
+ foobar = true;
+ if (line.contains("submodule \"a\""))
+ a = true;
+ }
+ assertTrue("The foo submodule should exist", foo);
+ assertFalse("The foo/bar submodule shouldn't exist", foobar);
+ assertTrue("The a submodule should exist", a);
}
- reader.close();
- assertTrue("The foo submodule should exist", foo);
- assertFalse("The foo/bar submodule shouldn't exist", foobar);
- assertTrue("The a submodule should exist", a);
}
@Test
@@ -959,11 +934,12 @@ public class RepoCommandTest extends RepositoryTestCase {
.call();
File hello = new File(localDb.getWorkTree(), "foo/hello.txt");
assertTrue("submodule should be checked out", hello.exists());
- BufferedReader reader = new BufferedReader(new FileReader(hello));
- String content = reader.readLine();
- reader.close();
- assertEquals("submodule content should be as expected",
- "master world", content);
+ try (BufferedReader reader = new BufferedReader(
+ new FileReader(hello))) {
+ String content = reader.readLine();
+ assertEquals("submodule content should be as expected",
+ "master world", content);
+ }
}
@Test
public void testRemoteAlias() throws Exception {
@@ -1165,11 +1141,12 @@ public class RepoCommandTest extends RepositoryTestCase {
.setURI(rootUri)
.call();
File hello = new File(db.getWorkTree(), "foo/hello.txt");
- BufferedReader reader = new BufferedReader(new FileReader(hello));
- String content = reader.readLine();
- reader.close();
- assertEquals("submodule content should be as expected",
- "branch world", content);
+ try (BufferedReader reader = new BufferedReader(
+ new FileReader(hello))) {
+ String content = reader.readLine();
+ assertEquals("submodule content should be as expected",
+ "branch world", content);
+ }
}
@Test
@@ -1191,11 +1168,12 @@ public class RepoCommandTest extends RepositoryTestCase {
.setURI(rootUri)
.call();
File hello = new File(db.getWorkTree(), "foo/hello.txt");
- BufferedReader reader = new BufferedReader(new FileReader(hello));
- String content = reader.readLine();
- reader.close();
- assertEquals("submodule content should be as expected",
- "branch world", content);
+ try (BufferedReader reader = new BufferedReader(
+ new FileReader(hello))) {
+ String content = reader.readLine();
+ assertEquals("submodule content should be as expected",
+ "branch world", content);
+ }
}
private void resolveRelativeUris() {
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/CGitIgnoreTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/CGitIgnoreTest.java
index 3b11616fe6..0c6ed0c19e 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/CGitIgnoreTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/CGitIgnoreTest.java
@@ -141,7 +141,9 @@ public class CGitIgnoreTest extends RepositoryTestCase {
// Do a tree walk that does descend into ignored directories and return
// a list of all ignored files
try (TreeWalk walk = new TreeWalk(db)) {
- walk.addTree(new FileTreeIterator(db));
+ FileTreeIterator iter = new FileTreeIterator(db);
+ iter.setWalkIgnoredDirectories(true);
+ walk.addTree(iter);
walk.setRecursive(true);
while (walk.next()) {
if (walk.getTree(WorkingTreeIterator.class).isEntryIgnored()) {
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/IgnoreNodeTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/IgnoreNodeTest.java
index ccc64fb468..78d9a82c24 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/IgnoreNodeTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/IgnoreNodeTest.java
@@ -42,7 +42,7 @@
*/
package org.eclipse.jgit.ignore;
-import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
import static org.eclipse.jgit.junit.Assert.assertEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -56,7 +56,6 @@ import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
-import org.eclipse.jgit.ignore.IgnoreNode.MatchResult;
import org.eclipse.jgit.junit.RepositoryTestCase;
import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.treewalk.FileTreeIterator;
@@ -546,19 +545,6 @@ public class IgnoreNodeTest extends RepositoryTestCase {
endWalk();
}
- @SuppressWarnings("deprecation")
- @Test
- public void testEmptyIgnoreNode() {
- // Rules are never empty: WorkingTreeIterator optimizes empty files away
- // So we have to test it manually in case third party clients use
- // IgnoreNode directly.
- IgnoreNode node = new IgnoreNode();
- assertEquals(MatchResult.CHECK_PARENT, node.isIgnored("", false));
- assertEquals(MatchResult.CHECK_PARENT, node.isIgnored("", false, false));
- assertEquals(MatchResult.CHECK_PARENT_NEGATE_FIRST_MATCH,
- node.isIgnored("", false, true));
- }
-
@Test
public void testEmptyIgnoreRules() throws IOException {
IgnoreNode node = new IgnoreNode();
@@ -746,7 +732,9 @@ public class IgnoreNodeTest extends RepositoryTestCase {
private void beginWalk() {
walk = new TreeWalk(db);
- walk.addTree(new FileTreeIterator(db));
+ FileTreeIterator iter = new FileTreeIterator(db);
+ iter.setWalkIgnoredDirectories(true);
+ walk.addTree(iter);
}
private void endWalk() throws IOException {
@@ -779,6 +767,6 @@ public class IgnoreNodeTest extends RepositoryTestCase {
for (String line : rules) {
data.append(line + "\n");
}
- return new ByteArrayInputStream(data.toString().getBytes(UTF_8));
+ return new ByteArrayInputStream(data.toString().getBytes(CHARSET));
}
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/indexdiff/IndexDiffWithSymlinkTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/indexdiff/IndexDiffWithSymlinkTest.java
index d5d3857ca4..26c11c7eb7 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/indexdiff/IndexDiffWithSymlinkTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/indexdiff/IndexDiffWithSymlinkTest.java
@@ -41,7 +41,7 @@
*/
package org.eclipse.jgit.indexdiff;
-import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@@ -128,7 +128,7 @@ public class IndexDiffWithSymlinkTest extends LocalDiskRepositoryTestCase {
File restoreScript = new File(testDir, name + ".sh");
try (OutputStream out = new BufferedOutputStream(
new FileOutputStream(restoreScript));
- Writer writer = new OutputStreamWriter(out, UTF_8)) {
+ Writer writer = new OutputStreamWriter(out, CHARSET)) {
writer.write("echo `which git` 1>&2\n");
writer.write("echo `git --version` 1>&2\n");
writer.write("git init " + name + " && \\\n");
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ConcurrentRepackTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ConcurrentRepackTest.java
index 4813d28017..643daa5c95 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ConcurrentRepackTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ConcurrentRepackTest.java
@@ -210,17 +210,17 @@ public class ConcurrentRepackTest extends RepositoryTestCase {
config.install();
}
- private RevObject parse(final AnyObjectId id)
+ private RevObject parse(AnyObjectId id)
throws MissingObjectException, IOException {
try (RevWalk rw = new RevWalk(db)) {
return rw.parseAny(id);
}
}
- private File[] pack(final Repository src, final RevObject... list)
+ private File[] pack(Repository src, RevObject... list)
throws IOException {
try (PackWriter pw = new PackWriter(src)) {
- for (final RevObject o : list) {
+ for (RevObject o : list) {
pw.addObject(o);
}
@@ -233,7 +233,7 @@ public class ConcurrentRepackTest extends RepositoryTestCase {
}
}
- private static void write(final File[] files, final PackWriter pw)
+ private static void write(File[] files, PackWriter pw)
throws IOException {
final long begin = files[0].getParentFile().lastModified();
NullProgressMonitor m = NullProgressMonitor.INSTANCE;
@@ -251,16 +251,16 @@ public class ConcurrentRepackTest extends RepositoryTestCase {
touch(begin, files[0].getParentFile());
}
- private static void delete(final File[] list) throws IOException {
+ private static void delete(File[] list) throws IOException {
final long begin = list[0].getParentFile().lastModified();
- for (final File f : list) {
+ for (File f : list) {
FileUtils.delete(f);
assertFalse(f + " was removed", f.exists());
}
touch(begin, list[0].getParentFile());
}
- private static void touch(final long begin, final File dir) {
+ private static void touch(long begin, File dir) {
while (begin >= dir.lastModified()) {
try {
Thread.sleep(25);
@@ -271,12 +271,12 @@ public class ConcurrentRepackTest extends RepositoryTestCase {
}
}
- private File fullPackFileName(final ObjectId name, final String suffix) {
+ private File fullPackFileName(ObjectId name, String suffix) {
final File packdir = db.getObjectDatabase().getPackDirectory();
return new File(packdir, "pack-" + name.name() + suffix);
}
- private RevObject writeBlob(final Repository repo, final String data)
+ private RevObject writeBlob(Repository repo, String data)
throws IOException {
final byte[] bytes = Constants.encode(data);
final ObjectId id;
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackFileTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackFileTest.java
index 91bd523975..04fccf3561 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackFileTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackFileTest.java
@@ -146,15 +146,15 @@ public class PackFileTest extends LocalDiskRepositoryTestCase {
assertFalse("is not large", ol.isLarge());
assertTrue("same content", Arrays.equals(data, ol.getCachedBytes()));
- ObjectStream in = ol.openStream();
- assertNotNull("have stream", in);
- assertEquals(type, in.getType());
- assertEquals(data.length, in.getSize());
- byte[] data2 = new byte[data.length];
- IO.readFully(in, data2, 0, data.length);
- assertTrue("same content", Arrays.equals(data2, data));
- assertEquals("stream at EOF", -1, in.read());
- in.close();
+ try (ObjectStream in = ol.openStream()) {
+ assertNotNull("have stream", in);
+ assertEquals(type, in.getType());
+ assertEquals(data.length, in.getSize());
+ byte[] data2 = new byte[data.length];
+ IO.readFully(in, data2, 0, data.length);
+ assertTrue("same content", Arrays.equals(data2, data));
+ assertEquals("stream at EOF", -1, in.read());
+ }
}
@Test
@@ -180,15 +180,15 @@ public class PackFileTest extends LocalDiskRepositoryTestCase {
.getMessage());
}
- ObjectStream in = ol.openStream();
- assertNotNull("have stream", in);
- assertEquals(type, in.getType());
- assertEquals(data.length, in.getSize());
- byte[] data2 = new byte[data.length];
- IO.readFully(in, data2, 0, data.length);
- assertTrue("same content", Arrays.equals(data2, data));
- assertEquals("stream at EOF", -1, in.read());
- in.close();
+ try (ObjectStream in = ol.openStream()) {
+ assertNotNull("have stream", in);
+ assertEquals(type, in.getType());
+ assertEquals(data.length, in.getSize());
+ byte[] data2 = new byte[data.length];
+ IO.readFully(in, data2, 0, data.length);
+ assertTrue("same content", Arrays.equals(data2, data));
+ assertEquals("stream at EOF", -1, in.read());
+ }
}
@Test
@@ -239,15 +239,15 @@ public class PackFileTest extends LocalDiskRepositoryTestCase {
assertNotNull(ol.getCachedBytes());
assertArrayEquals(data3, ol.getCachedBytes());
- ObjectStream in = ol.openStream();
- assertNotNull("have stream", in);
- assertEquals(Constants.OBJ_BLOB, in.getType());
- assertEquals(data3.length, in.getSize());
- byte[] act = new byte[data3.length];
- IO.readFully(in, act, 0, data3.length);
- assertTrue("same content", Arrays.equals(act, data3));
- assertEquals("stream at EOF", -1, in.read());
- in.close();
+ try (ObjectStream in = ol.openStream()) {
+ assertNotNull("have stream", in);
+ assertEquals(Constants.OBJ_BLOB, in.getType());
+ assertEquals(data3.length, in.getSize());
+ byte[] act = new byte[data3.length];
+ IO.readFully(in, act, 0, data3.length);
+ assertTrue("same content", Arrays.equals(act, data3));
+ assertEquals("stream at EOF", -1, in.read());
+ }
}
}
@@ -282,22 +282,16 @@ public class PackFileTest extends LocalDiskRepositoryTestCase {
File packName = new File(dir, idA.name() + ".pack");
File idxName = new File(dir, idA.name() + ".idx");
- FileOutputStream f = new FileOutputStream(packName);
- try {
+ try (FileOutputStream f = new FileOutputStream(packName)) {
f.write(pack.toByteArray());
- } finally {
- f.close();
}
- f = new FileOutputStream(idxName);
- try {
+ try (FileOutputStream f = new FileOutputStream(idxName)) {
List<PackedObjectInfo> list = new ArrayList<>();
list.add(a);
list.add(b);
Collections.sort(list);
new PackIndexWriterV1(f).write(list, footer);
- } finally {
- f.close();
}
PackFile packFile = new PackFile(packName, PackExt.INDEX.getBit());
@@ -321,16 +315,17 @@ public class PackFileTest extends LocalDiskRepositoryTestCase {
assertTrue("has blob", wc.has(id));
ObjectLoader ol = wc.open(id);
- ObjectStream in = ol.openStream();
- assertTrue(in instanceof ObjectStream.SmallStream);
- assertEquals(300, in.available());
- in.close();
+ try (ObjectStream in = ol.openStream()) {
+ assertTrue(in instanceof ObjectStream.SmallStream);
+ assertEquals(300, in.available());
+ }
wc.setStreamFileThreshold(299);
ol = wc.open(id);
- in = ol.openStream();
- assertTrue(in instanceof ObjectStream.Filter);
- assertEquals(1, in.available());
+ try (ObjectStream in = ol.openStream()) {
+ assertTrue(in instanceof ObjectStream.Filter);
+ assertEquals(1, in.available());
+ }
}
private static byte[] clone(int first, byte[] base) {
@@ -372,7 +367,7 @@ public class PackFileTest extends LocalDiskRepositoryTestCase {
pack.write(buf, 0, n);
}
- private static void deflate(TemporaryBuffer.Heap pack, final byte[] content)
+ private static void deflate(TemporaryBuffer.Heap pack, byte[] content)
throws IOException {
final Deflater deflater = new Deflater();
final byte[] buf = new byte[128];
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackWriterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackWriterTest.java
index 379432ddbb..04bed09af3 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackWriterTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackWriterTest.java
@@ -368,7 +368,7 @@ public class PackWriterTest extends SampleDataRepositoryTestCase {
ObjectId.fromString("902d5476fa249b7abc9d84c611577a81381f0327"),
ObjectId.fromString("6ff87c4664981e4397625791c8ea3bbb5f2279a3") ,
ObjectId.fromString("5b6e7c66c276e7610d4a73c70ec1a1f7c1003259") };
- try (final RevWalk parser = new RevWalk(db)) {
+ try (RevWalk parser = new RevWalk(db)) {
final RevObject forcedOrderRevs[] = new RevObject[forcedOrder.length];
for (int i = 0; i < forcedOrder.length; i++)
forcedOrderRevs[i] = parser.parseAny(forcedOrder[i]);
@@ -515,11 +515,8 @@ public class PackWriterTest extends SampleDataRepositoryTestCase {
// Validate that an index written by PackWriter is the same.
final File idx2File = new File(indexFile.getAbsolutePath() + ".2");
- final FileOutputStream is = new FileOutputStream(idx2File);
- try {
+ try (FileOutputStream is = new FileOutputStream(idx2File)) {
writer.writeIndex(is);
- } finally {
- is.close();
}
final PackIndex idx2 = PackIndex.open(idx2File);
assertTrue(idx2 instanceof PackIndexV2);
@@ -715,14 +712,14 @@ public class PackWriterTest extends SampleDataRepositoryTestCase {
String id = pw.computeName().getName();
File packdir = repo.getObjectDatabase().getPackDirectory();
File packFile = new File(packdir, "pack-" + id + ".pack");
- FileOutputStream packOS = new FileOutputStream(packFile);
- pw.writePack(NullProgressMonitor.INSTANCE,
- NullProgressMonitor.INSTANCE, packOS);
- packOS.close();
+ try (FileOutputStream packOS = new FileOutputStream(packFile)) {
+ pw.writePack(NullProgressMonitor.INSTANCE,
+ NullProgressMonitor.INSTANCE, packOS);
+ }
File idxFile = new File(packdir, "pack-" + id + ".idx");
- FileOutputStream idxOS = new FileOutputStream(idxFile);
- pw.writeIndex(idxOS);
- idxOS.close();
+ try (FileOutputStream idxOS = new FileOutputStream(idxFile)) {
+ pw.writeIndex(idxOS);
+ }
return PackIndex.open(idxFile);
}
}
@@ -838,7 +835,7 @@ public class PackWriterTest extends SampleDataRepositoryTestCase {
verifyOpenPack(thin);
}
- private void createVerifyOpenPack(final List<RevObject> objectSource)
+ private void createVerifyOpenPack(List<RevObject> objectSource)
throws MissingObjectException, IOException {
NullProgressMonitor m = NullProgressMonitor.INSTANCE;
writer = new PackWriter(config, db.newObjectReader());
@@ -849,7 +846,7 @@ public class PackWriterTest extends SampleDataRepositoryTestCase {
verifyOpenPack(false);
}
- private void verifyOpenPack(final boolean thin) throws IOException {
+ private void verifyOpenPack(boolean thin) throws IOException {
final byte[] packData = os.toByteArray();
if (thin) {
@@ -871,13 +868,13 @@ public class PackWriterTest extends SampleDataRepositoryTestCase {
assertNotNull("have PackFile after parsing", pack);
}
- private PackParser index(final byte[] packData) throws IOException {
+ private PackParser index(byte[] packData) throws IOException {
if (inserter == null)
inserter = dst.newObjectInserter();
return inserter.newPackParser(new ByteArrayInputStream(packData));
}
- private void verifyObjectsOrder(final ObjectId objectsOrder[]) {
+ private void verifyObjectsOrder(ObjectId objectsOrder[]) {
final List<PackIndex.MutableEntry> entries = new ArrayList<>();
for (MutableEntry me : pack) {
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefDirectoryTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefDirectoryTest.java
index fefccf314f..5a2bd9c333 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefDirectoryTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefDirectoryTest.java
@@ -1271,7 +1271,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase {
@Override
public void onRefsChanged(RefsChangedEvent event) {
try {
- refDb.getRefs("ref");
+ refDb.getRefsByPrefix("ref");
changeCount.incrementAndGet();
} catch (StackOverflowError soe) {
error.set(soe);
@@ -1280,8 +1280,8 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase {
}
}
});
- refDb.getRefs("ref");
- refDb.getRefs("ref");
+ refDb.getRefsByPrefix("ref");
+ refDb.getRefsByPrefix("ref");
assertNull(error.get());
assertNull(exception.get());
assertEquals(1, changeCount.get());
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefUpdateTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefUpdateTest.java
index 52861ecd53..e1adeedc54 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefUpdateTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefUpdateTest.java
@@ -45,8 +45,9 @@
package org.eclipse.jgit.internal.storage.file;
-import static java.nio.charset.StandardCharsets.UTF_8;
import static org.eclipse.jgit.junit.Assert.assertEquals;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
+import static org.eclipse.jgit.lib.Constants.LOCK_SUFFIX;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@@ -61,6 +62,7 @@ import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.Optional;
import org.eclipse.jgit.lib.AnyObjectId;
import org.eclipse.jgit.lib.Constants;
@@ -93,13 +95,13 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase {
}
}
- private RefUpdate updateRef(final String name) throws IOException {
+ private RefUpdate updateRef(String name) throws IOException {
final RefUpdate ref = db.updateRef(name);
ref.setNewObjectId(db.resolve(Constants.HEAD));
return ref;
}
- private void delete(final RefUpdate ref, final Result expected)
+ private void delete(RefUpdate ref, Result expected)
throws IOException {
delete(ref, expected, true, true);
}
@@ -109,11 +111,21 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase {
delete(db, ref, expected, exists, removed);
}
- private void delete(Repository repo, final RefUpdate ref, final Result expected,
- final boolean exists, final boolean removed) throws IOException {
- assertEquals(exists, repo.getAllRefs().containsKey(ref.getName()));
+ private void delete(Repository repo, final RefUpdate ref,
+ final Result expected, final boolean exists, final boolean removed)
+ throws IOException {
+ assertEquals(exists, getRef(repo, ref.getName()).isPresent());
assertEquals(expected, ref.delete());
- assertEquals(!removed, repo.getAllRefs().containsKey(ref.getName()));
+ assertEquals(!removed, getRef(repo, ref.getName()).isPresent());
+ }
+
+ private Optional<Ref> getRef(Repository repo, String name)
+ throws IOException {
+ return getRef(repo.getRefDatabase().getRefs(), name);
+ }
+
+ private Optional<Ref> getRef(List<Ref> refs, String name) {
+ return refs.stream().filter(r -> r.getName().equals(name)).findAny();
}
@Test
@@ -124,8 +136,7 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase {
ru.setNewObjectId(newid);
Result update = ru.update();
assertEquals(Result.NEW, update);
- final Ref r = db.getAllRefs().get(newRef);
- assertNotNull(r);
+ final Ref r = getRef(db, newRef).get();
assertEquals(newRef, r.getName());
assertNotNull(r.getObjectId());
assertNotSame(newid, r.getObjectId());
@@ -252,7 +263,7 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase {
ObjectId blobId;
try (ObjectInserter ins = bareRepo.newObjectInserter()) {
- blobId = ins.insert(Constants.OBJ_BLOB, "contents".getBytes(UTF_8));
+ blobId = ins.insert(Constants.OBJ_BLOB, "contents".getBytes(CHARSET));
ins.flush();
}
@@ -377,10 +388,10 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase {
@Test
public void testRefKeySameAsName() {
+ @SuppressWarnings("deprecation")
Map<String, Ref> allRefs = db.getAllRefs();
for (Entry<String, Ref> e : allRefs.entrySet()) {
assertEquals(e.getKey(), e.getValue().getName());
-
}
}
@@ -519,8 +530,8 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase {
*/
@Test
public void testRefsCacheAfterUpdate() throws Exception {
- // Do not use the defalt repo for this case.
- Map<String, Ref> allRefs = db.getAllRefs();
+ // Do not use the default repo for this case.
+ List<Ref> allRefs = db.getRefDatabase().getRefs();
ObjectId oldValue = db.resolve("HEAD");
ObjectId newValue = db.resolve("HEAD^");
// first make HEAD refer to loose ref
@@ -536,9 +547,9 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase {
update = updateRef.update();
assertEquals(Result.FAST_FORWARD, update);
- allRefs = db.getAllRefs();
- Ref master = allRefs.get("refs/heads/master");
- Ref head = allRefs.get("HEAD");
+ allRefs = db.getRefDatabase().getRefs();
+ Ref master = getRef(allRefs, "refs/heads/master").get();
+ Ref head = getRef(allRefs, "HEAD").get();
assertEquals("refs/heads/master", master.getName());
assertEquals("HEAD", head.getName());
assertTrue("is symbolic reference", head.isSymbolic());
@@ -556,8 +567,8 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase {
*/
@Test
public void testRefsCacheAfterUpdateLooseOnly() throws Exception {
- // Do not use the defalt repo for this case.
- Map<String, Ref> allRefs = db.getAllRefs();
+ // Do not use the default repo for this case.
+ List<Ref> allRefs = db.getRefDatabase().getRefs();
ObjectId oldValue = db.resolve("HEAD");
writeSymref(Constants.HEAD, "refs/heads/newref");
RefUpdate updateRef = db.updateRef(Constants.HEAD);
@@ -566,9 +577,9 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase {
Result update = updateRef.update();
assertEquals(Result.NEW, update);
- allRefs = db.getAllRefs();
- Ref head = allRefs.get("HEAD");
- Ref newref = allRefs.get("refs/heads/newref");
+ allRefs = db.getRefDatabase().getRefs();
+ Ref head = getRef(allRefs, "HEAD").get();
+ Ref newref = getRef(allRefs, "refs/heads/newref").get();
assertEquals("refs/heads/newref", newref.getName());
assertEquals("HEAD", head.getName());
assertTrue("is symbolic reference", head.isSymbolic());
@@ -819,11 +830,11 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase {
// Check that the involved refs are the same despite the failure
assertExists(false, toName);
if (!toLock.equals(toName))
- assertExists(false, toName + ".lock");
- assertExists(true, toLock + ".lock");
+ assertExists(false, toName + LOCK_SUFFIX);
+ assertExists(true, toLock + LOCK_SUFFIX);
if (!toLock.equals(fromName))
- assertExists(false, "logs/" + fromName + ".lock");
- assertExists(false, "logs/" + toName + ".lock");
+ assertExists(false, "logs/" + fromName + LOCK_SUFFIX);
+ assertExists(false, "logs/" + toName + LOCK_SUFFIX);
assertEquals(oldHeadId, db.resolve(Constants.HEAD));
assertEquals(oldfromId, db.resolve(fromName));
assertNull(db.resolve(toName));
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/T0003_BasicTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/T0003_BasicTest.java
index d7505af4cf..e113db12ac 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/T0003_BasicTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/T0003_BasicTest.java
@@ -47,7 +47,7 @@
package org.eclipse.jgit.internal.storage.file;
import static java.nio.charset.StandardCharsets.ISO_8859_1;
-import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@@ -137,10 +137,10 @@ public class T0003_BasicTest extends SampleDataRepositoryTestCase {
@Test
public void test000_openrepo_default_gitDirSet() throws IOException {
File repo1Parent = new File(trash.getParentFile(), "r1");
- Repository repo1initial = new FileRepository(new File(repo1Parent,
- Constants.DOT_GIT));
- repo1initial.create();
- repo1initial.close();
+ try (Repository repo1initial = new FileRepository(
+ new File(repo1Parent, Constants.DOT_GIT))) {
+ repo1initial.create();
+ }
File theDir = new File(repo1Parent, Constants.DOT_GIT);
FileRepository r = (FileRepository) new FileRepositoryBuilder()
@@ -162,10 +162,10 @@ public class T0003_BasicTest extends SampleDataRepositoryTestCase {
public void test000_openrepo_default_gitDirAndWorkTreeSet()
throws IOException {
File repo1Parent = new File(trash.getParentFile(), "r1");
- Repository repo1initial = new FileRepository(new File(repo1Parent,
- Constants.DOT_GIT));
- repo1initial.create();
- repo1initial.close();
+ try (Repository repo1initial = new FileRepository(
+ new File(repo1Parent, Constants.DOT_GIT))) {
+ repo1initial.create();
+ }
File theDir = new File(repo1Parent, Constants.DOT_GIT);
FileRepository r = (FileRepository) new FileRepositoryBuilder()
@@ -187,10 +187,10 @@ public class T0003_BasicTest extends SampleDataRepositoryTestCase {
@Test
public void test000_openrepo_default_workDirSet() throws IOException {
File repo1Parent = new File(trash.getParentFile(), "r1");
- Repository repo1initial = new FileRepository(new File(repo1Parent,
- Constants.DOT_GIT));
- repo1initial.create();
- repo1initial.close();
+ try (Repository repo1initial = new FileRepository(
+ new File(repo1Parent, Constants.DOT_GIT))) {
+ repo1initial.create();
+ }
File theDir = new File(repo1Parent, Constants.DOT_GIT);
FileRepository r = (FileRepository) new FileRepositoryBuilder()
@@ -213,13 +213,13 @@ public class T0003_BasicTest extends SampleDataRepositoryTestCase {
File repo1Parent = new File(trash.getParentFile(), "r1");
File workdir = new File(trash.getParentFile(), "rw");
FileUtils.mkdir(workdir);
- FileRepository repo1initial = new FileRepository(new File(repo1Parent,
- Constants.DOT_GIT));
- repo1initial.create();
- final FileBasedConfig cfg = repo1initial.getConfig();
- cfg.setString("core", null, "worktree", workdir.getAbsolutePath());
- cfg.save();
- repo1initial.close();
+ try (FileRepository repo1initial = new FileRepository(
+ new File(repo1Parent, Constants.DOT_GIT))) {
+ repo1initial.create();
+ final FileBasedConfig cfg = repo1initial.getConfig();
+ cfg.setString("core", null, "worktree", workdir.getAbsolutePath());
+ cfg.save();
+ }
File theDir = new File(repo1Parent, Constants.DOT_GIT);
FileRepository r = (FileRepository) new FileRepositoryBuilder()
@@ -242,13 +242,13 @@ public class T0003_BasicTest extends SampleDataRepositoryTestCase {
File repo1Parent = new File(trash.getParentFile(), "r1");
File workdir = new File(trash.getParentFile(), "rw");
FileUtils.mkdir(workdir);
- FileRepository repo1initial = new FileRepository(new File(repo1Parent,
- Constants.DOT_GIT));
- repo1initial.create();
- final FileBasedConfig cfg = repo1initial.getConfig();
- cfg.setString("core", null, "worktree", "../../rw");
- cfg.save();
- repo1initial.close();
+ try (FileRepository repo1initial = new FileRepository(
+ new File(repo1Parent, Constants.DOT_GIT))) {
+ repo1initial.create();
+ final FileBasedConfig cfg = repo1initial.getConfig();
+ cfg.setString("core", null, "worktree", "../../rw");
+ cfg.save();
+ }
File theDir = new File(repo1Parent, Constants.DOT_GIT);
FileRepository r = (FileRepository) new FileRepositoryBuilder()
@@ -273,26 +273,24 @@ public class T0003_BasicTest extends SampleDataRepositoryTestCase {
File indexFile = new File(trash, "idx");
File objDir = new File(trash, "../obj");
File altObjDir = db.getObjectDatabase().getDirectory();
- Repository repo1initial = new FileRepository(new File(repo1Parent,
- Constants.DOT_GIT));
- repo1initial.create();
- repo1initial.close();
+ try (Repository repo1initial = new FileRepository(
+ new File(repo1Parent, Constants.DOT_GIT))) {
+ repo1initial.create();
+ }
File theDir = new File(repo1Parent, Constants.DOT_GIT);
- FileRepository r = (FileRepository) new FileRepositoryBuilder() //
+ try (FileRepository r = (FileRepository) new FileRepositoryBuilder() //
.setGitDir(theDir).setObjectDirectory(objDir) //
.addAlternateObjectDirectory(altObjDir) //
.setIndexFile(indexFile) //
- .build();
- assertEqualsPath(theDir, r.getDirectory());
- assertEqualsPath(theDir.getParentFile(), r.getWorkTree());
- assertEqualsPath(indexFile, r.getIndexFile());
- assertEqualsPath(objDir, r.getObjectDatabase().getDirectory());
- assertNotNull(r.open(ObjectId
- .fromString("6db9c2ebf75590eef973081736730a9ea169a0c4")));
- // Must close or the default repo pack files created by this test gets
- // locked via the alternate object directories on Windows.
- r.close();
+ .build()) {
+ assertEqualsPath(theDir, r.getDirectory());
+ assertEqualsPath(theDir.getParentFile(), r.getWorkTree());
+ assertEqualsPath(indexFile, r.getIndexFile());
+ assertEqualsPath(objDir, r.getObjectDatabase().getDirectory());
+ assertNotNull(r.open(ObjectId
+ .fromString("6db9c2ebf75590eef973081736730a9ea169a0c4")));
+ }
}
protected void assertEqualsPath(File expected, File actual)
@@ -307,7 +305,7 @@ public class T0003_BasicTest extends SampleDataRepositoryTestCase {
// object (as it already exists in the pack).
//
final Repository newdb = createBareRepository();
- try (final ObjectInserter oi = newdb.newObjectInserter()) {
+ try (ObjectInserter oi = newdb.newObjectInserter()) {
final ObjectId treeId = oi.insert(new TreeFormatter());
assertEquals("4b825dc642cb6eb9a060e54bf8d69288fbee4904",
treeId.name());
@@ -375,7 +373,7 @@ public class T0003_BasicTest extends SampleDataRepositoryTestCase {
@Test
public void test007_Open() throws IOException {
- try (final FileRepository db2 = new FileRepository(db.getDirectory())) {
+ try (FileRepository db2 = new FileRepository(db.getDirectory())) {
assertEquals(db.getDirectory(), db2.getDirectory());
assertEquals(db.getObjectDatabase().getDirectory(), db2
.getObjectDatabase().getDirectory());
@@ -417,14 +415,11 @@ public class T0003_BasicTest extends SampleDataRepositoryTestCase {
// Verify the commit we just wrote is in the correct format.
ObjectDatabase odb = db.getObjectDatabase();
assertTrue("is ObjectDirectory", odb instanceof ObjectDirectory);
- final XInputStream xis = new XInputStream(new FileInputStream(
- ((ObjectDirectory) odb).fileFor(cmtid)));
- try {
+ try (XInputStream xis = new XInputStream(
+ new FileInputStream(((ObjectDirectory) odb).fileFor(cmtid)))) {
assertEquals(0x78, xis.readUInt8());
assertEquals(0x9c, xis.readUInt8());
assertEquals(0, 0x789c % 31);
- } finally {
- xis.close();
}
// Verify we can read it.
@@ -522,7 +517,7 @@ public class T0003_BasicTest extends SampleDataRepositoryTestCase {
4294967295000L, 60));
commit.setCommitter(new PersonIdent("Joe Hacker", "joe2@example.com",
4294967295000L, 60));
- commit.setEncoding(UTF_8);
+ commit.setEncoding(CHARSET);
commit.setMessage("\u00dcbergeeks");
ObjectId cid = insertCommit(commit);
assertEquals("4680908112778718f37e686cbebcc912730b3154", cid.name());
@@ -562,7 +557,7 @@ public class T0003_BasicTest extends SampleDataRepositoryTestCase {
@Test
public void test026_CreateCommitMultipleparents() throws IOException {
final ObjectId treeId;
- try (final ObjectInserter oi = db.newObjectInserter()) {
+ try (ObjectInserter oi = db.newObjectInserter()) {
final ObjectId blobId = oi.insert(Constants.OBJ_BLOB,
"and this is the data in me\n".getBytes(Constants.CHARSET
.name()));
@@ -752,7 +747,7 @@ public class T0003_BasicTest extends SampleDataRepositoryTestCase {
}
}
- private ObjectId insertCommit(final CommitBuilder builder)
+ private ObjectId insertCommit(CommitBuilder builder)
throws IOException, UnsupportedEncodingException {
try (ObjectInserter oi = db.newObjectInserter()) {
ObjectId id = oi.insert(builder);
@@ -769,7 +764,7 @@ public class T0003_BasicTest extends SampleDataRepositoryTestCase {
}
}
- private ObjectId insertTag(final TagBuilder tag) throws IOException,
+ private ObjectId insertTag(TagBuilder tag) throws IOException,
UnsupportedEncodingException {
try (ObjectInserter oi = db.newObjectInserter()) {
ObjectId id = oi.insert(tag);
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/UnpackedObjectTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/UnpackedObjectTest.java
index c5ab766838..98ff04e15e 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/UnpackedObjectTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/UnpackedObjectTest.java
@@ -130,15 +130,15 @@ public class UnpackedObjectTest extends LocalDiskRepositoryTestCase {
assertFalse("is not large", ol.isLarge());
assertTrue("same content", Arrays.equals(data, ol.getCachedBytes()));
- ObjectStream in = ol.openStream();
- assertNotNull("have stream", in);
- assertEquals(type, in.getType());
- assertEquals(data.length, in.getSize());
- byte[] data2 = new byte[data.length];
- IO.readFully(in, data2, 0, data.length);
- assertTrue("same content", Arrays.equals(data2, data));
- assertEquals("stream at EOF", -1, in.read());
- in.close();
+ try (ObjectStream in = ol.openStream()) {
+ assertNotNull("have stream", in);
+ assertEquals(type, in.getType());
+ assertEquals(data.length, in.getSize());
+ byte[] data2 = new byte[data.length];
+ IO.readFully(in, data2, 0, data.length);
+ assertTrue("same content", Arrays.equals(data2, data));
+ assertEquals("stream at EOF", -1, in.read());
+ }
}
@Test
@@ -150,11 +150,8 @@ public class UnpackedObjectTest extends LocalDiskRepositoryTestCase {
ObjectLoader ol;
{
- FileInputStream fs = new FileInputStream(path(id));
- try {
+ try (FileInputStream fs = new FileInputStream(path(id))) {
ol = UnpackedObject.open(fs, path(id), id, wc);
- } finally {
- fs.close();
}
}
@@ -171,15 +168,15 @@ public class UnpackedObjectTest extends LocalDiskRepositoryTestCase {
.getMessage());
}
- ObjectStream in = ol.openStream();
- assertNotNull("have stream", in);
- assertEquals(type, in.getType());
- assertEquals(data.length, in.getSize());
- byte[] data2 = new byte[data.length];
- IO.readFully(in, data2, 0, data.length);
- assertTrue("same content", Arrays.equals(data2, data));
- assertEquals("stream at EOF", -1, in.read());
- in.close();
+ try (ObjectStream in = ol.openStream()) {
+ assertNotNull("have stream", in);
+ assertEquals(type, in.getType());
+ assertEquals(data.length, in.getSize());
+ byte[] data2 = new byte[data.length];
+ IO.readFully(in, data2, 0, data.length);
+ assertTrue("same content", Arrays.equals(data2, data));
+ assertEquals("stream at EOF", -1, in.read());
+ }
}
@Test
@@ -316,23 +313,13 @@ public class UnpackedObjectTest extends LocalDiskRepositoryTestCase {
write(id, gz);
ObjectLoader ol;
- {
- FileInputStream fs = new FileInputStream(path(id));
- try {
- ol = UnpackedObject.open(fs, path(id), id, wc);
- } finally {
- fs.close();
- }
+ try (FileInputStream fs = new FileInputStream(path(id))) {
+ ol = UnpackedObject.open(fs, path(id), id, wc);
}
- try {
- byte[] tmp = new byte[data.length];
- InputStream in = ol.openStream();
- try {
- IO.readFully(in, tmp, 0, tmp.length);
- } finally {
- in.close();
- }
+ byte[] tmp = new byte[data.length];
+ try (InputStream in = ol.openStream()) {
+ IO.readFully(in, tmp, 0, tmp.length);
fail("Did not throw CorruptObjectException");
} catch (CorruptObjectException coe) {
assertEquals(MessageFormat.format(JGitText.get().objectIsCorrupt,
@@ -354,16 +341,12 @@ public class UnpackedObjectTest extends LocalDiskRepositoryTestCase {
write(id, tr);
ObjectLoader ol;
- {
- FileInputStream fs = new FileInputStream(path(id));
- try {
- ol = UnpackedObject.open(fs, path(id), id, wc);
- } finally {
- fs.close();
- }
+ try (FileInputStream fs = new FileInputStream(path(id))) {
+ ol = UnpackedObject.open(fs, path(id), id, wc);
}
byte[] tmp = new byte[data.length];
+ @SuppressWarnings("resource") // We are testing that the close() method throws
InputStream in = ol.openStream();
IO.readFully(in, tmp, 0, tmp.length);
try {
@@ -389,16 +372,12 @@ public class UnpackedObjectTest extends LocalDiskRepositoryTestCase {
write(id, tr);
ObjectLoader ol;
- {
- FileInputStream fs = new FileInputStream(path(id));
- try {
- ol = UnpackedObject.open(fs, path(id), id, wc);
- } finally {
- fs.close();
- }
+ try (FileInputStream fs = new FileInputStream(path(id))) {
+ ol = UnpackedObject.open(fs, path(id), id, wc);
}
byte[] tmp = new byte[data.length];
+ @SuppressWarnings("resource") // We are testing that the close() method throws
InputStream in = ol.openStream();
IO.readFully(in, tmp, 0, tmp.length);
try {
@@ -426,14 +405,15 @@ public class UnpackedObjectTest extends LocalDiskRepositoryTestCase {
assertFalse("is not large", ol.isLarge());
assertTrue("same content", Arrays.equals(data, ol.getCachedBytes()));
- ObjectStream in = ol.openStream();
- assertNotNull("have stream", in);
- assertEquals(type, in.getType());
- assertEquals(data.length, in.getSize());
- byte[] data2 = new byte[data.length];
- IO.readFully(in, data2, 0, data.length);
- assertTrue("same content", Arrays.equals(data, ol.getCachedBytes()));
- in.close();
+ try (ObjectStream in = ol.openStream()) {
+ assertNotNull("have stream", in);
+ assertEquals(type, in.getType());
+ assertEquals(data.length, in.getSize());
+ byte[] data2 = new byte[data.length];
+ IO.readFully(in, data2, 0, data.length);
+ assertTrue("same content",
+ Arrays.equals(data, ol.getCachedBytes()));
+ }
}
@Test
@@ -444,13 +424,8 @@ public class UnpackedObjectTest extends LocalDiskRepositoryTestCase {
write(id, compressPackFormat(type, data));
ObjectLoader ol;
- {
- FileInputStream fs = new FileInputStream(path(id));
- try {
- ol = UnpackedObject.open(fs, path(id), id, wc);
- } finally {
- fs.close();
- }
+ try (FileInputStream fs = new FileInputStream(path(id))) {
+ ol = UnpackedObject.open(fs, path(id), id, wc);
}
assertNotNull("created loader", ol);
@@ -466,15 +441,15 @@ public class UnpackedObjectTest extends LocalDiskRepositoryTestCase {
.getMessage());
}
- ObjectStream in = ol.openStream();
- assertNotNull("have stream", in);
- assertEquals(type, in.getType());
- assertEquals(data.length, in.getSize());
- byte[] data2 = new byte[data.length];
- IO.readFully(in, data2, 0, data.length);
- assertTrue("same content", Arrays.equals(data2, data));
- assertEquals("stream at EOF", -1, in.read());
- in.close();
+ try (ObjectStream in = ol.openStream()) {
+ assertNotNull("have stream", in);
+ assertEquals(type, in.getType());
+ assertEquals(data.length, in.getSize());
+ byte[] data2 = new byte[data.length];
+ IO.readFully(in, data2, 0, data.length);
+ assertTrue("same content", Arrays.equals(data2, data));
+ assertEquals("stream at EOF", -1, in.read());
+ }
}
@Test
@@ -573,11 +548,8 @@ public class UnpackedObjectTest extends LocalDiskRepositoryTestCase {
private void write(ObjectId id, byte[] data) throws IOException {
File path = path(id);
FileUtils.mkdirs(path.getParentFile());
- FileOutputStream out = new FileOutputStream(path);
- try {
+ try (FileOutputStream out = new FileOutputStream(path)) {
out.write(data);
- } finally {
- out.close();
}
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/WindowCacheGetTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/WindowCacheGetTest.java
index cc348388cf..82ad28ed21 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/WindowCacheGetTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/WindowCacheGetTest.java
@@ -74,11 +74,10 @@ public class WindowCacheGetTest extends SampleDataRepositoryTestCase {
super.setUp();
toLoad = new ArrayList<>();
- final BufferedReader br = new BufferedReader(new InputStreamReader(
+ try (BufferedReader br = new BufferedReader(new InputStreamReader(
new FileInputStream(JGitTestUtil
.getTestResourceFile("all_packed_objects.txt")),
- Constants.CHARSET));
- try {
+ Constants.CHARSET))) {
String line;
while ((line = br.readLine()) != null) {
final String[] parts = line.split(" {1,}");
@@ -90,8 +89,6 @@ public class WindowCacheGetTest extends SampleDataRepositoryTestCase {
// parts[4] is the offset in the pack
toLoad.add(o);
}
- } finally {
- br.close();
}
assertEquals(96, toLoad.size());
}
@@ -127,7 +124,7 @@ public class WindowCacheGetTest extends SampleDataRepositoryTestCase {
checkLimits(cfg);
}
- private static void checkLimits(final WindowCacheConfig cfg) {
+ private static void checkLimits(WindowCacheConfig cfg) {
final WindowCache cache = WindowCache.getInstance();
assertTrue(cache.getOpenFiles() <= cfg.getPackedGitOpenFiles());
assertTrue(cache.getOpenBytes() <= cfg.getPackedGitLimit());
@@ -136,7 +133,7 @@ public class WindowCacheGetTest extends SampleDataRepositoryTestCase {
}
private void doCacheTests() throws IOException {
- for (final TestObject o : toLoad) {
+ for (TestObject o : toLoad) {
final ObjectLoader or = db.open(o.id, o.type);
assertNotNull(or);
assertEquals(o.type, or.getType());
@@ -148,7 +145,7 @@ public class WindowCacheGetTest extends SampleDataRepositoryTestCase {
int type;
- void setType(final String typeStr) throws CorruptObjectException {
+ void setType(String typeStr) throws CorruptObjectException {
final byte[] typeRaw = Constants.encode(typeStr + " ");
final MutableInteger ptr = new MutableInteger();
type = Constants.decodeTypeString(id, typeRaw, (byte) ' ', ptr);
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/XInputStream.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/XInputStream.java
index 46f9ee3fff..910999c101 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/XInputStream.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/XInputStream.java
@@ -53,7 +53,7 @@ import org.eclipse.jgit.util.NB;
class XInputStream extends BufferedInputStream {
private final byte[] intbuf = new byte[8];
- XInputStream(final InputStream s) {
+ XInputStream(InputStream s) {
super(s);
}
@@ -63,7 +63,7 @@ class XInputStream extends BufferedInputStream {
return b;
}
- synchronized void readFully(final byte[] b, int o, int len)
+ synchronized void readFully(byte[] b, int o, int len)
throws IOException {
int r;
while (len > 0 && (r = read(b, o, len)) > 0) {
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/reftree/RefTreeDatabaseTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/reftree/RefTreeDatabaseTest.java
index 1684afa4e1..ae52ad5917 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/reftree/RefTreeDatabaseTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/reftree/RefTreeDatabaseTest.java
@@ -631,7 +631,7 @@ public class RefTreeDatabaseTest {
name);
}
- private void symref(final String name, final String dst)
+ private void symref(String name, String dst)
throws IOException {
commit(new Function() {
@Override
@@ -648,7 +648,7 @@ public class RefTreeDatabaseTest {
});
}
- private void update(final String name, final ObjectId id)
+ private void update(String name, ObjectId id)
throws IOException {
commit(new Function() {
@Override
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/junit/TestRepositoryTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/junit/TestRepositoryTest.java
index b7027f3272..965899e7a0 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/junit/TestRepositoryTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/junit/TestRepositoryTest.java
@@ -43,7 +43,7 @@
package org.eclipse.jgit.junit;
-import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
@@ -418,6 +418,6 @@ public class TestRepositoryTest {
RevObject obj = tr.get(rw.parseTree(treeish), path);
assertSame(RevBlob.class, obj.getClass());
ObjectLoader loader = rw.getObjectReader().open(obj);
- return new String(loader.getCachedBytes(), UTF_8);
+ return new String(loader.getCachedBytes(), CHARSET);
}
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/BranchConfigTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/BranchConfigTest.java
index 87bb082485..1ecdf21d45 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/BranchConfigTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/BranchConfigTest.java
@@ -160,7 +160,7 @@ public class BranchConfigTest {
assertTrue(new BranchConfig(c, "true").isRebase());
}
- private static Config parse(final String content) {
+ private static Config parse(String content) {
final Config c = new Config(null);
try {
c.fromText(content);
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java
index 7862005ebc..c4c4da8165 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java
@@ -914,12 +914,12 @@ public class ConfigTest {
assertEquals(exp, c.getLong("s", null, "a", 0L));
}
- private static Config parse(final String content)
+ private static Config parse(String content)
throws ConfigInvalidException {
return parse(content, null);
}
- private static Config parse(final String content, Config baseConfig)
+ private static Config parse(String content, Config baseConfig)
throws ConfigInvalidException {
final Config c = new Config(baseConfig);
c.fromText(content);
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutTest.java
index 0412242ebf..eb87827805 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutTest.java
@@ -78,8 +78,10 @@ import org.eclipse.jgit.junit.RepositoryTestCase;
import org.eclipse.jgit.junit.TestRepository;
import org.eclipse.jgit.junit.TestRepository.BranchBuilder;
import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.jgit.treewalk.AbstractTreeIterator;
import org.eclipse.jgit.treewalk.FileTreeIterator;
import org.eclipse.jgit.treewalk.TreeWalk;
+import org.eclipse.jgit.treewalk.WorkingTreeIterator;
import org.eclipse.jgit.util.FS;
import org.eclipse.jgit.util.FileUtils;
import org.junit.Assume;
@@ -1904,6 +1906,117 @@ public class DirCacheCheckoutTest extends RepositoryTestCase {
assertUpdated(longFileName);
}
+ @Test
+ public void testIgnoredDirectory() throws Exception {
+ writeTrashFile(".gitignore", "src/ignored");
+ writeTrashFile("src/ignored/sub/foo.txt", "1");
+ try (Git git = new Git(db)) {
+ git.add().addFilepattern(".").call();
+ RevCommit commit = git.commit().setMessage("adding .gitignore")
+ .call();
+ writeTrashFile("foo.txt", "2");
+ writeTrashFile("zzz.txt", "3");
+ git.add().addFilepattern("foo.txt").call();
+ git.commit().setMessage("add file").call();
+ assertEquals("Should not have entered ignored directory", 1,
+ resetHardAndCount(commit));
+ }
+ }
+
+ @Test
+ public void testIgnoredDirectoryWithTrackedContent() throws Exception {
+ writeTrashFile("src/ignored/sub/foo.txt", "1");
+ try (Git git = new Git(db)) {
+ git.add().addFilepattern(".").call();
+ git.commit().setMessage("adding foo.txt").call();
+ writeTrashFile(".gitignore", "src/ignored");
+ writeTrashFile("src/ignored/sub/foo.txt", "2");
+ writeTrashFile("src/ignored/other/bar.txt", "3");
+ git.add().addFilepattern(".").call();
+ RevCommit commit = git.commit().setMessage("adding .gitignore")
+ .call();
+ writeTrashFile("foo.txt", "2");
+ writeTrashFile("zzz.txt", "3");
+ git.add().addFilepattern("foo.txt").call();
+ git.commit().setMessage("add file").call();
+ File file = writeTrashFile("src/ignored/sub/foo.txt", "3");
+ assertEquals("Should have entered ignored directory", 3,
+ resetHardAndCount(commit));
+ checkFile(file, "2");
+ }
+ }
+
+ @Test
+ public void testResetWithChangeInGitignore() throws Exception {
+ writeTrashFile(".gitignore", "src/ignored");
+ writeTrashFile("src/ignored/sub/foo.txt", "1");
+ try (Git git = new Git(db)) {
+ git.add().addFilepattern(".").call();
+ RevCommit initial = git.commit().setMessage("initial").call();
+ writeTrashFile("src/newignored/foo.txt", "2");
+ writeTrashFile("src/.gitignore", "newignored");
+ git.add().addFilepattern(".").call();
+ RevCommit commit = git.commit().setMessage("newignored").call();
+ assertEquals("Should not have entered src/newignored directory", 1,
+ resetHardAndCount(initial));
+ assertEquals("Should have entered src/newignored directory", 2,
+ resetHardAndCount(commit));
+ deleteTrashFile("src/.gitignore");
+ git.rm().addFilepattern("src/.gitignore").call();
+ RevCommit top = git.commit().setMessage("Unignore newignore")
+ .call();
+ assertEquals("Should have entered src/newignored directory", 2,
+ resetHardAndCount(initial));
+ assertEquals("Should have entered src/newignored directory", 2,
+ resetHardAndCount(commit));
+ assertEquals("Should not have entered src/newignored directory", 1,
+ resetHardAndCount(top));
+
+ }
+ }
+
+ private static class TestFileTreeIterator extends FileTreeIterator {
+
+ // For assertions only
+ private final int[] count;
+
+ public TestFileTreeIterator(Repository repo, int[] count) {
+ super(repo);
+ this.count = count;
+ }
+
+ protected TestFileTreeIterator(final WorkingTreeIterator p,
+ final File root, FS fs, FileModeStrategy fileModeStrategy,
+ int[] count) {
+ super(p, root, fs, fileModeStrategy);
+ this.count = count;
+ }
+
+ @Override
+ protected AbstractTreeIterator enterSubtree() {
+ count[0] += 1;
+ return new TestFileTreeIterator(this,
+ ((FileEntry) current()).getFile(), fs, fileModeStrategy,
+ count);
+ }
+ }
+
+ private int resetHardAndCount(RevCommit commit) throws Exception {
+ int[] callCount = { 0 };
+ DirCache cache = db.lockDirCache();
+ FileTreeIterator workingTreeIterator = new TestFileTreeIterator(db,
+ callCount);
+ try {
+ DirCacheCheckout checkout = new DirCacheCheckout(db, null, cache,
+ commit.getTree().getId(), workingTreeIterator);
+ checkout.setFailOnConflict(false);
+ checkout.checkout();
+ } finally {
+ cache.unlock();
+ }
+ return callCount[0];
+ }
+
public void assertWorkDir(Map<String, String> i)
throws CorruptObjectException,
IOException {
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffTest.java
index 2cb8f86fc2..580b08b42f 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffTest.java
@@ -470,7 +470,8 @@ public class IndexDiffTest extends RepositoryTestCase {
}
/**
- * Test that ignored folders aren't listed as untracked
+ * Test that ignored folders aren't listed as untracked, but are listed as
+ * ignored.
*
* @throws Exception
*/
@@ -499,6 +500,8 @@ public class IndexDiffTest extends RepositoryTestCase {
diff.diff();
assertEquals(new HashSet<>(Arrays.asList("src")),
diff.getUntrackedFolders());
+ assertEquals(new HashSet<>(Arrays.asList("sr", "target")),
+ diff.getIgnoredNotInIndex());
git.add().addFilepattern("src").call();
writeTrashFile("sr/com/X1.java", "");
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectCheckerTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectCheckerTest.java
index f1c62d4be2..b8e8a12d53 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectCheckerTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectCheckerTest.java
@@ -45,7 +45,7 @@
package org.eclipse.jgit.lib;
import static java.lang.Integer.valueOf;
-import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
import static org.eclipse.jgit.junit.JGitTestUtil.concat;
import static org.eclipse.jgit.lib.Constants.OBJECT_ID_LENGTH;
import static org.eclipse.jgit.lib.Constants.OBJ_BAD;
@@ -1454,7 +1454,7 @@ public class ObjectCheckerTest {
StringBuilder b = new StringBuilder();
entry(b, "100644 A");
entry(b, "100644 a");
- byte[] data = b.toString().getBytes(UTF_8);
+ byte[] data = b.toString().getBytes(CHARSET);
checker.setSafeForWindows(true);
assertCorrupt("duplicate entry names", OBJ_TREE, data);
assertSkipListAccepts(OBJ_TREE, data);
@@ -1468,7 +1468,7 @@ public class ObjectCheckerTest {
StringBuilder b = new StringBuilder();
entry(b, "100644 A");
entry(b, "100644 a");
- byte[] data = b.toString().getBytes(UTF_8);
+ byte[] data = b.toString().getBytes(CHARSET);
checker.setSafeForMacOS(true);
assertCorrupt("duplicate entry names", OBJ_TREE, data);
assertSkipListAccepts(OBJ_TREE, data);
@@ -1482,7 +1482,7 @@ public class ObjectCheckerTest {
StringBuilder b = new StringBuilder();
entry(b, "100644 \u0065\u0301");
entry(b, "100644 \u00e9");
- byte[] data = b.toString().getBytes(UTF_8);
+ byte[] data = b.toString().getBytes(CHARSET);
checker.setSafeForMacOS(true);
assertCorrupt("duplicate entry names", OBJ_TREE, data);
assertSkipListAccepts(OBJ_TREE, data);
@@ -1496,7 +1496,7 @@ public class ObjectCheckerTest {
StringBuilder b = new StringBuilder();
entry(b, "100644 A");
checker.setSafeForMacOS(true);
- checker.checkTree(b.toString().getBytes(UTF_8));
+ checker.checkTree(b.toString().getBytes(CHARSET));
}
@Test
@@ -1607,7 +1607,7 @@ public class ObjectCheckerTest {
checker.checkTree(encodeASCII(b.toString()));
}
- private static void entry(StringBuilder b, final String modeName) {
+ private static void entry(StringBuilder b, String modeName) {
b.append(modeName);
b.append('\0');
for (int i = 0; i < OBJECT_ID_LENGTH; i++)
@@ -1647,7 +1647,7 @@ public class ObjectCheckerTest {
checker.setSkipList(null);
}
- private static ObjectIdSet set(final ObjectId... ids) {
+ private static ObjectIdSet set(ObjectId... ids) {
return new ObjectIdSet() {
@Override
public boolean contains(AnyObjectId objectId) {
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RacyGitTests.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RacyGitTests.java
index 9236b4e821..8d9ccab1bd 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RacyGitTests.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RacyGitTests.java
@@ -176,12 +176,9 @@ public class RacyGitTests extends RepositoryTestCase {
private File addToWorkDir(String path, String content) throws IOException {
File f = new File(db.getWorkTree(), path);
- FileOutputStream fos = new FileOutputStream(f);
- try {
+ try (FileOutputStream fos = new FileOutputStream(f)) {
fos.write(content.getBytes(Constants.CHARACTER_ENCODING));
return f;
- } finally {
- fos.close();
}
}
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefTest.java
index 7fb3309982..2481e64997 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefTest.java
@@ -57,6 +57,7 @@ import static org.junit.Assert.fail;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.util.List;
import java.util.Map;
import java.util.TreeSet;
@@ -253,11 +254,11 @@ public class RefTest extends SampleDataRepositoryTestCase {
InterruptedException {
Ref ref = db.exactRef("refs/heads/master");
assertEquals(Storage.PACKED, ref.getStorage());
- FileOutputStream os = new FileOutputStream(new File(db.getDirectory(),
- "refs/heads/master"));
- os.write(ref.getObjectId().name().getBytes());
- os.write('\n');
- os.close();
+ try (FileOutputStream os = new FileOutputStream(
+ new File(db.getDirectory(), "refs/heads/master"))) {
+ os.write(ref.getObjectId().name().getBytes());
+ os.write('\n');
+ }
ref = db.exactRef("refs/heads/master");
assertEquals(Storage.LOOSE, ref.getStorage());
@@ -305,4 +306,26 @@ public class RefTest extends SampleDataRepositoryTestCase {
assertSame(dst.getPeeledObjectId(), ref.getPeeledObjectId());
assertEquals(dst.isPeeled(), ref.isPeeled());
}
+
+ private static void checkContainsRef(List<Ref> haystack, Ref needle) {
+ for (Ref ref : haystack) {
+ if (ref.getName().equals(needle.getName()) &&
+ ref.getObjectId().equals(needle.getObjectId())) {
+ return;
+ }
+ }
+ fail("list " + haystack + " does not contain ref " + needle);
+ }
+
+ @Test
+ public void testGetRefsByPrefix() throws IOException {
+ List<Ref> refs = db.getRefDatabase().getRefsByPrefix("refs/heads/g");
+ assertEquals(2, refs.size());
+ checkContainsRef(refs, db.exactRef("refs/heads/g"));
+ checkContainsRef(refs, db.exactRef("refs/heads/gitlink"));
+
+ refs = db.getRefDatabase().getRefsByPrefix("refs/heads/prefix/");
+ assertEquals(1, refs.size());
+ checkContainsRef(refs, db.exactRef("refs/heads/prefix/a"));
+ }
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryCacheTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryCacheTest.java
index 1107c2c69b..58b005c282 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryCacheTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryCacheTest.java
@@ -94,24 +94,25 @@ public class RepositoryCacheTest extends RepositoryTestCase {
@Test
public void testFileKeyOpenExisting() throws IOException {
- Repository r;
-
- r = new FileKey(db.getDirectory(), db.getFS()).open(true);
- assertNotNull(r);
- assertEqualsFile(db.getDirectory(), r.getDirectory());
- r.close();
+ try (Repository r = new FileKey(db.getDirectory(), db.getFS())
+ .open(true)) {
+ assertNotNull(r);
+ assertEqualsFile(db.getDirectory(), r.getDirectory());
+ }
- r = new FileKey(db.getDirectory(), db.getFS()).open(false);
- assertNotNull(r);
- assertEqualsFile(db.getDirectory(), r.getDirectory());
- r.close();
+ try (Repository r = new FileKey(db.getDirectory(), db.getFS())
+ .open(false)) {
+ assertNotNull(r);
+ assertEqualsFile(db.getDirectory(), r.getDirectory());
+ }
}
@Test
public void testFileKeyOpenNew() throws IOException {
- final Repository n = createRepository(true, false);
- final File gitdir = n.getDirectory();
- n.close();
+ File gitdir;
+ try (Repository n = createRepository(true, false)) {
+ gitdir = n.getDirectory();
+ }
recursiveDelete(gitdir);
assertFalse(gitdir.exists());
@@ -143,6 +144,7 @@ public class RepositoryCacheTest extends RepositoryTestCase {
@Test
public void testCacheOpen() throws Exception {
final FileKey loc = FileKey.exact(db.getDirectory(), db.getFS());
+ @SuppressWarnings("resource") // We are testing the close() method
final Repository d2 = RepositoryCache.open(loc);
assertNotSame(db, d2);
assertSame(d2, RepositoryCache.open(FileKey.exact(loc.getFile(), db.getFS())));
@@ -176,6 +178,7 @@ public class RepositoryCacheTest extends RepositoryTestCase {
@Test
public void testRepositoryUsageCount() throws Exception {
FileKey loc = FileKey.exact(db.getDirectory(), db.getFS());
+ @SuppressWarnings("resource") // We are testing the close() method
Repository d2 = RepositoryCache.open(loc);
assertEquals(1, d2.useCnt.get());
RepositoryCache.open(FileKey.exact(loc.getFile(), db.getFS()));
@@ -189,6 +192,7 @@ public class RepositoryCacheTest extends RepositoryTestCase {
@Test
public void testRepositoryUsageCountWithRegisteredRepository()
throws IOException {
+ @SuppressWarnings("resource") // We are testing the close() method
Repository repo = createRepository(false, false);
assertEquals(1, repo.useCnt.get());
RepositoryCache.register(repo);
@@ -200,6 +204,7 @@ public class RepositoryCacheTest extends RepositoryTestCase {
@Test
public void testRepositoryNotUnregisteringWhenClosing() throws Exception {
FileKey loc = FileKey.exact(db.getDirectory(), db.getFS());
+ @SuppressWarnings("resource") // We are testing the close() method
Repository d2 = RepositoryCache.open(loc);
assertEquals(1, d2.useCnt.get());
assertThat(RepositoryCache.getRegisteredKeys(),
@@ -214,6 +219,7 @@ public class RepositoryCacheTest extends RepositoryTestCase {
@Test
public void testRepositoryUnregisteringWhenExpiredAndUsageCountNegative()
throws Exception {
+ @SuppressWarnings("resource") // We are testing the close() method
Repository repoA = createBareRepository();
RepositoryCache.register(repoA);
@@ -234,7 +240,9 @@ public class RepositoryCacheTest extends RepositoryTestCase {
@Test
public void testRepositoryUnregisteringWhenExpired() throws Exception {
+ @SuppressWarnings("resource") // We are testing the close() method
Repository repoA = createRepository(true, false);
+ @SuppressWarnings("resource") // We are testing the close() method
Repository repoB = createRepository(true, false);
Repository repoC = createBareRepository();
RepositoryCache.register(repoA);
@@ -268,6 +276,7 @@ public class RepositoryCacheTest extends RepositoryTestCase {
@Test
public void testReconfigure() throws InterruptedException, IOException {
+ @SuppressWarnings("resource") // We are testing the close() method
Repository repo = createRepository(false, false);
RepositoryCache.register(repo);
assertTrue(RepositoryCache.isCached(repo));
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryResolveTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryResolveTest.java
index 1d2a4e9ab7..05b78ea195 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryResolveTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryResolveTest.java
@@ -324,6 +324,8 @@ public class RepositoryResolveTest extends SampleDataRepositoryTestCase {
assertFalse(Repository.isValidRefName("x/a\\b"));
assertFalse(Repository.isValidRefName("x/a\u0000"));
+ db.resolve("x/a@");
+
assertUnparseable(".");
assertUnparseable("x@{3");
assertUnparseable("x[b");
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/SquashCommitMsgTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/SquashCommitMsgTest.java
index 3bcd787f81..203c00e28a 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/SquashCommitMsgTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/SquashCommitMsgTest.java
@@ -66,12 +66,9 @@ public class SquashCommitMsgTest extends RepositoryTestCase {
db.writeSquashCommitMsg(null);
assertEquals(db.readSquashCommitMsg(), null);
assertFalse(new File(db.getDirectory(), Constants.SQUASH_MSG).exists());
- FileOutputStream fos = new FileOutputStream(new File(db.getDirectory(),
- Constants.SQUASH_MSG));
- try {
+ try (FileOutputStream fos = new FileOutputStream(
+ new File(db.getDirectory(), Constants.SQUASH_MSG))) {
fos.write(squashMsg.getBytes(Constants.CHARACTER_ENCODING));
- } finally {
- fos.close();
}
assertEquals(db.readSquashCommitMsg(), squashMsg);
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ValidRefNameTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ValidRefNameTest.java
index d431a8910b..87e901fcfe 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ValidRefNameTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ValidRefNameTest.java
@@ -51,7 +51,7 @@ import org.eclipse.jgit.util.SystemReader;
import org.junit.Test;
public class ValidRefNameTest {
- private static void assertValid(final boolean exp, final String name) {
+ private static void assertValid(boolean exp, String name) {
SystemReader instance = SystemReader.getInstance();
try {
setUnixSystemReader();
@@ -81,7 +81,7 @@ public class ValidRefNameTest {
});
}
- private static void assertInvalidOnWindows(final String name) {
+ private static void assertInvalidOnWindows(String name) {
SystemReader instance = SystemReader.getInstance();
try {
setUnixSystemReader();
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/CherryPickTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/CherryPickTest.java
index 4948b373d0..19f6dcbc59 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/CherryPickTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/CherryPickTest.java
@@ -183,7 +183,7 @@ public class CherryPickTest extends RepositoryTestCase {
assertFalse(tw.next());
}
- private static void assertCorrectId(final DirCache treeT, final TreeWalk tw) {
+ private static void assertCorrectId(DirCache treeT, TreeWalk tw) {
assertEquals(treeT.getEntry(tw.getPathString()).getObjectId(), tw
.getObjectId(0));
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/RecursiveMergerTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/CrissCrossMergeTest.java
index 190224a855..aaa08a9e31 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/RecursiveMergerTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/CrissCrossMergeTest.java
@@ -83,7 +83,7 @@ import org.junit.experimental.theories.Theory;
import org.junit.runner.RunWith;
@RunWith(Theories.class)
-public class RecursiveMergerTest extends RepositoryTestCase {
+public class CrissCrossMergeTest extends RepositoryTestCase {
static int counter = 0;
@DataPoints
@@ -783,7 +783,7 @@ public class RecursiveMergerTest extends RepositoryTestCase {
}
}
- private void setIndex(final ObjectId id, String path)
+ private void setIndex(ObjectId id, String path)
throws MissingObjectException, IOException {
DirCache lockedDircache;
DirCacheEditor dcedit;
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/ResolveMergerTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergerTest.java
index 9322a4734e..58093a3729 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/ResolveMergerTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergerTest.java
@@ -42,7 +42,7 @@
*/
package org.eclipse.jgit.merge;
-import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
import static org.eclipse.jgit.lib.Constants.OBJ_BLOB;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -91,19 +91,17 @@ import org.eclipse.jgit.treewalk.FileTreeIterator;
import org.eclipse.jgit.util.FS;
import org.eclipse.jgit.util.FileUtils;
import org.junit.Assert;
-import org.junit.experimental.theories.DataPoint;
+import org.junit.experimental.theories.DataPoints;
import org.junit.experimental.theories.Theories;
import org.junit.experimental.theories.Theory;
import org.junit.runner.RunWith;
@RunWith(Theories.class)
-public class ResolveMergerTest extends RepositoryTestCase {
+public class MergerTest extends RepositoryTestCase {
- @DataPoint
- public static MergeStrategy resolve = MergeStrategy.RESOLVE;
-
- @DataPoint
- public static MergeStrategy recursive = MergeStrategy.RECURSIVE;
+ @DataPoints
+ public static MergeStrategy[] strategiesUnderTest = new MergeStrategy[] {
+ MergeStrategy.RECURSIVE, MergeStrategy.RESOLVE };
@Theory
public void failingDeleteOfDirectoryWithUntrackedContent(
@@ -756,7 +754,7 @@ public class ResolveMergerTest extends RepositoryTestCase {
}
binary[50] = '\0';
- writeTrashFile("file", new String(binary, UTF_8));
+ writeTrashFile("file", new String(binary, CHARSET));
git.add().addFilepattern("file").call();
RevCommit first = git.commit().setMessage("added file").call();
@@ -764,7 +762,7 @@ public class ResolveMergerTest extends RepositoryTestCase {
int idx = LINELEN * 1200 + 1;
byte save = binary[idx];
binary[idx] = '@';
- writeTrashFile("file", new String(binary, UTF_8));
+ writeTrashFile("file", new String(binary, CHARSET));
binary[idx] = save;
git.add().addFilepattern("file").call();
@@ -773,7 +771,7 @@ public class ResolveMergerTest extends RepositoryTestCase {
git.checkout().setCreateBranch(true).setStartPoint(first).setName("side").call();
binary[LINELEN * 1500 + 1] = '!';
- writeTrashFile("file", new String(binary, UTF_8));
+ writeTrashFile("file", new String(binary, CHARSET));
git.add().addFilepattern("file").call();
RevCommit sideCommit = git.commit().setAll(true)
.setMessage("modified file l 1500").call();
@@ -935,7 +933,7 @@ public class ResolveMergerTest extends RepositoryTestCase {
merger.getMergeResults().get("file");
try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
fmt.formatMerge(out, merger.getMergeResults().get("file"),
- "BASE", "OURS", "THEIRS", UTF_8.name());
+ "BASE", "OURS", "THEIRS", CHARSET.name());
String expected = "<<<<<<< OURS\n"
+ "1master\n"
+ "=======\n"
@@ -943,7 +941,7 @@ public class ResolveMergerTest extends RepositoryTestCase {
+ ">>>>>>> THEIRS\n"
+ "2\n"
+ "3";
- assertEquals(expected, new String(out.toByteArray(), UTF_8));
+ assertEquals(expected, new String(out.toByteArray(), CHARSET));
}
}
}
@@ -1033,19 +1031,21 @@ public class ResolveMergerTest extends RepositoryTestCase {
git.commit().setMessage("added c.txt").call();
// Get a handle to the the file so on windows it can't be deleted.
- FileInputStream fis = new FileInputStream(new File(db.getWorkTree(),
- "b.txt"));
- MergeResult mergeRes = git.merge().setStrategy(strategy)
- .include(masterCommit).call();
- if (mergeRes.getMergeStatus().equals(MergeStatus.FAILED)) {
- // probably windows
- assertEquals(1, mergeRes.getFailingPaths().size());
- assertEquals(MergeFailureReason.COULD_NOT_DELETE, mergeRes
- .getFailingPaths().get("b.txt"));
+ try (FileInputStream fis = new FileInputStream(
+ new File(db.getWorkTree(), "b.txt"))) {
+ MergeResult mergeRes = git.merge().setStrategy(strategy)
+ .include(masterCommit).call();
+ if (mergeRes.getMergeStatus().equals(MergeStatus.FAILED)) {
+ // probably windows
+ assertEquals(1, mergeRes.getFailingPaths().size());
+ assertEquals(MergeFailureReason.COULD_NOT_DELETE,
+ mergeRes.getFailingPaths().get("b.txt"));
+ }
+ assertEquals(
+ "[a.txt, mode:100644, content:master]"
+ + "[c.txt, mode:100644, content:side]",
+ indexState(CONTENT));
}
- assertEquals("[a.txt, mode:100644, content:master]"
- + "[c.txt, mode:100644, content:side]", indexState(CONTENT));
- fis.close();
}
@Theory
@@ -1328,6 +1328,6 @@ public class ResolveMergerTest extends RepositoryTestCase {
if (obj == null) {
return null;
}
- return new String(rw.getObjectReader().open(obj, OBJ_BLOB).getBytes(), UTF_8);
+ return new String(rw.getObjectReader().open(obj, OBJ_BLOB).getBytes(), CHARSET);
}
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/SimpleMergeTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/SimpleMergeTest.java
index 951568e7bb..dd2c2e84b6 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/SimpleMergeTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/SimpleMergeTest.java
@@ -403,7 +403,7 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase {
assertFalse(merge);
}
- private static void assertCorrectId(final DirCache treeT, final TreeWalk tw) {
+ private static void assertCorrectId(DirCache treeT, TreeWalk tw) {
assertEquals(treeT.getEntry(tw.getPathString()).getObjectId(), tw
.getObjectId(0));
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/EditListTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/EditListTest.java
index 6027aff716..6c107f983d 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/EditListTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/EditListTest.java
@@ -89,7 +89,7 @@ public class EditListTest {
assertEquals(new Edit(23 - 1, 25 - 1, 22 - 1, 28 - 1), e.get(2));
}
- private Patch parseTestPatchFile(final String patchFile) throws IOException {
+ private Patch parseTestPatchFile(String patchFile) throws IOException {
try (InputStream in = getClass().getResourceAsStream(patchFile)) {
if (in == null) {
fail("No " + patchFile + " test vector");
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/FileHeaderTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/FileHeaderTest.java
index 7b4e014449..24fbda1adb 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/FileHeaderTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/FileHeaderTest.java
@@ -433,30 +433,30 @@ public class FileHeaderTest {
assertTrue(ObjectId.fromString(nid).startsWith(fh.getNewId()));
}
- private static void assertParse(final FileHeader fh) {
+ private static void assertParse(FileHeader fh) {
int ptr = fh.parseGitFileName(0, fh.buf.length);
assertTrue(ptr > 0);
ptr = fh.parseGitHeaders(ptr, fh.buf.length);
assertTrue(ptr > 0);
}
- private static FileHeader data(final String in) {
+ private static FileHeader data(String in) {
return new FileHeader(Constants.encodeASCII(in), 0);
}
- private static FileHeader header(final String path) {
+ private static FileHeader header(String path) {
return data(gitLine(path) + "--- " + path + "\n");
}
- private static String gitLine(final String path) {
+ private static String gitLine(String path) {
return "a/" + path + " b/" + path + "\n";
}
- private static FileHeader dqHeader(final String path) {
+ private static FileHeader dqHeader(String path) {
return data(dqGitLine(path) + "--- " + path + "\n");
}
- private static String dqGitLine(final String path) {
+ private static String dqGitLine(String path) {
return "\"a/" + path + "\" \"b/" + path + "\"\n";
}
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/GetTextTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/GetTextTest.java
index 65375c7ae0..7b5868a393 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/GetTextTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/GetTextTest.java
@@ -44,7 +44,7 @@
package org.eclipse.jgit.patch;
import static java.nio.charset.StandardCharsets.ISO_8859_1;
-import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -83,7 +83,7 @@ public class GetTextTest {
@Test
public void testGetText_Convert() throws IOException {
final Charset csOld = ISO_8859_1;
- final Charset csNew = UTF_8;
+ final Charset csNew = CHARSET;
final Patch p = parseTestPatchFile();
assertTrue(p.getErrors().isEmpty());
assertEquals(1, p.getFiles().size());
@@ -103,7 +103,7 @@ public class GetTextTest {
@Test
public void testGetText_DiffCc() throws IOException {
final Charset csOld = ISO_8859_1;
- final Charset csNew = UTF_8;
+ final Charset csNew = CHARSET;
final Patch p = parseTestPatchFile();
assertTrue(p.getErrors().isEmpty());
assertEquals(1, p.getFiles().size());
@@ -134,7 +134,7 @@ public class GetTextTest {
}
}
- private String readTestPatchFile(final Charset cs) throws IOException {
+ private String readTestPatchFile(Charset cs) throws IOException {
final String patchFile = JGitTestUtil.getName() + ".patch";
try (InputStream in = getClass().getResourceAsStream(patchFile)) {
if (in == null) {
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchCcErrorTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchCcErrorTest.java
index e4b43172d6..6989343362 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchCcErrorTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchCcErrorTest.java
@@ -96,17 +96,14 @@ public class PatchCcErrorTest {
private Patch parseTestPatchFile() throws IOException {
final String patchFile = JGitTestUtil.getName() + ".patch";
- final InputStream in = getClass().getResourceAsStream(patchFile);
- if (in == null) {
- fail("No " + patchFile + " test vector");
- return null; // Never happens
- }
- try {
+ try (InputStream in = getClass().getResourceAsStream(patchFile)) {
+ if (in == null) {
+ fail("No " + patchFile + " test vector");
+ return null; // Never happens
+ }
final Patch p = new Patch();
p.parse(in);
return p;
- } finally {
- in.close();
}
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchCcTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchCcTest.java
index 837414b054..4a26d50e49 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchCcTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchCcTest.java
@@ -199,17 +199,14 @@ public class PatchCcTest {
private Patch parseTestPatchFile() throws IOException {
final String patchFile = JGitTestUtil.getName() + ".patch";
- final InputStream in = getClass().getResourceAsStream(patchFile);
- if (in == null) {
- fail("No " + patchFile + " test vector");
- return null; // Never happens
- }
- try {
+ try (InputStream in = getClass().getResourceAsStream(patchFile)) {
+ if (in == null) {
+ fail("No " + patchFile + " test vector");
+ return null; // Never happens
+ }
final Patch p = new Patch();
p.parse(in);
return p;
- } finally {
- in.close();
}
}
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchErrorTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchErrorTest.java
index 52e3874b6c..3bdf852167 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchErrorTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchErrorTest.java
@@ -177,17 +177,14 @@ public class PatchErrorTest {
private Patch parseTestPatchFile() throws IOException {
final String patchFile = JGitTestUtil.getName() + ".patch";
- final InputStream in = getClass().getResourceAsStream(patchFile);
- if (in == null) {
- fail("No " + patchFile + " test vector");
- return null; // Never happens
- }
- try {
+ try (InputStream in = getClass().getResourceAsStream(patchFile)) {
+ if (in == null) {
+ fail("No " + patchFile + " test vector");
+ return null; // Never happens
+ }
final Patch p = new Patch();
p.parse(in);
return p;
- } finally {
- in.close();
}
}
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchTest.java
index 9f57ab98c0..6a09a4919e 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchTest.java
@@ -357,17 +357,14 @@ public class PatchTest {
private Patch parseTestPatchFile() throws IOException {
final String patchFile = JGitTestUtil.getName() + ".patch";
- final InputStream in = getClass().getResourceAsStream(patchFile);
- if (in == null) {
- fail("No " + patchFile + " test vector");
- return null; // Never happens
- }
- try {
+ try (InputStream in = getClass().getResourceAsStream(patchFile)) {
+ if (in == null) {
+ fail("No " + patchFile + " test vector");
+ return null; // Never happens
+ }
final Patch p = new Patch();
p.parse(in);
return p;
- } finally {
- in.close();
}
}
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/FooterLineTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/FooterLineTest.java
index 87c8547812..ad8327ff4e 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/FooterLineTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/FooterLineTest.java
@@ -353,7 +353,7 @@ public class FooterLineTest extends RepositoryTestCase {
assertFalse("not CC", line.matches(FooterKey.CC));
}
- private RevCommit parse(final String msg) throws IOException {
+ private RevCommit parse(String msg) throws IOException {
final StringBuilder buf = new StringBuilder();
buf.append("tree " + ObjectId.zeroId().name() + "\n");
buf.append("author A. U. Thor <a@example.com> 1 +0000\n");
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevCommitParseTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevCommitParseTest.java
index 88f240bb1f..cfefac3aa1 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevCommitParseTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevCommitParseTest.java
@@ -44,7 +44,7 @@
package org.eclipse.jgit.revwalk;
import static java.nio.charset.StandardCharsets.ISO_8859_1;
-import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
@@ -114,7 +114,7 @@ public class RevCommitParseTest extends RepositoryTestCase {
assertNull(c.getTree());
assertNull(c.parents);
- c.parseCanonical(rw, body.toString().getBytes(UTF_8));
+ c.parseCanonical(rw, body.toString().getBytes(CHARSET));
assertNotNull(c.getTree());
assertEquals(treeId, c.getTree().getId());
assertSame(rw.lookupTree(treeId), c.getTree());
@@ -138,7 +138,7 @@ public class RevCommitParseTest extends RepositoryTestCase {
assertEquals(TimeZone.getTimeZone("GMT" + committerTimeZone), cCommitter.getTimeZone());
}
- private RevCommit create(final String msg) throws Exception {
+ private RevCommit create(String msg) throws Exception {
final StringBuilder b = new StringBuilder();
b.append("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n");
b.append("author A U. Thor <a_u_thor@example.com> 1218123387 +0700\n");
@@ -148,7 +148,7 @@ public class RevCommitParseTest extends RepositoryTestCase {
final RevCommit c;
c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
- c.parseCanonical(new RevWalk(db), b.toString().getBytes(UTF_8));
+ c.parseCanonical(new RevWalk(db), b.toString().getBytes(CHARSET));
return c;
}
@@ -161,7 +161,7 @@ public class RevCommitParseTest extends RepositoryTestCase {
final RevCommit c;
c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
- c.parseCanonical(new RevWalk(db), b.toString().getBytes(UTF_8));
+ c.parseCanonical(new RevWalk(db), b.toString().getBytes(CHARSET));
assertEquals("", c.getFullMessage());
assertEquals("", c.getShortMessage());
@@ -176,7 +176,7 @@ public class RevCommitParseTest extends RepositoryTestCase {
final RevCommit c;
c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
- c.parseCanonical(new RevWalk(db), b.toString().getBytes(UTF_8));
+ c.parseCanonical(new RevWalk(db), b.toString().getBytes(CHARSET));
assertEquals(new PersonIdent("", "a_u_thor@example.com", 1218123387000l, 7), c.getAuthorIdent());
assertEquals(new PersonIdent("", "", 1218123390000l, -5), c.getCommitterIdent());
@@ -185,13 +185,13 @@ public class RevCommitParseTest extends RepositoryTestCase {
@Test
public void testParse_implicit_UTF8_encoded() throws Exception {
final ByteArrayOutputStream b = new ByteArrayOutputStream();
- b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(UTF_8));
- b.write("author F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n".getBytes(UTF_8));
- b.write("committer C O. Miter <c@example.com> 1218123390 -0500\n".getBytes(UTF_8));
- b.write("\n".getBytes(UTF_8));
- b.write("Sm\u00f6rg\u00e5sbord\n".getBytes(UTF_8));
- b.write("\n".getBytes(UTF_8));
- b.write("\u304d\u308c\u3044\n".getBytes(UTF_8));
+ b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(CHARSET));
+ b.write("author F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n".getBytes(CHARSET));
+ b.write("committer C O. Miter <c@example.com> 1218123390 -0500\n".getBytes(CHARSET));
+ b.write("\n".getBytes(CHARSET));
+ b.write("Sm\u00f6rg\u00e5sbord\n".getBytes(CHARSET));
+ b.write("\n".getBytes(CHARSET));
+ b.write("\u304d\u308c\u3044\n".getBytes(CHARSET));
final RevCommit c;
c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); // bogus id
c.parseCanonical(new RevWalk(db), b.toByteArray());
@@ -205,13 +205,13 @@ public class RevCommitParseTest extends RepositoryTestCase {
@Test
public void testParse_implicit_mixed_encoded() throws Exception {
final ByteArrayOutputStream b = new ByteArrayOutputStream();
- b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(UTF_8));
+ b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(CHARSET));
b.write("author F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n".getBytes(ISO_8859_1));
- b.write("committer C O. Miter <c@example.com> 1218123390 -0500\n".getBytes(UTF_8));
- b.write("\n".getBytes(UTF_8));
- b.write("Sm\u00f6rg\u00e5sbord\n".getBytes(UTF_8));
- b.write("\n".getBytes(UTF_8));
- b.write("\u304d\u308c\u3044\n".getBytes(UTF_8));
+ b.write("committer C O. Miter <c@example.com> 1218123390 -0500\n".getBytes(CHARSET));
+ b.write("\n".getBytes(CHARSET));
+ b.write("Sm\u00f6rg\u00e5sbord\n".getBytes(CHARSET));
+ b.write("\n".getBytes(CHARSET));
+ b.write("\u304d\u308c\u3044\n".getBytes(CHARSET));
final RevCommit c;
c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); // bogus id
c.parseCanonical(new RevWalk(db), b.toByteArray());
@@ -260,14 +260,14 @@ public class RevCommitParseTest extends RepositoryTestCase {
@Test
public void testParse_explicit_bad_encoded() throws Exception {
final ByteArrayOutputStream b = new ByteArrayOutputStream();
- b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(UTF_8));
+ b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(CHARSET));
b.write("author F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n".getBytes(ISO_8859_1));
- b.write("committer C O. Miter <c@example.com> 1218123390 -0500\n".getBytes(UTF_8));
- b.write("encoding EUC-JP\n".getBytes(UTF_8));
- b.write("\n".getBytes(UTF_8));
- b.write("\u304d\u308c\u3044\n".getBytes(UTF_8));
- b.write("\n".getBytes(UTF_8));
- b.write("Hi\n".getBytes(UTF_8));
+ b.write("committer C O. Miter <c@example.com> 1218123390 -0500\n".getBytes(CHARSET));
+ b.write("encoding EUC-JP\n".getBytes(CHARSET));
+ b.write("\n".getBytes(CHARSET));
+ b.write("\u304d\u308c\u3044\n".getBytes(CHARSET));
+ b.write("\n".getBytes(CHARSET));
+ b.write("Hi\n".getBytes(CHARSET));
final RevCommit c;
c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); // bogus id
c.parseCanonical(new RevWalk(db), b.toByteArray());
@@ -291,14 +291,14 @@ public class RevCommitParseTest extends RepositoryTestCase {
@Test
public void testParse_explicit_bad_encoded2() throws Exception {
final ByteArrayOutputStream b = new ByteArrayOutputStream();
- b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(UTF_8));
- b.write("author F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n".getBytes(UTF_8));
- b.write("committer C O. Miter <c@example.com> 1218123390 -0500\n".getBytes(UTF_8));
- b.write("encoding ISO-8859-1\n".getBytes(UTF_8));
- b.write("\n".getBytes(UTF_8));
- b.write("\u304d\u308c\u3044\n".getBytes(UTF_8));
- b.write("\n".getBytes(UTF_8));
- b.write("Hi\n".getBytes(UTF_8));
+ b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(CHARSET));
+ b.write("author F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n".getBytes(CHARSET));
+ b.write("committer C O. Miter <c@example.com> 1218123390 -0500\n".getBytes(CHARSET));
+ b.write("encoding ISO-8859-1\n".getBytes(CHARSET));
+ b.write("\n".getBytes(CHARSET));
+ b.write("\u304d\u308c\u3044\n".getBytes(CHARSET));
+ b.write("\n".getBytes(CHARSET));
+ b.write("Hi\n".getBytes(CHARSET));
final RevCommit c;
c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); // bogus id
c.parseCanonical(new RevWalk(db), b.toByteArray());
@@ -313,13 +313,13 @@ public class RevCommitParseTest extends RepositoryTestCase {
public void testParse_incorrectUtf8Name() throws Exception {
ByteArrayOutputStream b = new ByteArrayOutputStream();
b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n"
- .getBytes(UTF_8));
- b.write("author au <a@example.com> 1218123387 +0700\n".getBytes(UTF_8));
+ .getBytes(CHARSET));
+ b.write("author au <a@example.com> 1218123387 +0700\n".getBytes(CHARSET));
b.write("committer co <c@example.com> 1218123390 -0500\n"
- .getBytes(UTF_8));
- b.write("encoding 'utf8'\n".getBytes(UTF_8));
- b.write("\n".getBytes(UTF_8));
- b.write("Sm\u00f6rg\u00e5sbord\n".getBytes(UTF_8));
+ .getBytes(CHARSET));
+ b.write("encoding 'utf8'\n".getBytes(CHARSET));
+ b.write("\n".getBytes(CHARSET));
+ b.write("Sm\u00f6rg\u00e5sbord\n".getBytes(CHARSET));
RevCommit c = new RevCommit(
id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
@@ -338,12 +338,12 @@ public class RevCommitParseTest extends RepositoryTestCase {
@Test
public void testParse_illegalEncoding() throws Exception {
ByteArrayOutputStream b = new ByteArrayOutputStream();
- b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(UTF_8));
- b.write("author au <a@example.com> 1218123387 +0700\n".getBytes(UTF_8));
- b.write("committer co <c@example.com> 1218123390 -0500\n".getBytes(UTF_8));
- b.write("encoding utf-8logoutputencoding=gbk\n".getBytes(UTF_8));
- b.write("\n".getBytes(UTF_8));
- b.write("message\n".getBytes(UTF_8));
+ b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(CHARSET));
+ b.write("author au <a@example.com> 1218123387 +0700\n".getBytes(CHARSET));
+ b.write("committer co <c@example.com> 1218123390 -0500\n".getBytes(CHARSET));
+ b.write("encoding utf-8logoutputencoding=gbk\n".getBytes(CHARSET));
+ b.write("\n".getBytes(CHARSET));
+ b.write("message\n".getBytes(CHARSET));
RevCommit c = new RevCommit(
id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
@@ -365,12 +365,12 @@ public class RevCommitParseTest extends RepositoryTestCase {
@Test
public void testParse_unsupportedEncoding() throws Exception {
ByteArrayOutputStream b = new ByteArrayOutputStream();
- b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(UTF_8));
- b.write("author au <a@example.com> 1218123387 +0700\n".getBytes(UTF_8));
- b.write("committer co <c@example.com> 1218123390 -0500\n".getBytes(UTF_8));
- b.write("encoding it_IT.UTF8\n".getBytes(UTF_8));
- b.write("\n".getBytes(UTF_8));
- b.write("message\n".getBytes(UTF_8));
+ b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(CHARSET));
+ b.write("author au <a@example.com> 1218123387 +0700\n".getBytes(CHARSET));
+ b.write("committer co <c@example.com> 1218123390 -0500\n".getBytes(CHARSET));
+ b.write("encoding it_IT.UTF8\n".getBytes(CHARSET));
+ b.write("\n".getBytes(CHARSET));
+ b.write("message\n".getBytes(CHARSET));
RevCommit c = new RevCommit(
id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
@@ -483,7 +483,7 @@ public class RevCommitParseTest extends RepositoryTestCase {
assertEquals(shortMsg, c.getShortMessage());
}
- private static ObjectId id(final String str) {
+ private static ObjectId id(String str) {
return ObjectId.fromString(str);
}
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevObjectTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevObjectTest.java
index 122a3973d0..8e389ae252 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevObjectTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevObjectTest.java
@@ -76,7 +76,7 @@ public class RevObjectTest extends RevWalkTestCase {
final RevCommit a2;
final RevCommit b2;
- try (final RevWalk rw2 = new RevWalk(db)) {
+ try (RevWalk rw2 = new RevWalk(db)) {
a2 = rw2.parseCommit(a1);
b2 = rw2.parseCommit(b1);
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevTagParseTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevTagParseTest.java
index 38bd371b90..e11cef7c92 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevTagParseTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevTagParseTest.java
@@ -44,7 +44,7 @@
package org.eclipse.jgit.revwalk;
import static java.nio.charset.StandardCharsets.ISO_8859_1;
-import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
@@ -82,7 +82,7 @@ public class RevTagParseTest extends RepositoryTestCase {
testOneType(Constants.OBJ_TAG);
}
- private void testOneType(final int typeCode) throws Exception {
+ private void testOneType(int typeCode) throws Exception {
final ObjectId id = id("9788669ad918b6fcce64af8882fc9a81cb6aba67");
final StringBuilder b = new StringBuilder();
b.append("object " + id.name() + "\n");
@@ -98,7 +98,7 @@ public class RevTagParseTest extends RepositoryTestCase {
assertNull(c.getObject());
assertNull(c.getTagName());
- c.parseCanonical(rw, b.toString().getBytes(UTF_8));
+ c.parseCanonical(rw, b.toString().getBytes(CHARSET));
assertNotNull(c.getObject());
assertEquals(id, c.getObject().getId());
assertSame(rw.lookupAny(id, typeCode), c.getObject());
@@ -141,7 +141,7 @@ public class RevTagParseTest extends RepositoryTestCase {
assertNull(c.getObject());
assertNull(c.getTagName());
- c.parseCanonical(rw, body.toString().getBytes(UTF_8));
+ c.parseCanonical(rw, body.toString().getBytes(CHARSET));
assertNotNull(c.getObject());
assertEquals(treeId, c.getObject().getId());
assertSame(rw.lookupTree(treeId), c.getObject());
@@ -189,7 +189,7 @@ public class RevTagParseTest extends RepositoryTestCase {
assertNull(c.getObject());
assertNull(c.getTagName());
- c.parseCanonical(rw, body.toString().getBytes(UTF_8));
+ c.parseCanonical(rw, body.toString().getBytes(CHARSET));
assertNotNull(c.getObject());
assertEquals(treeId, c.getObject().getId());
assertSame(rw.lookupTree(treeId), c.getObject());
@@ -202,7 +202,7 @@ public class RevTagParseTest extends RepositoryTestCase {
assertNull(c.getTaggerIdent());
}
- private RevTag create(final String msg) throws Exception {
+ private RevTag create(String msg) throws Exception {
final StringBuilder b = new StringBuilder();
b.append("object 9788669ad918b6fcce64af8882fc9a81cb6aba67\n");
b.append("type tree\n");
@@ -213,7 +213,7 @@ public class RevTagParseTest extends RepositoryTestCase {
final RevTag c;
c = new RevTag(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
- c.parseCanonical(new RevWalk(db), b.toString().getBytes(UTF_8));
+ c.parseCanonical(new RevWalk(db), b.toString().getBytes(CHARSET));
return c;
}
@@ -221,17 +221,17 @@ public class RevTagParseTest extends RepositoryTestCase {
public void testParse_implicit_UTF8_encoded() throws Exception {
final ByteArrayOutputStream b = new ByteArrayOutputStream();
b.write("object 9788669ad918b6fcce64af8882fc9a81cb6aba67\n"
- .getBytes(UTF_8));
- b.write("type tree\n".getBytes(UTF_8));
- b.write("tag v1.2.3.4.5\n".getBytes(UTF_8));
+ .getBytes(CHARSET));
+ b.write("type tree\n".getBytes(CHARSET));
+ b.write("tag v1.2.3.4.5\n".getBytes(CHARSET));
b
.write("tagger F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n"
- .getBytes(UTF_8));
- b.write("\n".getBytes(UTF_8));
- b.write("Sm\u00f6rg\u00e5sbord\n".getBytes(UTF_8));
- b.write("\n".getBytes(UTF_8));
- b.write("\u304d\u308c\u3044\n".getBytes(UTF_8));
+ .getBytes(CHARSET));
+ b.write("\n".getBytes(CHARSET));
+ b.write("Sm\u00f6rg\u00e5sbord\n".getBytes(CHARSET));
+ b.write("\n".getBytes(CHARSET));
+ b.write("\u304d\u308c\u3044\n".getBytes(CHARSET));
final RevTag c;
c = new RevTag(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
c.parseCanonical(new RevWalk(db), b.toByteArray());
@@ -246,15 +246,15 @@ public class RevTagParseTest extends RepositoryTestCase {
public void testParse_implicit_mixed_encoded() throws Exception {
final ByteArrayOutputStream b = new ByteArrayOutputStream();
b.write("object 9788669ad918b6fcce64af8882fc9a81cb6aba67\n"
- .getBytes(UTF_8));
- b.write("type tree\n".getBytes(UTF_8));
- b.write("tag v1.2.3.4.5\n".getBytes(UTF_8));
+ .getBytes(CHARSET));
+ b.write("type tree\n".getBytes(CHARSET));
+ b.write("tag v1.2.3.4.5\n".getBytes(CHARSET));
b.write("tagger F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n"
.getBytes(ISO_8859_1));
- b.write("\n".getBytes(UTF_8));
- b.write("Sm\u00f6rg\u00e5sbord\n".getBytes(UTF_8));
- b.write("\n".getBytes(UTF_8));
- b.write("\u304d\u308c\u3044\n".getBytes(UTF_8));
+ b.write("\n".getBytes(CHARSET));
+ b.write("Sm\u00f6rg\u00e5sbord\n".getBytes(CHARSET));
+ b.write("\n".getBytes(CHARSET));
+ b.write("\u304d\u308c\u3044\n".getBytes(CHARSET));
final RevTag c;
c = new RevTag(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
c.parseCanonical(new RevWalk(db), b.toByteArray());
@@ -307,17 +307,17 @@ public class RevTagParseTest extends RepositoryTestCase {
public void testParse_explicit_bad_encoded() throws Exception {
final ByteArrayOutputStream b = new ByteArrayOutputStream();
b.write("object 9788669ad918b6fcce64af8882fc9a81cb6aba67\n"
- .getBytes(UTF_8));
- b.write("type tree\n".getBytes(UTF_8));
- b.write("tag v1.2.3.4.5\n".getBytes(UTF_8));
+ .getBytes(CHARSET));
+ b.write("type tree\n".getBytes(CHARSET));
+ b.write("tag v1.2.3.4.5\n".getBytes(CHARSET));
b
.write("tagger F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n"
.getBytes(ISO_8859_1));
- b.write("encoding EUC-JP\n".getBytes(UTF_8));
- b.write("\n".getBytes(UTF_8));
- b.write("\u304d\u308c\u3044\n".getBytes(UTF_8));
- b.write("\n".getBytes(UTF_8));
- b.write("Hi\n".getBytes(UTF_8));
+ b.write("encoding EUC-JP\n".getBytes(CHARSET));
+ b.write("\n".getBytes(CHARSET));
+ b.write("\u304d\u308c\u3044\n".getBytes(CHARSET));
+ b.write("\n".getBytes(CHARSET));
+ b.write("Hi\n".getBytes(CHARSET));
final RevTag c;
c = new RevTag(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
c.parseCanonical(new RevWalk(db), b.toByteArray());
@@ -342,17 +342,17 @@ public class RevTagParseTest extends RepositoryTestCase {
public void testParse_explicit_bad_encoded2() throws Exception {
final ByteArrayOutputStream b = new ByteArrayOutputStream();
b.write("object 9788669ad918b6fcce64af8882fc9a81cb6aba67\n"
- .getBytes(UTF_8));
- b.write("type tree\n".getBytes(UTF_8));
- b.write("tag v1.2.3.4.5\n".getBytes(UTF_8));
+ .getBytes(CHARSET));
+ b.write("type tree\n".getBytes(CHARSET));
+ b.write("tag v1.2.3.4.5\n".getBytes(CHARSET));
b
.write("tagger F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n"
- .getBytes(UTF_8));
- b.write("encoding ISO-8859-1\n".getBytes(UTF_8));
- b.write("\n".getBytes(UTF_8));
- b.write("\u304d\u308c\u3044\n".getBytes(UTF_8));
- b.write("\n".getBytes(UTF_8));
- b.write("Hi\n".getBytes(UTF_8));
+ .getBytes(CHARSET));
+ b.write("encoding ISO-8859-1\n".getBytes(CHARSET));
+ b.write("\n".getBytes(CHARSET));
+ b.write("\u304d\u308c\u3044\n".getBytes(CHARSET));
+ b.write("\n".getBytes(CHARSET));
+ b.write("Hi\n".getBytes(CHARSET));
final RevTag c;
c = new RevTag(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
c.parseCanonical(new RevWalk(db), b.toByteArray());
@@ -365,13 +365,13 @@ public class RevTagParseTest extends RepositoryTestCase {
@Test
public void testParse_illegalEncoding() throws Exception {
ByteArrayOutputStream b = new ByteArrayOutputStream();
- b.write("object 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(UTF_8));
- b.write("type tree\n".getBytes(UTF_8));
- b.write("tag v1.0\n".getBytes(UTF_8));
- b.write("tagger t <t@example.com> 1218123387 +0700\n".getBytes(UTF_8));
- b.write("encoding utf-8logoutputencoding=gbk\n".getBytes(UTF_8));
- b.write("\n".getBytes(UTF_8));
- b.write("message\n".getBytes(UTF_8));
+ b.write("object 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(CHARSET));
+ b.write("type tree\n".getBytes(CHARSET));
+ b.write("tag v1.0\n".getBytes(CHARSET));
+ b.write("tagger t <t@example.com> 1218123387 +0700\n".getBytes(CHARSET));
+ b.write("encoding utf-8logoutputencoding=gbk\n".getBytes(CHARSET));
+ b.write("\n".getBytes(CHARSET));
+ b.write("message\n".getBytes(CHARSET));
RevTag t = new RevTag(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
t.parseCanonical(new RevWalk(db), b.toByteArray());
@@ -384,13 +384,13 @@ public class RevTagParseTest extends RepositoryTestCase {
@Test
public void testParse_unsupportedEncoding() throws Exception {
ByteArrayOutputStream b = new ByteArrayOutputStream();
- b.write("object 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(UTF_8));
- b.write("type tree\n".getBytes(UTF_8));
- b.write("tag v1.0\n".getBytes(UTF_8));
- b.write("tagger t <t@example.com> 1218123387 +0700\n".getBytes(UTF_8));
- b.write("encoding it_IT.UTF8\n".getBytes(UTF_8));
- b.write("\n".getBytes(UTF_8));
- b.write("message\n".getBytes(UTF_8));
+ b.write("object 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(CHARSET));
+ b.write("type tree\n".getBytes(CHARSET));
+ b.write("tag v1.0\n".getBytes(CHARSET));
+ b.write("tagger t <t@example.com> 1218123387 +0700\n".getBytes(CHARSET));
+ b.write("encoding it_IT.UTF8\n".getBytes(CHARSET));
+ b.write("\n".getBytes(CHARSET));
+ b.write("message\n".getBytes(CHARSET));
RevTag t = new RevTag(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
t.parseCanonical(new RevWalk(db), b.toByteArray());
@@ -480,7 +480,7 @@ public class RevTagParseTest extends RepositoryTestCase {
assertEquals(src.getMessage(), p.getFullMessage());
}
- private static ObjectId id(final String str) {
+ private static ObjectId id(String str) {
return ObjectId.fromString(str);
}
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkFollowFilterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkFollowFilterTest.java
index ab2705cbec..70050270d3 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkFollowFilterTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkFollowFilterTest.java
@@ -75,7 +75,7 @@ public class RevWalkFollowFilterTest extends RevWalkTestCase {
diffCollector = new DiffCollector();
}
- protected FollowFilter follow(final String followPath) {
+ protected FollowFilter follow(String followPath) {
FollowFilter followFilter =
FollowFilter.create(followPath, new Config().get(DiffConfig.KEY));
followFilter.setRenameCallback(diffCollector);
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkPathFilter1Test.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkPathFilter1Test.java
index 6ec529c319..b55a45aa6c 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkPathFilter1Test.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkPathFilter1Test.java
@@ -54,7 +54,7 @@ import org.eclipse.jgit.treewalk.filter.TreeFilter;
import org.junit.Test;
public class RevWalkPathFilter1Test extends RevWalkTestCase {
- protected void filter(final String path) {
+ protected void filter(String path) {
rw.setTreeFilter(AndTreeFilter.create(PathFilterGroup
.createFromStrings(Collections.singleton(path)),
TreeFilter.ANY_DIFF));
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkPathFilter6012Test.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkPathFilter6012Test.java
index 631e3956fc..cef55210f0 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkPathFilter6012Test.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkPathFilter6012Test.java
@@ -102,17 +102,17 @@ public class RevWalkPathFilter6012Test extends RevWalkTestCase {
}
}
- protected void check(final RevCommit... order) throws Exception {
+ protected void check(RevCommit... order) throws Exception {
markStart(i);
final StringBuilder act = new StringBuilder();
- for (final RevCommit z : rw) {
+ for (RevCommit z : rw) {
final String name = byName.get(z);
assertNotNull(name);
act.append(name);
act.append(' ');
}
final StringBuilder exp = new StringBuilder();
- for (final RevCommit z : order) {
+ for (RevCommit z : order) {
final String name = byName.get(z);
assertNotNull(name);
exp.append(name);
@@ -121,7 +121,7 @@ public class RevWalkPathFilter6012Test extends RevWalkTestCase {
assertEquals(exp.toString(), act.toString());
}
- protected void filter(final String path) {
+ protected void filter(String path) {
rw.setTreeFilter(AndTreeFilter.create(PathFilterGroup
.createFromStrings(Collections.singleton(path)),
TreeFilter.ANY_DIFF));
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkTestCase.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkTestCase.java
index f12cc0872f..544398219f 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkTestCase.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkTestCase.java
@@ -74,38 +74,38 @@ public abstract class RevWalkTestCase extends RepositoryTestCase {
return util.getDate();
}
- protected void tick(final int secDelta) {
+ protected void tick(int secDelta) {
util.tick(secDelta);
}
- protected RevBlob blob(final String content) throws Exception {
+ protected RevBlob blob(String content) throws Exception {
return util.blob(content);
}
- protected DirCacheEntry file(final String path, final RevBlob blob)
+ protected DirCacheEntry file(String path, RevBlob blob)
throws Exception {
return util.file(path, blob);
}
- protected RevTree tree(final DirCacheEntry... entries) throws Exception {
+ protected RevTree tree(DirCacheEntry... entries) throws Exception {
return util.tree(entries);
}
- protected RevObject get(final RevTree tree, final String path)
+ protected RevObject get(RevTree tree, String path)
throws Exception {
return util.get(tree, path);
}
- protected RevCommit commit(final RevCommit... parents) throws Exception {
+ protected RevCommit commit(RevCommit... parents) throws Exception {
return util.commit(parents);
}
- protected RevCommit commit(final RevTree tree, final RevCommit... parents)
+ protected RevCommit commit(RevTree tree, RevCommit... parents)
throws Exception {
return util.commit(tree, parents);
}
- protected RevCommit commit(final int secDelta, final RevCommit... parents)
+ protected RevCommit commit(int secDelta, RevCommit... parents)
throws Exception {
return util.commit(secDelta, parents);
}
@@ -115,7 +115,7 @@ public abstract class RevWalkTestCase extends RepositoryTestCase {
return util.commit(secDelta, tree, parents);
}
- protected RevTag tag(final String name, final RevObject dst)
+ protected RevTag tag(String name, RevObject dst)
throws Exception {
return util.tag(name, dst);
}
@@ -125,19 +125,19 @@ public abstract class RevWalkTestCase extends RepositoryTestCase {
return util.commit();
}
- protected <T extends RevObject> T parseBody(final T t) throws Exception {
+ protected <T extends RevObject> T parseBody(T t) throws Exception {
return util.parseBody(t);
}
- protected void markStart(final RevCommit commit) throws Exception {
+ protected void markStart(RevCommit commit) throws Exception {
rw.markStart(commit);
}
- protected void markUninteresting(final RevCommit commit) throws Exception {
+ protected void markUninteresting(RevCommit commit) throws Exception {
rw.markUninteresting(commit);
}
- protected void assertCommit(final RevCommit exp, final RevCommit act) {
+ protected void assertCommit(RevCommit exp, RevCommit act) {
assertSame(exp, act);
}
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkUtilsReachableTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkUtilsReachableTest.java
index 10bea0a8b5..a26ae10af3 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkUtilsReachableTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkUtilsReachableTest.java
@@ -109,7 +109,7 @@ public class RevWalkUtilsReachableTest extends RevWalkTestCase {
}
}
- private Ref branch(final String name, final RevCommit dst) throws Exception {
+ private Ref branch(String name, RevCommit dst) throws Exception {
return Git.wrap(db).branchCreate().setName(name)
.setStartPoint(dst.name()).call();
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/FileBasedConfigTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/FileBasedConfigTest.java
index 7f0d60295c..0dea5ce97b 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/FileBasedConfigTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/FileBasedConfigTest.java
@@ -42,7 +42,7 @@
*/
package org.eclipse.jgit.storage.file;
-import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
import static org.eclipse.jgit.util.FileUtils.pathToString;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
@@ -105,7 +105,7 @@ public class FileBasedConfigTest {
@Test
public void testUTF8withoutBOM() throws IOException, ConfigInvalidException {
- final File file = createFile(CONTENT1.getBytes(UTF_8));
+ final File file = createFile(CONTENT1.getBytes(CHARSET));
final FileBasedConfig config = new FileBasedConfig(file, FS.DETECTED);
config.load();
assertEquals(ALICE, config.getString(USER, null, NAME));
@@ -121,7 +121,7 @@ public class FileBasedConfigTest {
bos1.write(0xEF);
bos1.write(0xBB);
bos1.write(0xBF);
- bos1.write(CONTENT1.getBytes(UTF_8));
+ bos1.write(CONTENT1.getBytes(CHARSET));
final File file = createFile(bos1.toByteArray());
final FileBasedConfig config = new FileBasedConfig(file, FS.DETECTED);
@@ -135,7 +135,7 @@ public class FileBasedConfigTest {
bos2.write(0xEF);
bos2.write(0xBB);
bos2.write(0xBF);
- bos2.write(CONTENT2.getBytes(UTF_8));
+ bos2.write(CONTENT2.getBytes(CHARSET));
assertArrayEquals(bos2.toByteArray(), IO.readFully(file));
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleAddTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleAddTest.java
index f42dd02814..1a67e41976 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleAddTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleAddTest.java
@@ -129,10 +129,11 @@ public class SubmoduleAddTest extends RepositoryTestCase {
command.setPath(path);
String uri = db.getDirectory().toURI().toString();
command.setURI(uri);
- Repository repo = command.call();
- assertNotNull(repo);
- ObjectId subCommit = repo.resolve(Constants.HEAD);
- repo.close();
+ ObjectId subCommit;
+ try (Repository repo = command.call()) {
+ assertNotNull(repo);
+ subCommit = repo.resolve(Constants.HEAD);
+ }
SubmoduleWalk generator = SubmoduleWalk.forIndex(db);
assertTrue(generator.next());
@@ -141,10 +142,10 @@ public class SubmoduleAddTest extends RepositoryTestCase {
assertEquals(uri, generator.getModulesUrl());
assertEquals(path, generator.getModulesPath());
assertEquals(uri, generator.getConfigUrl());
- Repository subModRepo = generator.getRepository();
- assertNotNull(subModRepo);
- assertEquals(subCommit, commit);
- subModRepo.close();
+ try (Repository subModRepo = generator.getRepository()) {
+ assertNotNull(subModRepo);
+ assertEquals(subCommit, commit);
+ }
Status status = Git.wrap(db).status().call();
assertTrue(status.getAdded().contains(Constants.DOT_GIT_MODULES));
@@ -209,16 +210,14 @@ public class SubmoduleAddTest extends RepositoryTestCase {
fullUri = fullUri.replace('\\', '/');
}
assertEquals(fullUri, generator.getConfigUrl());
- Repository subModRepo = generator.getRepository();
- assertNotNull(subModRepo);
- assertEquals(
- fullUri,
- subModRepo
- .getConfig()
- .getString(ConfigConstants.CONFIG_REMOTE_SECTION,
- Constants.DEFAULT_REMOTE_NAME,
- ConfigConstants.CONFIG_KEY_URL));
- subModRepo.close();
+ try (Repository subModRepo = generator.getRepository()) {
+ assertNotNull(subModRepo);
+ assertEquals(fullUri,
+ subModRepo.getConfig().getString(
+ ConfigConstants.CONFIG_REMOTE_SECTION,
+ Constants.DEFAULT_REMOTE_NAME,
+ ConfigConstants.CONFIG_KEY_URL));
+ }
assertEquals(commit, repo.resolve(Constants.HEAD));
Status status = Git.wrap(db).status().call();
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleSyncTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleSyncTest.java
index 13db44a9c5..6f3b52f7bb 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleSyncTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleSyncTest.java
@@ -135,12 +135,14 @@ public class SubmoduleSyncTest extends RepositoryTestCase {
generator = SubmoduleWalk.forIndex(db);
assertTrue(generator.next());
assertEquals(url, generator.getConfigUrl());
- Repository subModRepository = generator.getRepository();
- StoredConfig submoduleConfig = subModRepository.getConfig();
- subModRepository.close();
- assertEquals(url, submoduleConfig.getString(
- ConfigConstants.CONFIG_REMOTE_SECTION,
- Constants.DEFAULT_REMOTE_NAME, ConfigConstants.CONFIG_KEY_URL));
+ try (Repository subModRepository = generator.getRepository()) {
+ StoredConfig submoduleConfig = subModRepository.getConfig();
+ assertEquals(url,
+ submoduleConfig.getString(
+ ConfigConstants.CONFIG_REMOTE_SECTION,
+ Constants.DEFAULT_REMOTE_NAME,
+ ConfigConstants.CONFIG_KEY_URL));
+ }
}
@Test
@@ -208,11 +210,13 @@ public class SubmoduleSyncTest extends RepositoryTestCase {
generator = SubmoduleWalk.forIndex(db);
assertTrue(generator.next());
assertEquals("git://server/sub.git", generator.getConfigUrl());
- Repository subModRepository1 = generator.getRepository();
- StoredConfig submoduleConfig = subModRepository1.getConfig();
- subModRepository1.close();
- assertEquals("git://server/sub.git", submoduleConfig.getString(
- ConfigConstants.CONFIG_REMOTE_SECTION,
- Constants.DEFAULT_REMOTE_NAME, ConfigConstants.CONFIG_KEY_URL));
+ try (Repository subModRepository1 = generator.getRepository()) {
+ StoredConfig submoduleConfig = subModRepository1.getConfig();
+ assertEquals("git://server/sub.git",
+ submoduleConfig.getString(
+ ConfigConstants.CONFIG_REMOTE_SECTION,
+ Constants.DEFAULT_REMOTE_NAME,
+ ConfigConstants.CONFIG_KEY_URL));
+ }
}
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleUpdateTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleUpdateTest.java
index 7064f6097b..bbce413ef3 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleUpdateTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleUpdateTest.java
@@ -121,10 +121,10 @@ public class SubmoduleUpdateTest extends RepositoryTestCase {
SubmoduleWalk generator = SubmoduleWalk.forIndex(db);
assertTrue(generator.next());
- Repository subRepo = generator.getRepository();
- assertNotNull(subRepo);
- assertEquals(commit, subRepo.resolve(Constants.HEAD));
- subRepo.close();
+ try (Repository subRepo = generator.getRepository()) {
+ assertNotNull(subRepo);
+ assertEquals(commit, subRepo.resolve(Constants.HEAD));
+ }
}
@Test
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BundleWriterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BundleWriterTest.java
index 658b971acb..d30ac840a6 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BundleWriterTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BundleWriterTest.java
@@ -45,7 +45,7 @@
package org.eclipse.jgit.transport;
-import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
import static org.eclipse.jgit.lib.Constants.OBJ_BLOB;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@@ -199,7 +199,7 @@ public class BundleWriterTest extends SampleDataRepositoryTestCase {
Ref ref = repo.exactRef(refName);
assertNotNull(ref);
assertEquals(id, ref.getObjectId());
- assertEquals(data, new String(repo.open(id, OBJ_BLOB).getBytes(), UTF_8));
+ assertEquals(data, new String(repo.open(id, OBJ_BLOB).getBytes(), CHARSET));
}
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/NetRCTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/NetRCTest.java
index 2fea8a92ac..4e5d56acb2 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/NetRCTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/NetRCTest.java
@@ -42,6 +42,7 @@
package org.eclipse.jgit.transport;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
@@ -73,11 +74,11 @@ public class NetRCTest extends RepositoryTestCase {
configFile = new File(home, ".netrc");
}
- private void config(final String data) throws IOException {
- final OutputStreamWriter fw = new OutputStreamWriter(
- new FileOutputStream(configFile), "UTF-8");
- fw.write(data);
- fw.close();
+ private void config(String data) throws IOException {
+ try (OutputStreamWriter fw = new OutputStreamWriter(
+ new FileOutputStream(configFile), CHARSET)) {
+ fw.write(data);
+ }
}
@Test
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/OpenSshConfigTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/OpenSshConfigTest.java
index d604751fef..abf80ecd4d 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/OpenSshConfigTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/OpenSshConfigTest.java
@@ -43,6 +43,7 @@
package org.eclipse.jgit.transport;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -89,11 +90,11 @@ public class OpenSshConfigTest extends RepositoryTestCase {
osc = new OpenSshConfig(home, configFile);
}
- private void config(final String data) throws IOException {
+ private void config(String data) throws IOException {
long lastMtime = configFile.lastModified();
do {
try (final OutputStreamWriter fw = new OutputStreamWriter(
- new FileOutputStream(configFile), "UTF-8")) {
+ new FileOutputStream(configFile), CHARSET)) {
fw.write(data);
}
} while (lastMtime == configFile.lastModified());
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PackParserTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PackParserTest.java
index 5d9bdbdbad..b6d0611437 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PackParserTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PackParserTest.java
@@ -93,8 +93,7 @@ public class PackParserTest extends RepositoryTestCase {
@Test
public void test1() throws IOException {
File packFile = JGitTestUtil.getTestResourceFile("pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f.pack");
- final InputStream is = new FileInputStream(packFile);
- try {
+ try (InputStream is = new FileInputStream(packFile)) {
ObjectDirectoryPackParser p = (ObjectDirectoryPackParser) index(is);
p.parse(NullProgressMonitor.INSTANCE);
PackFile file = p.getPackFile();
@@ -107,8 +106,6 @@ public class PackParserTest extends RepositoryTestCase {
assertTrue(file.hasObject(ObjectId.fromString("902d5476fa249b7abc9d84c611577a81381f0327")));
assertTrue(file.hasObject(ObjectId.fromString("aabf2ffaec9b497f0950352b3e582d73035c2035")));
assertTrue(file.hasObject(ObjectId.fromString("c59759f143fb1fe21c197981df75a7ee00290799")));
- } finally {
- is.close();
}
}
@@ -121,8 +118,7 @@ public class PackParserTest extends RepositoryTestCase {
@Test
public void test2() throws IOException {
File packFile = JGitTestUtil.getTestResourceFile("pack-df2982f284bbabb6bdb59ee3fcc6eb0983e20371.pack");
- final InputStream is = new FileInputStream(packFile);
- try {
+ try (InputStream is = new FileInputStream(packFile)) {
ObjectDirectoryPackParser p = (ObjectDirectoryPackParser) index(is);
p.parse(NullProgressMonitor.INSTANCE);
PackFile file = p.getPackFile();
@@ -140,8 +136,6 @@ public class PackParserTest extends RepositoryTestCase {
assertTrue(file.hasObject(ObjectId.fromString("20a8ade77639491ea0bd667bf95de8abf3a434c8")));
assertTrue(file.hasObject(ObjectId.fromString("2675188fd86978d5bc4d7211698b2118ae3bf658")));
// and lots more...
- } finally {
- is.close();
}
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PacketLineInTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PacketLineInTest.java
index 13fc68d8c8..8b1d860059 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PacketLineInTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PacketLineInTest.java
@@ -116,17 +116,6 @@ public class PacketLineInTest {
}
@Test
- public void testReadString_Len0001() {
- init("0001");
- try {
- in.readString();
- fail("incorrectly accepted invalid packet header");
- } catch (IOException e) {
- assertEquals("Invalid packet line header: 0001", e.getMessage());
- }
- }
-
- @Test
public void testReadString_Len0002() {
init("0002");
try {
@@ -164,6 +153,13 @@ public class PacketLineInTest {
assertEOF();
}
+ @Test
+ public void testReadString_Delim() throws IOException {
+ init("0001");
+ assertSame(PacketLineIn.DELIM, in.readString());
+ assertEOF();
+ }
+
// readStringNoLF
@Test
@@ -330,7 +326,7 @@ public class PacketLineInTest {
// test support
- private void init(final String msg) {
+ private void init(String msg) {
rawIn = new ByteArrayInputStream(Constants.encodeASCII(msg));
in = new PacketLineIn(rawIn);
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PacketLineOutTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PacketLineOutTest.java
index eca54756b1..391a701b8e 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PacketLineOutTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PacketLineOutTest.java
@@ -113,6 +113,12 @@ public class PacketLineOutTest {
assertEquals(1, flushCnt[0]);
}
+ @Test
+ public void testWriteDelim() throws IOException {
+ out.writeDelim();
+ assertBuffer("0001");
+ }
+
// writePacket
@Test
@@ -167,7 +173,7 @@ public class PacketLineOutTest {
assertEquals(1, flushCnt[0]);
}
- private void assertBuffer(final String exp) throws IOException {
+ private void assertBuffer(String exp) throws IOException {
assertEquals(exp, new String(rawOut.toByteArray(),
Constants.CHARACTER_ENCODING));
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushConnectionTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushConnectionTest.java
index c16c1b2a93..63478f6f92 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushConnectionTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushConnectionTest.java
@@ -51,12 +51,16 @@ import static org.junit.Assert.fail;
import java.io.IOException;
import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import org.eclipse.jgit.errors.TransportException;
import org.eclipse.jgit.internal.storage.dfs.DfsRepositoryDescription;
import org.eclipse.jgit.internal.storage.dfs.InMemoryRepository;
+import org.eclipse.jgit.junit.TestRepository;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.NullProgressMonitor;
import org.eclipse.jgit.lib.ObjectId;
@@ -76,6 +80,7 @@ public class PushConnectionTest {
private Object ctx = new Object();
private InMemoryRepository server;
private InMemoryRepository client;
+ private List<String> processedRefs;
private ObjectId obj1;
private ObjectId obj2;
private ObjectId obj3;
@@ -85,6 +90,7 @@ public class PushConnectionTest {
public void setUp() throws Exception {
server = newRepo("server");
client = newRepo("client");
+ processedRefs = new ArrayList<>();
testProtocol = new TestProtocol<>(
null,
new ReceivePackFactory<Object>() {
@@ -92,7 +98,18 @@ public class PushConnectionTest {
public ReceivePack create(Object req, Repository db)
throws ServiceNotEnabledException,
ServiceNotAuthorizedException {
- return new ReceivePack(db);
+ ReceivePack rp = new ReceivePack(db);
+ rp.setPreReceiveHook(
+ new PreReceiveHook() {
+ @Override
+ public void onPreReceive(ReceivePack receivePack,
+ Collection<ReceiveCommand> cmds) {
+ for (ReceiveCommand cmd : cmds) {
+ processedRefs.add(cmd.getRefName());
+ }
+ }
+ });
+ return rp;
}
});
uri = testProtocol.register(ctx, server);
@@ -196,4 +213,45 @@ public class PushConnectionTest {
}
}
}
+
+ @Test
+ public void commandOrder() throws Exception {
+ TestRepository<?> tr = new TestRepository<>(client);
+ List<RemoteRefUpdate> updates = new ArrayList<>();
+ // Arbitrary non-sorted order.
+ for (int i = 9; i >= 0; i--) {
+ String name = "refs/heads/b" + i;
+ tr.branch(name).commit().create();
+ RemoteRefUpdate rru = new RemoteRefUpdate(client, name, name, false, null,
+ ObjectId.zeroId());
+ updates.add(rru);
+ }
+
+ PushResult result;
+ try (Transport tn = testProtocol.open(uri, client, "server")) {
+ result = tn.push(NullProgressMonitor.INSTANCE, updates);
+ }
+
+ for (RemoteRefUpdate remoteUpdate : result.getRemoteUpdates()) {
+ assertEquals(
+ "update should succeed on " + remoteUpdate.getRemoteName(),
+ RemoteRefUpdate.Status.OK, remoteUpdate.getStatus());
+ }
+
+ List<String> expected = remoteRefNames(updates);
+ assertEquals(
+ "ref names processed by ReceivePack should match input ref names in order",
+ expected, processedRefs);
+ assertEquals(
+ "remote ref names should match input ref names in order",
+ expected, remoteRefNames(result.getRemoteUpdates()));
+ }
+
+ private static List<String> remoteRefNames(Collection<RemoteRefUpdate> updates) {
+ List<String> result = new ArrayList<>();
+ for (RemoteRefUpdate u : updates) {
+ result.add(u.getRemoteName());
+ }
+ return result;
+ }
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushProcessTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushProcessTest.java
index 104a69c9f7..611cd0cef2 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushProcessTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushProcessTest.java
@@ -422,7 +422,7 @@ public class PushProcessTest extends SampleDataRepositoryTestCase {
PushConnection {
MockPushConnection() {
final Map<String, Ref> refsMap = new HashMap<>();
- for (final Ref r : advertisedRefs)
+ for (Ref r : advertisedRefs)
refsMap.put(r.getName(), r);
available(refsMap);
}
@@ -443,7 +443,7 @@ public class PushProcessTest extends SampleDataRepositoryTestCase {
public void push(ProgressMonitor monitor,
Map<String, RemoteRefUpdate> refsToUpdate)
throws TransportException {
- for (final RemoteRefUpdate rru : refsToUpdate.values()) {
+ for (RemoteRefUpdate rru : refsToUpdate.values()) {
assertEquals(Status.NOT_ATTEMPTED, rru.getStatus());
rru.setStatus(connectionUpdateStatus);
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ReceivePackAdvertiseRefsHookTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ReceivePackAdvertiseRefsHookTest.java
index 8ef87cb3c1..b77042220f 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ReceivePackAdvertiseRefsHookTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ReceivePackAdvertiseRefsHookTest.java
@@ -136,7 +136,7 @@ public class ReceivePackAdvertiseRefsHookTest extends LocalDiskRepositoryTestCas
try (TransportLocal t = new TransportLocal(src, uriOf(dst),
dst.getDirectory()) {
@Override
- ReceivePack createReceivePack(final Repository db) {
+ ReceivePack createReceivePack(Repository db) {
db.close();
dst.incrementOpen();
@@ -199,6 +199,23 @@ public class ReceivePackAdvertiseRefsHookTest extends LocalDiskRepositoryTestCas
assertFalse(haves.get().contains(P));
}
+ private TransportLocal newTransportLocalWithStrictValidation()
+ throws Exception {
+ return new TransportLocal(src, uriOf(dst), dst.getDirectory()) {
+ @Override
+ ReceivePack createReceivePack(Repository db) {
+ db.close();
+ dst.incrementOpen();
+
+ final ReceivePack rp = super.createReceivePack(dst);
+ rp.setCheckReceivedObjects(true);
+ rp.setCheckReferencedObjectsAreReachable(true);
+ rp.setAdvertiseRefsHook(new HidePrivateHook());
+ return rp;
+ }
+ };
+ }
+
@Test
public void testSuccess() throws Exception {
// Manually force a delta of an object so we reuse it later.
@@ -230,19 +247,7 @@ public class ReceivePackAdvertiseRefsHookTest extends LocalDiskRepositoryTestCas
// Push this new content to the remote, doing strict validation.
//
- TransportLocal t = new TransportLocal(src, uriOf(dst), dst.getDirectory()) {
- @Override
- ReceivePack createReceivePack(final Repository db) {
- db.close();
- dst.incrementOpen();
-
- final ReceivePack rp = super.createReceivePack(dst);
- rp.setCheckReceivedObjects(true);
- rp.setCheckReferencedObjectsAreReachable(true);
- rp.setAdvertiseRefsHook(new HidePrivateHook());
- return rp;
- }
- };
+ PushResult r;
RemoteRefUpdate u = new RemoteRefUpdate( //
src, //
R_MASTER, // src name
@@ -251,12 +256,9 @@ public class ReceivePackAdvertiseRefsHookTest extends LocalDiskRepositoryTestCas
null, // local tracking branch
null // expected id
);
- PushResult r;
- try {
+ try (TransportLocal t = newTransportLocalWithStrictValidation()) {
t.setPushThin(true);
r = t.push(PM, Collections.singleton(u));
- } finally {
- t.close();
}
assertNotNull("have result", r);
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/RemoteConfigTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/RemoteConfigTest.java
index a0cf0d2dbc..9aabd71d97 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/RemoteConfigTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/RemoteConfigTest.java
@@ -67,12 +67,12 @@ public class RemoteConfigTest {
config = new Config();
}
- private void readConfig(final String dat) throws ConfigInvalidException {
+ private void readConfig(String dat) throws ConfigInvalidException {
config = new Config();
config.fromText(dat);
}
- private void checkConfig(final String exp) {
+ private void checkConfig(String exp) {
assertEquals(exp, config.toText());
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/SideBandOutputStreamTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/SideBandOutputStreamTest.java
index 4571619603..4d3e162240 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/SideBandOutputStreamTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/SideBandOutputStreamTest.java
@@ -259,7 +259,7 @@ public class SideBandOutputStreamTest {
}
}
- private void assertBuffer(final String exp) throws IOException {
+ private void assertBuffer(String exp) throws IOException {
assertEquals(exp, new String(rawOut.toByteArray(),
Constants.CHARACTER_ENCODING));
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/TransportTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/TransportTest.java
index d4c47d37e3..c239922d71 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/TransportTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/TransportTest.java
@@ -142,7 +142,7 @@ public class TransportTest extends SampleDataRepositoryTestCase {
assertEquals(12, result.size());
boolean foundA = false;
boolean foundB = false;
- for (final RemoteRefUpdate rru : result) {
+ for (RemoteRefUpdate rru : result) {
if ("refs/heads/a".equals(rru.getSrcRef())
&& "refs/heads/test/a".equals(rru.getRemoteName()))
foundA = true;
@@ -174,7 +174,7 @@ public class TransportTest extends SampleDataRepositoryTestCase {
assertEquals(2, result.size());
boolean foundA = false;
boolean foundC = false;
- for (final RemoteRefUpdate rru : result) {
+ for (RemoteRefUpdate rru : result) {
if ("refs/heads/a".equals(rru.getSrcRef())
&& "refs/heads/b".equals(rru.getRemoteName()))
foundA = true;
@@ -233,7 +233,7 @@ public class TransportTest extends SampleDataRepositoryTestCase {
assertEquals(2, result.size());
boolean foundA = false;
boolean foundC = false;
- for (final RemoteRefUpdate rru : result) {
+ for (RemoteRefUpdate rru : result) {
if ("refs/heads/a".equals(rru.getSrcRef())
&& "refs/heads/b".equals(rru.getRemoteName())) {
foundA = true;
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java
index a8127abd36..ef083da183 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java
@@ -1,22 +1,41 @@
package org.eclipse.jgit.transport;
+import static org.hamcrest.Matchers.hasItems;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.theInstance;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
+import java.util.Arrays;
import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.StringWriter;
+import org.eclipse.jgit.errors.PackProtocolException;
import org.eclipse.jgit.errors.TransportException;
import org.eclipse.jgit.internal.storage.dfs.DfsGarbageCollector;
import org.eclipse.jgit.internal.storage.dfs.DfsRepositoryDescription;
import org.eclipse.jgit.internal.storage.dfs.InMemoryRepository;
import org.eclipse.jgit.junit.TestRepository;
import org.eclipse.jgit.lib.NullProgressMonitor;
+import org.eclipse.jgit.lib.ProgressMonitor;
+import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.lib.Sets;
+import org.eclipse.jgit.lib.TextProgressMonitor;
import org.eclipse.jgit.revwalk.RevBlob;
import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.jgit.revwalk.RevTree;
+import org.eclipse.jgit.revwalk.RevTag;
import org.eclipse.jgit.transport.UploadPack.RequestPolicy;
import org.eclipse.jgit.transport.resolver.ServiceNotAuthorizedException;
import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException;
import org.eclipse.jgit.transport.resolver.UploadPackFactory;
+import org.eclipse.jgit.util.io.NullOutputStream;
import org.hamcrest.Matchers;
import org.junit.After;
import org.junit.Before;
@@ -170,4 +189,899 @@ public class UploadPackTest {
Collections.singletonList(new RefSpec(blob.name())));
}
}
+
+ @Test
+ public void testFetchWithBlobNoneFilter() throws Exception {
+ InMemoryRepository server2 = newRepo("server2");
+ TestRepository<InMemoryRepository> remote2 =
+ new TestRepository<>(server2);
+ RevBlob blob1 = remote2.blob("foobar");
+ RevBlob blob2 = remote2.blob("fooba");
+ RevTree tree = remote2.tree(remote2.file("1", blob1),
+ remote2.file("2", blob2));
+ RevCommit commit = remote2.commit(tree);
+ remote2.update("master", commit);
+
+ server2.getConfig().setBoolean("uploadpack", null, "allowfilter", true);
+
+ testProtocol = new TestProtocol<>(
+ new UploadPackFactory<Object>() {
+ @Override
+ public UploadPack create(Object req, Repository db)
+ throws ServiceNotEnabledException,
+ ServiceNotAuthorizedException {
+ UploadPack up = new UploadPack(db);
+ return up;
+ }
+ }, null);
+ uri = testProtocol.register(ctx, server2);
+
+ try (Transport tn = testProtocol.open(uri, client, "server2")) {
+ tn.setFilterBlobLimit(0);
+ tn.fetch(NullProgressMonitor.INSTANCE,
+ Collections.singletonList(new RefSpec(commit.name())));
+ assertTrue(client.hasObject(tree.toObjectId()));
+ assertFalse(client.hasObject(blob1.toObjectId()));
+ assertFalse(client.hasObject(blob2.toObjectId()));
+ }
+ }
+
+ @Test
+ public void testFetchWithBlobLimitFilter() throws Exception {
+ InMemoryRepository server2 = newRepo("server2");
+ TestRepository<InMemoryRepository> remote2 =
+ new TestRepository<>(server2);
+ RevBlob longBlob = remote2.blob("foobar");
+ RevBlob shortBlob = remote2.blob("fooba");
+ RevTree tree = remote2.tree(remote2.file("1", longBlob),
+ remote2.file("2", shortBlob));
+ RevCommit commit = remote2.commit(tree);
+ remote2.update("master", commit);
+
+ server2.getConfig().setBoolean("uploadpack", null, "allowfilter", true);
+
+ testProtocol = new TestProtocol<>(
+ new UploadPackFactory<Object>() {
+ @Override
+ public UploadPack create(Object req, Repository db)
+ throws ServiceNotEnabledException,
+ ServiceNotAuthorizedException {
+ UploadPack up = new UploadPack(db);
+ return up;
+ }
+ }, null);
+ uri = testProtocol.register(ctx, server2);
+
+ try (Transport tn = testProtocol.open(uri, client, "server2")) {
+ tn.setFilterBlobLimit(5);
+ tn.fetch(NullProgressMonitor.INSTANCE,
+ Collections.singletonList(new RefSpec(commit.name())));
+ assertFalse(client.hasObject(longBlob.toObjectId()));
+ assertTrue(client.hasObject(shortBlob.toObjectId()));
+ }
+ }
+
+ @Test
+ public void testFetchWithBlobLimitFilterAndBitmaps() throws Exception {
+ InMemoryRepository server2 = newRepo("server2");
+ TestRepository<InMemoryRepository> remote2 =
+ new TestRepository<>(server2);
+ RevBlob longBlob = remote2.blob("foobar");
+ RevBlob shortBlob = remote2.blob("fooba");
+ RevTree tree = remote2.tree(remote2.file("1", longBlob),
+ remote2.file("2", shortBlob));
+ RevCommit commit = remote2.commit(tree);
+ remote2.update("master", commit);
+
+ server2.getConfig().setBoolean("uploadpack", null, "allowfilter", true);
+
+ // generate bitmaps
+ new DfsGarbageCollector(server2).pack(null);
+ server2.scanForRepoChanges();
+
+ testProtocol = new TestProtocol<>(
+ new UploadPackFactory<Object>() {
+ @Override
+ public UploadPack create(Object req, Repository db)
+ throws ServiceNotEnabledException,
+ ServiceNotAuthorizedException {
+ UploadPack up = new UploadPack(db);
+ return up;
+ }
+ }, null);
+ uri = testProtocol.register(ctx, server2);
+
+ try (Transport tn = testProtocol.open(uri, client, "server2")) {
+ tn.setFilterBlobLimit(5);
+ tn.fetch(NullProgressMonitor.INSTANCE,
+ Collections.singletonList(new RefSpec(commit.name())));
+ assertFalse(client.hasObject(longBlob.toObjectId()));
+ assertTrue(client.hasObject(shortBlob.toObjectId()));
+ }
+ }
+
+ @Test
+ public void testFetchWithNonSupportingServer() throws Exception {
+ InMemoryRepository server2 = newRepo("server2");
+ TestRepository<InMemoryRepository> remote2 =
+ new TestRepository<>(server2);
+ RevBlob blob = remote2.blob("foo");
+ RevTree tree = remote2.tree(remote2.file("1", blob));
+ RevCommit commit = remote2.commit(tree);
+ remote2.update("master", commit);
+
+ server2.getConfig().setBoolean("uploadpack", null, "allowfilter", false);
+
+ testProtocol = new TestProtocol<>(
+ new UploadPackFactory<Object>() {
+ @Override
+ public UploadPack create(Object req, Repository db)
+ throws ServiceNotEnabledException,
+ ServiceNotAuthorizedException {
+ UploadPack up = new UploadPack(db);
+ return up;
+ }
+ }, null);
+ uri = testProtocol.register(ctx, server2);
+
+ try (Transport tn = testProtocol.open(uri, client, "server2")) {
+ tn.setFilterBlobLimit(0);
+
+ thrown.expect(TransportException.class);
+ thrown.expectMessage("filter requires server to advertise that capability");
+
+ tn.fetch(NullProgressMonitor.INSTANCE,
+ Collections.singletonList(new RefSpec(commit.name())));
+ }
+ }
+
+ /*
+ * Invokes UploadPack with protocol v2 and sends it the given lines,
+ * and returns UploadPack's output stream.
+ */
+ private ByteArrayInputStream uploadPackV2Setup(RequestPolicy requestPolicy,
+ RefFilter refFilter, String... inputLines) throws Exception {
+
+ ByteArrayOutputStream send = new ByteArrayOutputStream();
+ PacketLineOut pckOut = new PacketLineOut(send);
+ for (String line : inputLines) {
+ if (line == PacketLineIn.END) {
+ pckOut.end();
+ } else if (line == PacketLineIn.DELIM) {
+ pckOut.writeDelim();
+ } else {
+ pckOut.writeString(line);
+ }
+ }
+
+ server.getConfig().setString("protocol", null, "version", "2");
+ UploadPack up = new UploadPack(server);
+ if (requestPolicy != null)
+ up.setRequestPolicy(requestPolicy);
+ if (refFilter != null)
+ up.setRefFilter(refFilter);
+ up.setExtraParameters(Sets.of("version=2"));
+
+ ByteArrayOutputStream recv = new ByteArrayOutputStream();
+ up.upload(new ByteArrayInputStream(send.toByteArray()), recv, null);
+
+ return new ByteArrayInputStream(recv.toByteArray());
+ }
+
+ /*
+ * Invokes UploadPack with protocol v2 and sends it the given lines.
+ * Returns UploadPack's output stream, not including the capability
+ * advertisement by the server.
+ */
+ private ByteArrayInputStream uploadPackV2(RequestPolicy requestPolicy,
+ RefFilter refFilter, String... inputLines) throws Exception {
+ ByteArrayInputStream recvStream =
+ uploadPackV2Setup(requestPolicy, refFilter, inputLines);
+ PacketLineIn pckIn = new PacketLineIn(recvStream);
+
+ // drain capabilities
+ while (pckIn.readString() != PacketLineIn.END) {
+ // do nothing
+ }
+ return recvStream;
+ }
+
+ private ByteArrayInputStream uploadPackV2(String... inputLines) throws Exception {
+ return uploadPackV2(null, null, inputLines);
+ }
+
+ @Test
+ public void testV2Capabilities() throws Exception {
+ ByteArrayInputStream recvStream =
+ uploadPackV2Setup(null, null, PacketLineIn.END);
+ PacketLineIn pckIn = new PacketLineIn(recvStream);
+
+ assertThat(pckIn.readString(), is("version 2"));
+ assertThat(
+ Arrays.asList(pckIn.readString(), pckIn.readString()),
+ // TODO(jonathantanmy) This check is written this way
+ // to make it simple to see that we expect this list of
+ // capabilities, but probably should be loosened to
+ // allow additional commands to be added to the list,
+ // and additional capabilities to be added to existing
+ // commands without requiring test changes.
+ hasItems("ls-refs", "fetch=shallow"));
+ assertTrue(pckIn.readString() == PacketLineIn.END);
+ }
+
+ @Test
+ public void testV2CapabilitiesAllowFilter() throws Exception {
+ server.getConfig().setBoolean("uploadpack", null, "allowfilter", true);
+ ByteArrayInputStream recvStream =
+ uploadPackV2Setup(null, null, PacketLineIn.END);
+ PacketLineIn pckIn = new PacketLineIn(recvStream);
+
+ assertThat(pckIn.readString(), is("version 2"));
+ assertThat(
+ Arrays.asList(pckIn.readString(), pckIn.readString()),
+ // TODO(jonathantanmy) This check overspecifies the
+ // order of the capabilities of "fetch".
+ hasItems("ls-refs", "fetch=filter shallow"));
+ assertTrue(pckIn.readString() == PacketLineIn.END);
+ }
+
+ @Test
+ @SuppressWarnings("boxing")
+ public void testV2EmptyRequest() throws Exception {
+ ByteArrayInputStream recvStream = uploadPackV2(PacketLineIn.END);
+ // Verify that there is nothing more after the capability
+ // advertisement.
+ assertThat(recvStream.available(), is(0));
+ }
+
+ @Test
+ public void testV2LsRefs() throws Exception {
+ RevCommit tip = remote.commit().message("message").create();
+ remote.update("master", tip);
+ server.updateRef("HEAD").link("refs/heads/master");
+ RevTag tag = remote.tag("tag", tip);
+ remote.update("refs/tags/tag", tag);
+
+ ByteArrayInputStream recvStream = uploadPackV2("command=ls-refs\n", PacketLineIn.END);
+ PacketLineIn pckIn = new PacketLineIn(recvStream);
+
+ assertThat(pckIn.readString(), is(tip.toObjectId().getName() + " HEAD"));
+ assertThat(pckIn.readString(), is(tip.toObjectId().getName() + " refs/heads/master"));
+ assertThat(pckIn.readString(), is(tag.toObjectId().getName() + " refs/tags/tag"));
+ assertTrue(pckIn.readString() == PacketLineIn.END);
+ }
+
+ @Test
+ public void testV2LsRefsSymrefs() throws Exception {
+ RevCommit tip = remote.commit().message("message").create();
+ remote.update("master", tip);
+ server.updateRef("HEAD").link("refs/heads/master");
+ RevTag tag = remote.tag("tag", tip);
+ remote.update("refs/tags/tag", tag);
+
+ ByteArrayInputStream recvStream = uploadPackV2("command=ls-refs\n", PacketLineIn.DELIM, "symrefs", PacketLineIn.END);
+ PacketLineIn pckIn = new PacketLineIn(recvStream);
+
+ assertThat(pckIn.readString(), is(tip.toObjectId().getName() + " HEAD symref-target:refs/heads/master"));
+ assertThat(pckIn.readString(), is(tip.toObjectId().getName() + " refs/heads/master"));
+ assertThat(pckIn.readString(), is(tag.toObjectId().getName() + " refs/tags/tag"));
+ assertTrue(pckIn.readString() == PacketLineIn.END);
+ }
+
+ @Test
+ public void testV2LsRefsPeel() throws Exception {
+ RevCommit tip = remote.commit().message("message").create();
+ remote.update("master", tip);
+ server.updateRef("HEAD").link("refs/heads/master");
+ RevTag tag = remote.tag("tag", tip);
+ remote.update("refs/tags/tag", tag);
+
+ ByteArrayInputStream recvStream = uploadPackV2("command=ls-refs\n", PacketLineIn.DELIM, "peel", PacketLineIn.END);
+ PacketLineIn pckIn = new PacketLineIn(recvStream);
+
+ assertThat(pckIn.readString(), is(tip.toObjectId().getName() + " HEAD"));
+ assertThat(pckIn.readString(), is(tip.toObjectId().getName() + " refs/heads/master"));
+ assertThat(
+ pckIn.readString(),
+ is(tag.toObjectId().getName() + " refs/tags/tag peeled:"
+ + tip.toObjectId().getName()));
+ assertTrue(pckIn.readString() == PacketLineIn.END);
+ }
+
+ @Test
+ public void testV2LsRefsMultipleCommands() throws Exception {
+ RevCommit tip = remote.commit().message("message").create();
+ remote.update("master", tip);
+ server.updateRef("HEAD").link("refs/heads/master");
+ RevTag tag = remote.tag("tag", tip);
+ remote.update("refs/tags/tag", tag);
+
+ ByteArrayInputStream recvStream = uploadPackV2(
+ "command=ls-refs\n", PacketLineIn.DELIM, "symrefs", "peel", PacketLineIn.END,
+ "command=ls-refs\n", PacketLineIn.DELIM, PacketLineIn.END);
+ PacketLineIn pckIn = new PacketLineIn(recvStream);
+
+ assertThat(pckIn.readString(), is(tip.toObjectId().getName() + " HEAD symref-target:refs/heads/master"));
+ assertThat(pckIn.readString(), is(tip.toObjectId().getName() + " refs/heads/master"));
+ assertThat(
+ pckIn.readString(),
+ is(tag.toObjectId().getName() + " refs/tags/tag peeled:"
+ + tip.toObjectId().getName()));
+ assertTrue(pckIn.readString() == PacketLineIn.END);
+ assertThat(pckIn.readString(), is(tip.toObjectId().getName() + " HEAD"));
+ assertThat(pckIn.readString(), is(tip.toObjectId().getName() + " refs/heads/master"));
+ assertThat(pckIn.readString(), is(tag.toObjectId().getName() + " refs/tags/tag"));
+ assertTrue(pckIn.readString() == PacketLineIn.END);
+ }
+
+ @Test
+ public void testV2LsRefsRefPrefix() throws Exception {
+ RevCommit tip = remote.commit().message("message").create();
+ remote.update("master", tip);
+ remote.update("other", tip);
+ remote.update("yetAnother", tip);
+
+ ByteArrayInputStream recvStream = uploadPackV2(
+ "command=ls-refs\n",
+ PacketLineIn.DELIM,
+ "ref-prefix refs/heads/maste",
+ "ref-prefix refs/heads/other",
+ PacketLineIn.END);
+ PacketLineIn pckIn = new PacketLineIn(recvStream);
+
+ assertThat(pckIn.readString(), is(tip.toObjectId().getName() + " refs/heads/master"));
+ assertThat(pckIn.readString(), is(tip.toObjectId().getName() + " refs/heads/other"));
+ assertTrue(pckIn.readString() == PacketLineIn.END);
+ }
+
+ @Test
+ public void testV2LsRefsRefPrefixNoSlash() throws Exception {
+ RevCommit tip = remote.commit().message("message").create();
+ remote.update("master", tip);
+ remote.update("other", tip);
+
+ ByteArrayInputStream recvStream = uploadPackV2(
+ "command=ls-refs\n",
+ PacketLineIn.DELIM,
+ "ref-prefix refs/heads/maste",
+ "ref-prefix r",
+ PacketLineIn.END);
+ PacketLineIn pckIn = new PacketLineIn(recvStream);
+
+ assertThat(pckIn.readString(), is(tip.toObjectId().getName() + " refs/heads/master"));
+ assertThat(pckIn.readString(), is(tip.toObjectId().getName() + " refs/heads/other"));
+ assertTrue(pckIn.readString() == PacketLineIn.END);
+ }
+
+ @Test
+ public void testV2LsRefsUnrecognizedArgument() throws Exception {
+ thrown.expect(PackProtocolException.class);
+ thrown.expectMessage("unexpected invalid-argument");
+ uploadPackV2(
+ "command=ls-refs\n",
+ PacketLineIn.DELIM,
+ "invalid-argument\n",
+ PacketLineIn.END);
+ }
+
+ /*
+ * Parse multiplexed packfile output from upload-pack using protocol V2
+ * into the client repository.
+ */
+ private ReceivedPackStatistics parsePack(ByteArrayInputStream recvStream) throws Exception {
+ return parsePack(recvStream, NullProgressMonitor.INSTANCE);
+ }
+
+ private ReceivedPackStatistics parsePack(ByteArrayInputStream recvStream, ProgressMonitor pm)
+ throws Exception {
+ SideBandInputStream sb = new SideBandInputStream(
+ recvStream, pm,
+ new StringWriter(), NullOutputStream.INSTANCE);
+ PackParser pp = client.newObjectInserter().newPackParser(sb);
+ pp.parse(NullProgressMonitor.INSTANCE);
+ return pp.getReceivedPackStatistics();
+ }
+
+ @Test
+ public void testV2FetchRequestPolicyAdvertised() throws Exception {
+ RevCommit advertized = remote.commit().message("x").create();
+ RevCommit unadvertized = remote.commit().message("y").create();
+ remote.update("branch1", advertized);
+
+ // This works
+ uploadPackV2(
+ RequestPolicy.ADVERTISED,
+ null,
+ "command=fetch\n",
+ PacketLineIn.DELIM,
+ "want " + advertized.name() + "\n",
+ PacketLineIn.END);
+
+ // This doesn't
+ thrown.expect(TransportException.class);
+ thrown.expectMessage(Matchers.containsString(
+ "want " + unadvertized.name() + " not valid"));
+ uploadPackV2(
+ RequestPolicy.ADVERTISED,
+ null,
+ "command=fetch\n",
+ PacketLineIn.DELIM,
+ "want " + unadvertized.name() + "\n",
+ PacketLineIn.END);
+ }
+
+ @Test
+ public void testV2FetchRequestPolicyReachableCommit() throws Exception {
+ RevCommit reachable = remote.commit().message("x").create();
+ RevCommit advertized = remote.commit().message("x").parent(reachable).create();
+ RevCommit unreachable = remote.commit().message("y").create();
+ remote.update("branch1", advertized);
+
+ // This works
+ uploadPackV2(
+ RequestPolicy.REACHABLE_COMMIT,
+ null,
+ "command=fetch\n",
+ PacketLineIn.DELIM,
+ "want " + reachable.name() + "\n",
+ PacketLineIn.END);
+
+ // This doesn't
+ thrown.expect(TransportException.class);
+ thrown.expectMessage(Matchers.containsString(
+ "want " + unreachable.name() + " not valid"));
+ uploadPackV2(
+ RequestPolicy.REACHABLE_COMMIT,
+ null,
+ "command=fetch\n",
+ PacketLineIn.DELIM,
+ "want " + unreachable.name() + "\n",
+ PacketLineIn.END);
+ }
+
+ @Test
+ public void testV2FetchRequestPolicyTip() throws Exception {
+ RevCommit parentOfTip = remote.commit().message("x").create();
+ RevCommit tip = remote.commit().message("y").parent(parentOfTip).create();
+ remote.update("secret", tip);
+
+ // This works
+ uploadPackV2(
+ RequestPolicy.TIP,
+ new RejectAllRefFilter(),
+ "command=fetch\n",
+ PacketLineIn.DELIM,
+ "want " + tip.name() + "\n",
+ PacketLineIn.END);
+
+ // This doesn't
+ thrown.expect(TransportException.class);
+ thrown.expectMessage(Matchers.containsString(
+ "want " + parentOfTip.name() + " not valid"));
+ uploadPackV2(
+ RequestPolicy.TIP,
+ new RejectAllRefFilter(),
+ "command=fetch\n",
+ PacketLineIn.DELIM,
+ "want " + parentOfTip.name() + "\n",
+ PacketLineIn.END);
+ }
+
+ @Test
+ public void testV2FetchRequestPolicyReachableCommitTip() throws Exception {
+ RevCommit parentOfTip = remote.commit().message("x").create();
+ RevCommit tip = remote.commit().message("y").parent(parentOfTip).create();
+ RevCommit unreachable = remote.commit().message("y").create();
+ remote.update("secret", tip);
+
+ // This works
+ uploadPackV2(
+ RequestPolicy.REACHABLE_COMMIT_TIP,
+ new RejectAllRefFilter(),
+ "command=fetch\n",
+ PacketLineIn.DELIM,
+ "want " + parentOfTip.name() + "\n",
+ PacketLineIn.END);
+
+ // This doesn't
+ thrown.expect(TransportException.class);
+ thrown.expectMessage(Matchers.containsString(
+ "want " + unreachable.name() + " not valid"));
+ uploadPackV2(
+ RequestPolicy.REACHABLE_COMMIT_TIP,
+ new RejectAllRefFilter(),
+ "command=fetch\n",
+ PacketLineIn.DELIM,
+ "want " + unreachable.name() + "\n",
+ PacketLineIn.END);
+ }
+
+ @Test
+ public void testV2FetchRequestPolicyAny() throws Exception {
+ RevCommit unreachable = remote.commit().message("y").create();
+
+ // Exercise to make sure that even unreachable commits can be fetched
+ uploadPackV2(
+ RequestPolicy.ANY,
+ null,
+ "command=fetch\n",
+ PacketLineIn.DELIM,
+ "want " + unreachable.name() + "\n",
+ PacketLineIn.END);
+ }
+
+ @Test
+ public void testV2FetchServerDoesNotStopNegotiation() throws Exception {
+ RevCommit fooParent = remote.commit().message("x").create();
+ RevCommit fooChild = remote.commit().message("x").parent(fooParent).create();
+ RevCommit barParent = remote.commit().message("y").create();
+ RevCommit barChild = remote.commit().message("y").parent(barParent).create();
+ remote.update("branch1", fooChild);
+ remote.update("branch2", barChild);
+
+ ByteArrayInputStream recvStream = uploadPackV2(
+ "command=fetch\n",
+ PacketLineIn.DELIM,
+ "want " + fooChild.toObjectId().getName() + "\n",
+ "want " + barChild.toObjectId().getName() + "\n",
+ "have " + fooParent.toObjectId().getName() + "\n",
+ PacketLineIn.END);
+ PacketLineIn pckIn = new PacketLineIn(recvStream);
+
+ assertThat(pckIn.readString(), is("acknowledgments"));
+ assertThat(pckIn.readString(), is("ACK " + fooParent.toObjectId().getName()));
+ assertThat(pckIn.readString(), theInstance(PacketLineIn.END));
+ }
+
+ @Test
+ public void testV2FetchServerStopsNegotiation() throws Exception {
+ RevCommit fooParent = remote.commit().message("x").create();
+ RevCommit fooChild = remote.commit().message("x").parent(fooParent).create();
+ RevCommit barParent = remote.commit().message("y").create();
+ RevCommit barChild = remote.commit().message("y").parent(barParent).create();
+ remote.update("branch1", fooChild);
+ remote.update("branch2", barChild);
+
+ ByteArrayInputStream recvStream = uploadPackV2(
+ "command=fetch\n",
+ PacketLineIn.DELIM,
+ "want " + fooChild.toObjectId().getName() + "\n",
+ "want " + barChild.toObjectId().getName() + "\n",
+ "have " + fooParent.toObjectId().getName() + "\n",
+ "have " + barParent.toObjectId().getName() + "\n",
+ PacketLineIn.END);
+ PacketLineIn pckIn = new PacketLineIn(recvStream);
+
+ assertThat(pckIn.readString(), is("acknowledgments"));
+ assertThat(
+ Arrays.asList(pckIn.readString(), pckIn.readString()),
+ hasItems(
+ "ACK " + fooParent.toObjectId().getName(),
+ "ACK " + barParent.toObjectId().getName()));
+ assertThat(pckIn.readString(), is("ready"));
+ assertThat(pckIn.readString(), theInstance(PacketLineIn.DELIM));
+ assertThat(pckIn.readString(), is("packfile"));
+ parsePack(recvStream);
+ assertFalse(client.hasObject(fooParent.toObjectId()));
+ assertTrue(client.hasObject(fooChild.toObjectId()));
+ assertFalse(client.hasObject(barParent.toObjectId()));
+ assertTrue(client.hasObject(barChild.toObjectId()));
+ }
+
+ @Test
+ public void testV2FetchClientStopsNegotiation() throws Exception {
+ RevCommit fooParent = remote.commit().message("x").create();
+ RevCommit fooChild = remote.commit().message("x").parent(fooParent).create();
+ RevCommit barParent = remote.commit().message("y").create();
+ RevCommit barChild = remote.commit().message("y").parent(barParent).create();
+ remote.update("branch1", fooChild);
+ remote.update("branch2", barChild);
+
+ ByteArrayInputStream recvStream = uploadPackV2(
+ "command=fetch\n",
+ PacketLineIn.DELIM,
+ "want " + fooChild.toObjectId().getName() + "\n",
+ "want " + barChild.toObjectId().getName() + "\n",
+ "have " + fooParent.toObjectId().getName() + "\n",
+ "done\n",
+ PacketLineIn.END);
+ PacketLineIn pckIn = new PacketLineIn(recvStream);
+
+ assertThat(pckIn.readString(), is("packfile"));
+ parsePack(recvStream);
+ assertFalse(client.hasObject(fooParent.toObjectId()));
+ assertTrue(client.hasObject(fooChild.toObjectId()));
+ assertTrue(client.hasObject(barParent.toObjectId()));
+ assertTrue(client.hasObject(barChild.toObjectId()));
+ }
+
+ @Test
+ public void testV2FetchThinPack() throws Exception {
+ String commonInBlob = "abcdefghijklmnopqrstuvwxyz";
+
+ RevBlob parentBlob = remote.blob(commonInBlob + "a");
+ RevCommit parent = remote.commit(remote.tree(remote.file("foo", parentBlob)));
+ RevBlob childBlob = remote.blob(commonInBlob + "b");
+ RevCommit child = remote.commit(remote.tree(remote.file("foo", childBlob)), parent);
+ remote.update("branch1", child);
+
+ // Pretend that we have parent to get a thin pack based on it.
+ ByteArrayInputStream recvStream = uploadPackV2(
+ "command=fetch\n",
+ PacketLineIn.DELIM,
+ "want " + child.toObjectId().getName() + "\n",
+ "have " + parent.toObjectId().getName() + "\n",
+ "thin-pack\n",
+ "done\n",
+ PacketLineIn.END);
+ PacketLineIn pckIn = new PacketLineIn(recvStream);
+
+ assertThat(pckIn.readString(), is("packfile"));
+
+ // Verify that we received a thin pack by trying to apply it
+ // against the client repo, which does not have parent.
+ thrown.expect(IOException.class);
+ thrown.expectMessage("pack has unresolved deltas");
+ parsePack(recvStream);
+ }
+
+ @Test
+ public void testV2FetchNoProgress() throws Exception {
+ RevCommit commit = remote.commit().message("x").create();
+ remote.update("branch1", commit);
+
+ // Without no-progress, progress is reported.
+ StringWriter sw = new StringWriter();
+ ByteArrayInputStream recvStream = uploadPackV2(
+ "command=fetch\n",
+ PacketLineIn.DELIM,
+ "want " + commit.toObjectId().getName() + "\n",
+ "done\n",
+ PacketLineIn.END);
+ PacketLineIn pckIn = new PacketLineIn(recvStream);
+ assertThat(pckIn.readString(), is("packfile"));
+ parsePack(recvStream, new TextProgressMonitor(sw));
+ assertFalse(sw.toString().isEmpty());
+
+ // With no-progress, progress is not reported.
+ sw = new StringWriter();
+ recvStream = uploadPackV2(
+ "command=fetch\n",
+ PacketLineIn.DELIM,
+ "want " + commit.toObjectId().getName() + "\n",
+ "no-progress\n",
+ "done\n",
+ PacketLineIn.END);
+ pckIn = new PacketLineIn(recvStream);
+ assertThat(pckIn.readString(), is("packfile"));
+ parsePack(recvStream, new TextProgressMonitor(sw));
+ assertTrue(sw.toString().isEmpty());
+ }
+
+ @Test
+ public void testV2FetchIncludeTag() throws Exception {
+ RevCommit commit = remote.commit().message("x").create();
+ RevTag tag = remote.tag("tag", commit);
+ remote.update("branch1", commit);
+ remote.update("refs/tags/tag", tag);
+
+ // Without include-tag.
+ ByteArrayInputStream recvStream = uploadPackV2(
+ "command=fetch\n",
+ PacketLineIn.DELIM,
+ "want " + commit.toObjectId().getName() + "\n",
+ "done\n",
+ PacketLineIn.END);
+ PacketLineIn pckIn = new PacketLineIn(recvStream);
+ assertThat(pckIn.readString(), is("packfile"));
+ parsePack(recvStream);
+ assertFalse(client.hasObject(tag.toObjectId()));
+
+ // With tag.
+ recvStream = uploadPackV2(
+ "command=fetch\n",
+ PacketLineIn.DELIM,
+ "want " + commit.toObjectId().getName() + "\n",
+ "include-tag\n",
+ "done\n",
+ PacketLineIn.END);
+ pckIn = new PacketLineIn(recvStream);
+ assertThat(pckIn.readString(), is("packfile"));
+ parsePack(recvStream);
+ assertTrue(client.hasObject(tag.toObjectId()));
+ }
+
+ @Test
+ public void testV2FetchOfsDelta() throws Exception {
+ String commonInBlob = "abcdefghijklmnopqrstuvwxyz";
+
+ RevBlob parentBlob = remote.blob(commonInBlob + "a");
+ RevCommit parent = remote.commit(remote.tree(remote.file("foo", parentBlob)));
+ RevBlob childBlob = remote.blob(commonInBlob + "b");
+ RevCommit child = remote.commit(remote.tree(remote.file("foo", childBlob)), parent);
+ remote.update("branch1", child);
+
+ // Without ofs-delta.
+ ByteArrayInputStream recvStream = uploadPackV2(
+ "command=fetch\n",
+ PacketLineIn.DELIM,
+ "want " + child.toObjectId().getName() + "\n",
+ "done\n",
+ PacketLineIn.END);
+ PacketLineIn pckIn = new PacketLineIn(recvStream);
+ assertThat(pckIn.readString(), is("packfile"));
+ ReceivedPackStatistics stats = parsePack(recvStream);
+ assertTrue(stats.getNumOfsDelta() == 0);
+
+ // With ofs-delta.
+ recvStream = uploadPackV2(
+ "command=fetch\n",
+ PacketLineIn.DELIM,
+ "want " + child.toObjectId().getName() + "\n",
+ "ofs-delta\n",
+ "done\n",
+ PacketLineIn.END);
+ pckIn = new PacketLineIn(recvStream);
+ assertThat(pckIn.readString(), is("packfile"));
+ stats = parsePack(recvStream);
+ assertTrue(stats.getNumOfsDelta() != 0);
+ }
+
+ @Test
+ public void testV2FetchShallow() throws Exception {
+ RevCommit commonParent = remote.commit().message("parent").create();
+ RevCommit fooChild = remote.commit().message("x").parent(commonParent).create();
+ RevCommit barChild = remote.commit().message("y").parent(commonParent).create();
+ remote.update("branch1", barChild);
+
+ // Without shallow, the server thinks that we have
+ // commonParent, so it doesn't send it.
+ ByteArrayInputStream recvStream = uploadPackV2(
+ "command=fetch\n",
+ PacketLineIn.DELIM,
+ "want " + barChild.toObjectId().getName() + "\n",
+ "have " + fooChild.toObjectId().getName() + "\n",
+ "done\n",
+ PacketLineIn.END);
+ PacketLineIn pckIn = new PacketLineIn(recvStream);
+ assertThat(pckIn.readString(), is("packfile"));
+ parsePack(recvStream);
+ assertTrue(client.hasObject(barChild.toObjectId()));
+ assertFalse(client.hasObject(commonParent.toObjectId()));
+
+ // With shallow, the server knows that we don't have
+ // commonParent, so it sends it.
+ recvStream = uploadPackV2(
+ "command=fetch\n",
+ PacketLineIn.DELIM,
+ "want " + barChild.toObjectId().getName() + "\n",
+ "have " + fooChild.toObjectId().getName() + "\n",
+ "shallow " + fooChild.toObjectId().getName() + "\n",
+ "done\n",
+ PacketLineIn.END);
+ pckIn = new PacketLineIn(recvStream);
+ assertThat(pckIn.readString(), is("packfile"));
+ parsePack(recvStream);
+ assertTrue(client.hasObject(commonParent.toObjectId()));
+ }
+
+ @Test
+ public void testV2FetchDeepenAndDone() throws Exception {
+ RevCommit parent = remote.commit().message("parent").create();
+ RevCommit child = remote.commit().message("x").parent(parent).create();
+ remote.update("branch1", child);
+
+ // "deepen 1" sends only the child.
+ ByteArrayInputStream recvStream = uploadPackV2(
+ "command=fetch\n",
+ PacketLineIn.DELIM,
+ "want " + child.toObjectId().getName() + "\n",
+ "deepen 1\n",
+ "done\n",
+ PacketLineIn.END);
+ PacketLineIn pckIn = new PacketLineIn(recvStream);
+ assertThat(pckIn.readString(), is("shallow-info"));
+ assertThat(pckIn.readString(), is("shallow " + child.toObjectId().getName()));
+ assertThat(pckIn.readString(), theInstance(PacketLineIn.DELIM));
+ assertThat(pckIn.readString(), is("packfile"));
+ parsePack(recvStream);
+ assertTrue(client.hasObject(child.toObjectId()));
+ assertFalse(client.hasObject(parent.toObjectId()));
+
+ // Without that, the parent is sent too.
+ recvStream = uploadPackV2(
+ "command=fetch\n",
+ PacketLineIn.DELIM,
+ "want " + child.toObjectId().getName() + "\n",
+ "done\n",
+ PacketLineIn.END);
+ pckIn = new PacketLineIn(recvStream);
+ assertThat(pckIn.readString(), is("packfile"));
+ parsePack(recvStream);
+ assertTrue(client.hasObject(parent.toObjectId()));
+ }
+
+ @Test
+ public void testV2FetchDeepenWithoutDone() throws Exception {
+ RevCommit parent = remote.commit().message("parent").create();
+ RevCommit child = remote.commit().message("x").parent(parent).create();
+ remote.update("branch1", child);
+
+ ByteArrayInputStream recvStream = uploadPackV2(
+ "command=fetch\n",
+ PacketLineIn.DELIM,
+ "want " + child.toObjectId().getName() + "\n",
+ "deepen 1\n",
+ PacketLineIn.END);
+ PacketLineIn pckIn = new PacketLineIn(recvStream);
+
+ // Verify that only the correct section is sent. "shallow-info"
+ // is not sent because, according to the specification, it is
+ // sent only if a packfile is sent.
+ assertThat(pckIn.readString(), is("acknowledgments"));
+ assertThat(pckIn.readString(), is("NAK"));
+ assertThat(pckIn.readString(), theInstance(PacketLineIn.END));
+ }
+
+ @Test
+ public void testV2FetchUnrecognizedArgument() throws Exception {
+ thrown.expect(PackProtocolException.class);
+ thrown.expectMessage("unexpected invalid-argument");
+ uploadPackV2(
+ "command=fetch\n",
+ PacketLineIn.DELIM,
+ "invalid-argument\n",
+ PacketLineIn.END);
+ }
+
+ @Test
+ public void testV2FetchFilter() throws Exception {
+ RevBlob big = remote.blob("foobar");
+ RevBlob small = remote.blob("fooba");
+ RevTree tree = remote.tree(remote.file("1", big),
+ remote.file("2", small));
+ RevCommit commit = remote.commit(tree);
+ remote.update("master", commit);
+
+ server.getConfig().setBoolean("uploadpack", null, "allowfilter", true);
+
+ ByteArrayInputStream recvStream = uploadPackV2(
+ "command=fetch\n",
+ PacketLineIn.DELIM,
+ "want " + commit.toObjectId().getName() + "\n",
+ "filter blob:limit=5\n",
+ "done\n",
+ PacketLineIn.END);
+ PacketLineIn pckIn = new PacketLineIn(recvStream);
+ assertThat(pckIn.readString(), is("packfile"));
+ parsePack(recvStream);
+
+ assertFalse(client.hasObject(big.toObjectId()));
+ assertTrue(client.hasObject(small.toObjectId()));
+ }
+
+ @Test
+ public void testV2FetchFilterWhenNotAllowed() throws Exception {
+ RevCommit commit = remote.commit().message("0").create();
+ remote.update("master", commit);
+
+ server.getConfig().setBoolean("uploadpack", null, "allowfilter", false);
+
+ thrown.expect(PackProtocolException.class);
+ thrown.expectMessage("unexpected filter blob:limit=5");
+ uploadPackV2(
+ "command=fetch\n",
+ PacketLineIn.DELIM,
+ "want " + commit.toObjectId().getName() + "\n",
+ "filter blob:limit=5\n",
+ "done\n",
+ PacketLineIn.END);
+ }
+
+ private static class RejectAllRefFilter implements RefFilter {
+ @Override
+ public Map<String, Ref> filter(Map<String, Ref> refs) {
+ return new HashMap<>();
+ }
+ }
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/WalkEncryptionTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/WalkEncryptionTest.java
index cb04f83fb5..33e2529731 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/WalkEncryptionTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/WalkEncryptionTest.java
@@ -43,7 +43,7 @@
package org.eclipse.jgit.transport;
-import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
import static org.eclipse.jgit.transport.WalkEncryptionTest.Util.cryptoCipherListPBE;
import static org.eclipse.jgit.transport.WalkEncryptionTest.Util.cryptoCipherListTrans;
import static org.eclipse.jgit.transport.WalkEncryptionTest.Util.folderDelete;
@@ -360,7 +360,7 @@ public class WalkEncryptionTest {
* @throws Exception
*/
static String textRead(File file) throws Exception {
- return new String(Files.readAllBytes(file.toPath()), UTF_8);
+ return new String(Files.readAllBytes(file.toPath()), CHARSET);
}
/**
@@ -371,7 +371,7 @@ public class WalkEncryptionTest {
* @throws Exception
*/
static void textWrite(File file, String text) throws Exception {
- Files.write(file.toPath(), text.getBytes(UTF_8));
+ Files.write(file.toPath(), text.getBytes(CHARSET));
}
static void verifyFileContent(File fileOne, File fileTwo)
@@ -419,12 +419,9 @@ public class WalkEncryptionTest {
URLConnection c = url.openConnection();
c.setConnectTimeout(500);
c.setReadTimeout(500);
- BufferedReader reader = new BufferedReader(
- new InputStreamReader(c.getInputStream()));
- try {
+ try (BufferedReader reader = new BufferedReader(
+ new InputStreamReader(c.getInputStream()))) {
return reader.readLine();
- } finally {
- reader.close();
}
} catch (UnknownHostException | SocketTimeoutException e) {
return "Can't reach http://checkip.amazonaws.com to"
@@ -654,9 +651,9 @@ public class WalkEncryptionTest {
Properties props = Props.discover();
props.put(AmazonS3.Keys.PASSWORD, JGIT_PASS);
props.put(AmazonS3.Keys.CRYPTO_ALG, algorithm);
- PrintWriter writer = new PrintWriter(JGIT_CONF_FILE);
- props.store(writer, "JGIT S3 connection configuration file.");
- writer.close();
+ try (PrintWriter writer = new PrintWriter(JGIT_CONF_FILE)) {
+ props.store(writer, "JGIT S3 connection configuration file.");
+ }
}
/**
@@ -668,9 +665,9 @@ public class WalkEncryptionTest {
static void configCreate(Properties source) throws Exception {
Properties target = Props.discover();
target.putAll(source);
- PrintWriter writer = new PrintWriter(JGIT_CONF_FILE);
- target.store(writer, "JGIT S3 connection configuration file.");
- writer.close();
+ try (PrintWriter writer = new PrintWriter(JGIT_CONF_FILE)) {
+ target.store(writer, "JGIT S3 connection configuration file.");
+ }
}
/**
@@ -741,7 +738,7 @@ public class WalkEncryptionTest {
AmazonS3 s3 = new AmazonS3(props);
String file = JGIT_USER + "-" + UUID.randomUUID().toString();
String path = JGIT_REMOTE_DIR + "/" + file;
- s3.put(bucket, path, file.getBytes(UTF_8));
+ s3.put(bucket, path, file.getBytes(CHARSET));
s3.delete(bucket, path);
}
@@ -836,10 +833,10 @@ public class WalkEncryptionTest {
{
byte[] origin = sourceText.getBytes(charset);
ByteArrayOutputStream target = new ByteArrayOutputStream();
- OutputStream source = crypto.encrypt(target);
- source.write(origin);
- source.flush();
- source.close();
+ try (OutputStream source = crypto.encrypt(target)) {
+ source.write(origin);
+ source.flush();
+ }
cipherText = target.toByteArray();
}
{
@@ -1074,10 +1071,10 @@ public class WalkEncryptionTest {
remoteConfig.update(config);
config.save();
- Git git = Git.open(dirOne);
- git.checkout().setName("master").call();
- git.push().setRemote(remote).setRefSpecs(specs).call();
- git.close();
+ try (Git git = Git.open(dirOne)) {
+ git.checkout().setName("master").call();
+ git.push().setRemote(remote).setRefSpecs(specs).call();
+ }
File fileStatic = new File(dirOne, nameStatic);
assertTrue("Provided by setup", fileStatic.exists());
@@ -1089,11 +1086,11 @@ public class WalkEncryptionTest {
File fileStatic = new File(dirTwo, nameStatic);
assertFalse("Not Provided by setup", fileStatic.exists());
- Git git = Git.cloneRepository().setURI(uri).setDirectory(dirTwo)
- .call();
- git.close();
+ try (Git git = Git.cloneRepository().setURI(uri)
+ .setDirectory(dirTwo).call()) {
+ assertTrue("Provided by clone", fileStatic.exists());
+ }
- assertTrue("Provided by clone", fileStatic.exists());
}
{ // Verify static file content.
@@ -1111,11 +1108,11 @@ public class WalkEncryptionTest {
assertTrue("Provided by create", fileDynamic.exists());
assertTrue("Need content to encrypt", fileDynamic.length() > 0);
- Git git = Git.open(dirOne);
- git.add().addFilepattern(nameDynamic).call();
- git.commit().setMessage(nameDynamic).call();
- git.push().setRemote(remote).setRefSpecs(specs).call();
- git.close();
+ try (Git git = Git.open(dirOne)) {
+ git.add().addFilepattern(nameDynamic).call();
+ git.commit().setMessage(nameDynamic).call();
+ git.push().setRemote(remote).setRefSpecs(specs).call();
+ }
}
@@ -1124,9 +1121,9 @@ public class WalkEncryptionTest {
File fileDynamic = new File(dirTwo, nameDynamic);
assertFalse("Not Provided by setup", fileDynamic.exists());
- Git git = Git.open(dirTwo);
- git.pull().call();
- git.close();
+ try (Git git = Git.open(dirTwo)) {
+ git.pull().call();
+ }
assertTrue("Provided by pull", fileDynamic.exists());
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/CanonicalTreeParserTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/CanonicalTreeParserTest.java
index f5e97c2dc2..6195e640fb 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/CanonicalTreeParserTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/CanonicalTreeParserTest.java
@@ -91,9 +91,9 @@ public class CanonicalTreeParserTest {
hash_sometree), entry(m644, "foo", hash_foo));
}
- private static byte[] mktree(final byte[]... data) throws Exception {
+ private static byte[] mktree(byte[]... data) throws Exception {
final ByteArrayOutputStream out = new ByteArrayOutputStream();
- for (final byte[] e : data)
+ for (byte[] e : data)
out.write(e);
return out.toByteArray();
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorTest.java
index e34cb97798..0e009b9540 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorTest.java
@@ -821,7 +821,7 @@ public class FileTreeIteratorTest extends RepositoryTestCase {
assertEquals(sha1string, tw.getObjectId(1).getName() /* 1=filetree here */);
}
- private static String nameOf(final AbstractTreeIterator i) {
+ private static String nameOf(AbstractTreeIterator i) {
return RawParseUtils.decode(Constants.CHARSET, i.path, 0, i.pathLen);
}
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorWithTimeControl.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorWithTimeControl.java
index 717a2f3b2c..fc79d4586d 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorWithTimeControl.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorWithTimeControl.java
@@ -93,7 +93,7 @@ public class FileTreeIteratorWithTimeControl extends FileTreeIterator {
}
@Override
- public AbstractTreeIterator createSubtreeIterator(final ObjectReader reader) {
+ public AbstractTreeIterator createSubtreeIterator(ObjectReader reader) {
return new FileTreeIteratorWithTimeControl(this,
((FileEntry) current()).getFile(), fs, modTimes);
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/PostOrderTreeWalkTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/PostOrderTreeWalkTest.java
index 6ad47c2956..232422edf6 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/PostOrderTreeWalkTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/PostOrderTreeWalkTest.java
@@ -60,14 +60,14 @@ import org.junit.Test;
public class PostOrderTreeWalkTest extends RepositoryTestCase {
@Test
public void testInitialize_NoPostOrder() throws Exception {
- try (final TreeWalk tw = new TreeWalk(db)) {
+ try (TreeWalk tw = new TreeWalk(db)) {
assertFalse(tw.isPostOrderTraversal());
}
}
@Test
public void testInitialize_TogglePostOrder() throws Exception {
- try (final TreeWalk tw = new TreeWalk(db)) {
+ try (TreeWalk tw = new TreeWalk(db)) {
assertFalse(tw.isPostOrderTraversal());
tw.setPostOrderTraversal(true);
assertTrue(tw.isPostOrderTraversal());
@@ -78,7 +78,7 @@ public class PostOrderTreeWalkTest extends RepositoryTestCase {
@Test
public void testResetDoesNotAffectPostOrder() throws Exception {
- try (final TreeWalk tw = new TreeWalk(db)) {
+ try (TreeWalk tw = new TreeWalk(db)) {
tw.setPostOrderTraversal(true);
assertTrue(tw.isPostOrderTraversal());
tw.reset();
@@ -104,7 +104,7 @@ public class PostOrderTreeWalkTest extends RepositoryTestCase {
b.finish();
assertEquals(4, tree.getEntryCount());
- try (final TreeWalk tw = new TreeWalk(db)) {
+ try (TreeWalk tw = new TreeWalk(db)) {
tw.setPostOrderTraversal(false);
tw.addTree(new DirCacheIterator(tree));
@@ -132,7 +132,7 @@ public class PostOrderTreeWalkTest extends RepositoryTestCase {
b.finish();
assertEquals(4, tree.getEntryCount());
- try (final TreeWalk tw = new TreeWalk(db)) {
+ try (TreeWalk tw = new TreeWalk(db)) {
tw.setPostOrderTraversal(true);
tw.addTree(new DirCacheIterator(tree));
@@ -166,7 +166,7 @@ public class PostOrderTreeWalkTest extends RepositoryTestCase {
b.finish();
assertEquals(4, tree.getEntryCount());
- try (final TreeWalk tw = new TreeWalk(db)) {
+ try (TreeWalk tw = new TreeWalk(db)) {
tw.setPostOrderTraversal(true);
tw.addTree(new DirCacheIterator(tree));
@@ -180,7 +180,7 @@ public class PostOrderTreeWalkTest extends RepositoryTestCase {
}
}
- private DirCacheEntry makeFile(final String path) throws Exception {
+ private DirCacheEntry makeFile(String path) throws Exception {
return createEntry(path, REGULAR_FILE);
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/AlwaysCloneTreeFilter.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/AlwaysCloneTreeFilter.java
index 8e2cca44ae..d9cfb622a8 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/AlwaysCloneTreeFilter.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/AlwaysCloneTreeFilter.java
@@ -52,7 +52,7 @@ class AlwaysCloneTreeFilter extends TreeFilter {
}
@Override
- public boolean include(final TreeWalk walker) {
+ public boolean include(TreeWalk walker) {
return false;
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/NotTreeFilterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/NotTreeFilterTest.java
index f7a7fb8a97..c6389fb1ae 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/NotTreeFilterTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/NotTreeFilterTest.java
@@ -57,12 +57,13 @@ import org.junit.Test;
public class NotTreeFilterTest extends RepositoryTestCase {
@Test
public void testWrap() throws Exception {
- final TreeWalk tw = new TreeWalk(db);
- final TreeFilter a = TreeFilter.ALL;
- final TreeFilter n = NotTreeFilter.create(a);
- assertNotNull(n);
- assertTrue(a.include(tw));
- assertFalse(n.include(tw));
+ try (TreeWalk tw = new TreeWalk(db)) {
+ final TreeFilter a = TreeFilter.ALL;
+ final TreeFilter n = NotTreeFilter.create(a);
+ assertNotNull(n);
+ assertTrue(a.include(tw));
+ assertFalse(n.include(tw));
+ }
}
@Test
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/PathFilterGroupTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/PathFilterGroupTest.java
index d921aabdc1..71a2f327c8 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/PathFilterGroupTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/PathFilterGroupTest.java
@@ -254,7 +254,7 @@ public class PathFilterGroupTest {
}
}
- TreeWalk fakeWalk(final String path) throws IOException {
+ TreeWalk fakeWalk(String path) throws IOException {
DirCache dc = DirCache.newInCore();
DirCacheEditor dce = dc.editor();
dce.add(new DirCacheEditor.PathEdit(path) {
@@ -274,7 +274,7 @@ public class PathFilterGroupTest {
return ret;
}
- TreeWalk fakeWalkAtSubtree(final String path) throws IOException {
+ TreeWalk fakeWalkAtSubtree(String path) throws IOException {
DirCache dc = DirCache.newInCore();
DirCacheEditor dce = dc.editor();
dce.add(new DirCacheEditor.PathEdit(path + "/README") {
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/PathSuffixFilterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/PathSuffixFilterTest.java
index 38adda3120..148d5ac820 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/PathSuffixFilterTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/PathSuffixFilterTest.java
@@ -113,7 +113,7 @@ public class PathSuffixFilterTest extends RepositoryTestCase {
private List<String> getMatchingPaths(String suffixFilter,
final ObjectId treeId, boolean recursiveWalk) throws IOException {
- try (final TreeWalk tw = new TreeWalk(db)) {
+ try (TreeWalk tw = new TreeWalk(db)) {
tw.setFilter(PathSuffixFilter.create(suffixFilter));
tw.setRecursive(recursiveWalk);
tw.addTree(treeId);
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/TreeFilterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/TreeFilterTest.java
index c3423b6fb1..8686c4f094 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/TreeFilterTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/TreeFilterTest.java
@@ -55,7 +55,7 @@ import org.junit.Test;
public class TreeFilterTest extends RepositoryTestCase {
@Test
public void testALL_IncludesAnything() throws Exception {
- try (final TreeWalk tw = new TreeWalk(db)) {
+ try (TreeWalk tw = new TreeWalk(db)) {
tw.addTree(new EmptyTreeIterator());
assertTrue(TreeFilter.ALL.include(tw));
}
@@ -73,7 +73,7 @@ public class TreeFilterTest extends RepositoryTestCase {
@Test
public void testNotALL_IncludesNothing() throws Exception {
- try (final TreeWalk tw = new TreeWalk(db)) {
+ try (TreeWalk tw = new TreeWalk(db)) {
tw.addTree(new EmptyTreeIterator());
assertFalse(TreeFilter.ALL.negate().include(tw));
}
@@ -81,7 +81,7 @@ public class TreeFilterTest extends RepositoryTestCase {
@Test
public void testANY_DIFF_IncludesSingleTreeCase() throws Exception {
- try (final TreeWalk tw = new TreeWalk(db)) {
+ try (TreeWalk tw = new TreeWalk(db)) {
tw.addTree(new EmptyTreeIterator());
assertTrue(TreeFilter.ANY_DIFF.include(tw));
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/ChangeIdUtilTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/ChangeIdUtilTest.java
index 6fed233051..81467c2d01 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/ChangeIdUtilTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/ChangeIdUtilTest.java
@@ -680,15 +680,15 @@ public class ChangeIdUtilTest {
"\n"));
}
- private void hookDoesNotModify(final String in) throws Exception {
+ private void hookDoesNotModify(String in) throws Exception {
assertEquals(in, call(in));
}
- private String call(final String body) throws Exception {
+ private String call(String body) throws Exception {
return call(body, false);
}
- private String call(final String body, boolean replaceExisting) throws Exception {
+ private String call(String body, boolean replaceExisting) throws Exception {
ObjectId computeChangeId = ChangeIdUtil.computeChangeId(treeId1,
parentId1, author, committer, body);
if (computeChangeId == null)
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/HookTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/HookTest.java
index a680ef9f9c..e34c3cebd6 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/HookTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/HookTest.java
@@ -241,7 +241,7 @@ public class HookTest extends RepositoryTestCase {
}
}
- private File writeHookFile(final String name, final String data)
+ private File writeHookFile(String name, String data)
throws IOException {
File path = new File(db.getWorkTree() + "/.git/hooks/", name);
JGitTestUtil.write(path, data);
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/NBTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/NBTest.java
index d2d44ffdc8..830f20e5c3 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/NBTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/NBTest.java
@@ -338,7 +338,7 @@ public class NBTest {
assertOutput(b(0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff), out, 3);
}
- private static void prepareOutput(final byte[] buf) {
+ private static void prepareOutput(byte[] buf) {
for (int i = 0; i < buf.length; i++)
buf[i] = (byte) (0x77 + i);
}
@@ -353,11 +353,11 @@ public class NBTest {
assertEquals((byte) (0x77 + i), buf[i]);
}
- private static byte[] b(final int a, final int b) {
+ private static byte[] b(int a, int b) {
return new byte[] { (byte) a, (byte) b };
}
- private static byte[] padb(final int len, final int a, final int b) {
+ private static byte[] padb(int len, int a, int b) {
final byte[] r = new byte[len + 2];
for (int i = 0; i < len; i++)
r[i] = (byte) 0xaf;
@@ -370,7 +370,7 @@ public class NBTest {
return new byte[] { (byte) a, (byte) b, (byte) c };
}
- private static byte[] b(final int a, final int b, final int c, final int d) {
+ private static byte[] b(int a, int b, int c, int d) {
return new byte[] { (byte) a, (byte) b, (byte) c, (byte) d };
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/QuotedStringBourneStyleTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/QuotedStringBourneStyleTest.java
index 65078763e7..49ad55f42d 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/QuotedStringBourneStyleTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/QuotedStringBourneStyleTest.java
@@ -52,14 +52,14 @@ import org.eclipse.jgit.lib.Constants;
import org.junit.Test;
public class QuotedStringBourneStyleTest {
- private static void assertQuote(final String in, final String exp) {
+ private static void assertQuote(String in, String exp) {
final String r = BOURNE.quote(in);
assertNotSame(in, r);
assertFalse(in.equals(r));
assertEquals('\'' + exp + '\'', r);
}
- private static void assertDequote(final String exp, final String in) {
+ private static void assertDequote(String exp, String in) {
final byte[] b = Constants.encode('\'' + in + '\'');
final String r = BOURNE.dequote(b, 0, b.length);
assertEquals(exp, r);
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/QuotedStringBourneUserPathStyleTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/QuotedStringBourneUserPathStyleTest.java
index 7463528b56..17f1b77e0b 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/QuotedStringBourneUserPathStyleTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/QuotedStringBourneUserPathStyleTest.java
@@ -52,14 +52,14 @@ import org.eclipse.jgit.lib.Constants;
import org.junit.Test;
public class QuotedStringBourneUserPathStyleTest {
- private static void assertQuote(final String in, final String exp) {
+ private static void assertQuote(String in, String exp) {
final String r = BOURNE_USER_PATH.quote(in);
assertNotSame(in, r);
assertFalse(in.equals(r));
assertEquals('\'' + exp + '\'', r);
}
- private static void assertDequote(final String exp, final String in) {
+ private static void assertDequote(String exp, String in) {
final byte[] b = Constants.encode('\'' + in + '\'');
final String r = BOURNE_USER_PATH.dequote(b, 0, b.length);
assertEquals(exp, r);
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/QuotedStringGitPathStyleTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/QuotedStringGitPathStyleTest.java
index a6f33451ce..9a0c96e171 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/QuotedStringGitPathStyleTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/QuotedStringGitPathStyleTest.java
@@ -54,14 +54,14 @@ import org.eclipse.jgit.lib.Constants;
import org.junit.Test;
public class QuotedStringGitPathStyleTest {
- private static void assertQuote(final String exp, final String in) {
+ private static void assertQuote(String exp, String in) {
final String r = GIT_PATH.quote(in);
assertNotSame(in, r);
assertFalse(in.equals(r));
assertEquals('"' + exp + '"', r);
}
- private static void assertDequote(final String exp, final String in) {
+ private static void assertDequote(String exp, String in) {
final byte[] b = ('"' + in + '"').getBytes(ISO_8859_1);
final String r = GIT_PATH.dequote(b, 0, b.length);
assertEquals(exp, r);
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawParseUtils_HexParseTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawParseUtils_HexParseTest.java
index f5b56e7b78..f3c046d4a9 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawParseUtils_HexParseTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawParseUtils_HexParseTest.java
@@ -81,7 +81,7 @@ public class RawParseUtils_HexParseTest {
assertNotHex('.');
}
- private static void assertNotHex(final char c) {
+ private static void assertNotHex(char c) {
try {
RawParseUtils.parseHexInt4((byte) c);
fail("Incorrectly acccepted " + c);
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawParseUtils_LineMapTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawParseUtils_LineMapTest.java
index 0243798666..7630c11185 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawParseUtils_LineMapTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawParseUtils_LineMapTest.java
@@ -47,18 +47,25 @@ import static java.nio.charset.StandardCharsets.ISO_8859_1;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertNotNull;
+import org.eclipse.jgit.errors.BinaryBlobException;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.ExpectedException;
public class RawParseUtils_LineMapTest {
+ @Rule
+ public ExpectedException exception = ExpectedException.none();
+
+
@Test
- public void testEmpty() {
+ public void testEmpty() throws Exception {
final IntList map = RawParseUtils.lineMap(new byte[] {}, 0, 0);
assertNotNull(map);
assertArrayEquals(new int[]{Integer.MIN_VALUE, 0}, asInts(map));
}
@Test
- public void testOneBlankLine() {
+ public void testOneBlankLine() throws Exception {
final IntList map = RawParseUtils.lineMap(new byte[] { '\n' }, 0, 1);
assertArrayEquals(new int[]{Integer.MIN_VALUE, 0, 1}, asInts(map));
}
@@ -85,6 +92,13 @@ public class RawParseUtils_LineMapTest {
}
@Test
+ public void testLineMapOrBinary() throws Exception {
+ final byte[] buf = "xxxfoo\nb\0ar".getBytes(ISO_8859_1);
+ exception.expect(BinaryBlobException.class);
+ RawParseUtils.lineMapOrBinary(buf, 3, buf.length);
+ }
+
+ @Test
public void testFourLineBlanks() {
final byte[] buf = "foo\n\n\nbar\n".getBytes(ISO_8859_1);
final IntList map = RawParseUtils.lineMap(buf, 0, buf.length);
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawSubStringPatternTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawSubStringPatternTest.java
index e8566d2438..a748b52215 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawSubStringPatternTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawSubStringPatternTest.java
@@ -42,7 +42,7 @@
*/
package org.eclipse.jgit.util;
-import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@@ -93,7 +93,7 @@ public class RawSubStringPatternTest extends RepositoryTestCase {
}
private static RawCharSequence raw(String text) {
- byte[] bytes = text.getBytes(UTF_8);
+ byte[] bytes = text.getBytes(CHARSET);
return new RawCharSequence(bytes, 0, bytes.length);
}
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RefListTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RefListTest.java
index 5a1468a8b6..d124d7365c 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RefListTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RefListTest.java
@@ -456,7 +456,7 @@ public class RefListTest {
return b.toRefList();
}
- private static Ref newRef(final String name) {
+ private static Ref newRef(String name) {
return new ObjectIdRef.Unpeeled(Ref.Storage.LOOSE, name, ID);
}
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/TemporaryBufferTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/TemporaryBufferTest.java
index d978804d57..edcce126bb 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/TemporaryBufferTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/TemporaryBufferTest.java
@@ -61,6 +61,7 @@ import org.junit.Test;
public class TemporaryBufferTest {
@Test
public void testEmpty() throws IOException {
+ @SuppressWarnings("resource") // Buffer is explicitly destroyed in finally block
final TemporaryBuffer b = new TemporaryBuffer.LocalFile(null);
try {
b.close();
@@ -75,6 +76,7 @@ public class TemporaryBufferTest {
@Test
public void testOneByte() throws IOException {
+ @SuppressWarnings("resource") // Buffer is explicitly destroyed in finally block
final TemporaryBuffer b = new TemporaryBuffer.LocalFile(null);
final byte test = (byte) new TestRng(getName()).nextInt();
try {
@@ -87,10 +89,8 @@ public class TemporaryBufferTest {
assertEquals(1, r.length);
assertEquals(test, r[0]);
}
- {
- final ByteArrayOutputStream o = new ByteArrayOutputStream();
+ try (ByteArrayOutputStream o = new ByteArrayOutputStream()) {
b.writeTo(o, null);
- o.close();
final byte[] r = o.toByteArray();
assertEquals(1, r.length);
assertEquals(test, r[0]);
@@ -102,6 +102,7 @@ public class TemporaryBufferTest {
@Test
public void testOneBlock_BulkWrite() throws IOException {
+ @SuppressWarnings("resource") // Buffer is explicitly destroyed in finally block
final TemporaryBuffer b = new TemporaryBuffer.LocalFile(null);
final byte[] test = new TestRng(getName())
.nextBytes(TemporaryBuffer.Block.SZ);
@@ -118,10 +119,8 @@ public class TemporaryBufferTest {
assertEquals(test.length, r.length);
assertArrayEquals(test, r);
}
- {
- final ByteArrayOutputStream o = new ByteArrayOutputStream();
+ try (ByteArrayOutputStream o = new ByteArrayOutputStream()) {
b.writeTo(o, null);
- o.close();
final byte[] r = o.toByteArray();
assertEquals(test.length, r.length);
assertArrayEquals(test, r);
@@ -133,6 +132,7 @@ public class TemporaryBufferTest {
@Test
public void testOneBlockAndHalf_BulkWrite() throws IOException {
+ @SuppressWarnings("resource") // Buffer is explicitly destroyed in finally block
final TemporaryBuffer b = new TemporaryBuffer.LocalFile(null);
final byte[] test = new TestRng(getName())
.nextBytes(TemporaryBuffer.Block.SZ * 3 / 2);
@@ -149,10 +149,8 @@ public class TemporaryBufferTest {
assertEquals(test.length, r.length);
assertArrayEquals(test, r);
}
- {
- final ByteArrayOutputStream o = new ByteArrayOutputStream();
+ try (ByteArrayOutputStream o = new ByteArrayOutputStream()) {
b.writeTo(o, null);
- o.close();
final byte[] r = o.toByteArray();
assertEquals(test.length, r.length);
assertArrayEquals(test, r);
@@ -164,6 +162,7 @@ public class TemporaryBufferTest {
@Test
public void testOneBlockAndHalf_SingleWrite() throws IOException {
+ @SuppressWarnings("resource") // Buffer is explicitly destroyed in finally block
final TemporaryBuffer b = new TemporaryBuffer.LocalFile(null);
final byte[] test = new TestRng(getName())
.nextBytes(TemporaryBuffer.Block.SZ * 3 / 2);
@@ -178,10 +177,8 @@ public class TemporaryBufferTest {
assertEquals(test.length, r.length);
assertArrayEquals(test, r);
}
- {
- final ByteArrayOutputStream o = new ByteArrayOutputStream();
+ try (ByteArrayOutputStream o = new ByteArrayOutputStream()) {
b.writeTo(o, null);
- o.close();
final byte[] r = o.toByteArray();
assertEquals(test.length, r.length);
assertArrayEquals(test, r);
@@ -193,6 +190,7 @@ public class TemporaryBufferTest {
@Test
public void testOneBlockAndHalf_Copy() throws IOException {
+ @SuppressWarnings("resource") // Buffer is explicitly destroyed in finally block
final TemporaryBuffer b = new TemporaryBuffer.LocalFile(null);
final byte[] test = new TestRng(getName())
.nextBytes(TemporaryBuffer.Block.SZ * 3 / 2);
@@ -208,10 +206,8 @@ public class TemporaryBufferTest {
assertEquals(test.length, r.length);
assertArrayEquals(test, r);
}
- {
- final ByteArrayOutputStream o = new ByteArrayOutputStream();
+ try (ByteArrayOutputStream o = new ByteArrayOutputStream()) {
b.writeTo(o, null);
- o.close();
final byte[] r = o.toByteArray();
assertEquals(test.length, r.length);
assertArrayEquals(test, r);
@@ -223,6 +219,7 @@ public class TemporaryBufferTest {
@Test
public void testLarge_SingleWrite() throws IOException {
+ @SuppressWarnings("resource") // Buffer is explicitly destroyed in finally block
final TemporaryBuffer b = new TemporaryBuffer.LocalFile(null);
final byte[] test = new TestRng(getName())
.nextBytes(TemporaryBuffer.DEFAULT_IN_CORE_LIMIT * 3);
@@ -236,10 +233,8 @@ public class TemporaryBufferTest {
assertEquals(test.length, r.length);
assertArrayEquals(test, r);
}
- {
- final ByteArrayOutputStream o = new ByteArrayOutputStream();
+ try (ByteArrayOutputStream o = new ByteArrayOutputStream()) {
b.writeTo(o, null);
- o.close();
final byte[] r = o.toByteArray();
assertEquals(test.length, r.length);
assertArrayEquals(test, r);
@@ -253,18 +248,18 @@ public class TemporaryBufferTest {
public void testInCoreInputStream() throws IOException {
final int cnt = 256;
final byte[] test = new TestRng(getName()).nextBytes(cnt);
- final TemporaryBuffer.Heap b = new TemporaryBuffer.Heap(cnt + 4);
- b.write(test);
- b.close();
-
- InputStream in = b.openInputStream();
- byte[] act = new byte[cnt];
- IO.readFully(in, act, 0, cnt);
- assertArrayEquals(test, act);
+ try (TemporaryBuffer.Heap b = new TemporaryBuffer.Heap(cnt + 4)) {
+ b.write(test);
+ InputStream in = b.openInputStream();
+ byte[] act = new byte[cnt];
+ IO.readFully(in, act, 0, cnt);
+ assertArrayEquals(test, act);
+ }
}
@Test
public void testInCoreLimit_SwitchOnAppendByte() throws IOException {
+ @SuppressWarnings("resource") // Buffer is explicitly destroyed in finally block
final TemporaryBuffer b = new TemporaryBuffer.LocalFile(null);
final byte[] test = new TestRng(getName())
.nextBytes(TemporaryBuffer.DEFAULT_IN_CORE_LIMIT + 1);
@@ -279,10 +274,8 @@ public class TemporaryBufferTest {
assertEquals(test.length, r.length);
assertArrayEquals(test, r);
}
- {
- final ByteArrayOutputStream o = new ByteArrayOutputStream();
+ try (ByteArrayOutputStream o = new ByteArrayOutputStream()) {
b.writeTo(o, null);
- o.close();
final byte[] r = o.toByteArray();
assertEquals(test.length, r.length);
assertArrayEquals(test, r);
@@ -294,6 +287,7 @@ public class TemporaryBufferTest {
@Test
public void testInCoreLimit_SwitchBeforeAppendByte() throws IOException {
+ @SuppressWarnings("resource") // Buffer is explicitly destroyed in finally block
final TemporaryBuffer b = new TemporaryBuffer.LocalFile(null);
final byte[] test = new TestRng(getName())
.nextBytes(TemporaryBuffer.DEFAULT_IN_CORE_LIMIT * 3);
@@ -308,10 +302,8 @@ public class TemporaryBufferTest {
assertEquals(test.length, r.length);
assertArrayEquals(test, r);
}
- {
- final ByteArrayOutputStream o = new ByteArrayOutputStream();
+ try (ByteArrayOutputStream o = new ByteArrayOutputStream()) {
b.writeTo(o, null);
- o.close();
final byte[] r = o.toByteArray();
assertEquals(test.length, r.length);
assertArrayEquals(test, r);
@@ -323,6 +315,7 @@ public class TemporaryBufferTest {
@Test
public void testInCoreLimit_SwitchOnCopy() throws IOException {
+ @SuppressWarnings("resource") // Buffer is explicitly destroyed in finally block
final TemporaryBuffer b = new TemporaryBuffer.LocalFile(null);
final byte[] test = new TestRng(getName())
.nextBytes(TemporaryBuffer.DEFAULT_IN_CORE_LIMIT * 2);
@@ -340,10 +333,8 @@ public class TemporaryBufferTest {
assertEquals(test.length, r.length);
assertArrayEquals(test, r);
}
- {
- final ByteArrayOutputStream o = new ByteArrayOutputStream();
+ try (ByteArrayOutputStream o = new ByteArrayOutputStream()) {
b.writeTo(o, null);
- o.close();
final byte[] r = o.toByteArray();
assertEquals(test.length, r.length);
assertArrayEquals(test, r);
@@ -355,7 +346,7 @@ public class TemporaryBufferTest {
@Test
public void testDestroyWhileOpen() throws IOException {
- @SuppressWarnings("resource" /* java 7 */)
+ @SuppressWarnings("resource") // Buffer is explicitly destroyed in finally block
final TemporaryBuffer b = new TemporaryBuffer.LocalFile(null);
try {
b.write(new TestRng(getName())
@@ -367,6 +358,7 @@ public class TemporaryBufferTest {
@Test
public void testRandomWrites() throws IOException {
+ @SuppressWarnings("resource") // Buffer is explicitly destroyed in finally block
final TemporaryBuffer b = new TemporaryBuffer.LocalFile(null);
final TestRng rng = new TestRng(getName());
final int max = TemporaryBuffer.DEFAULT_IN_CORE_LIMIT * 2;
@@ -399,10 +391,8 @@ public class TemporaryBufferTest {
assertEquals(expect.length, r.length);
assertArrayEquals(expect, r);
}
- {
- final ByteArrayOutputStream o = new ByteArrayOutputStream();
+ try (ByteArrayOutputStream o = new ByteArrayOutputStream()) {
b.writeTo(o, null);
- o.close();
final byte[] r = o.toByteArray();
assertEquals(expect.length, r.length);
assertArrayEquals(expect, r);
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoCRLFOutputStreamTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoCRLFOutputStreamTest.java
index a72d33cd51..0655827310 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoCRLFOutputStreamTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoCRLFOutputStreamTest.java
@@ -96,32 +96,31 @@ public class AutoCRLFOutputStreamTest {
for (int i = -4; i < 5; ++i) {
int size = Math.abs(i);
byte[] buf = new byte[size];
- InputStream in = new ByteArrayInputStream(inbytes);
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- OutputStream out = new AutoCRLFOutputStream(bos);
- if (i > 0) {
- int n;
- while ((n = in.read(buf)) >= 0) {
- out.write(buf, 0, n);
+ try (InputStream in = new ByteArrayInputStream(inbytes);
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ OutputStream out = new AutoCRLFOutputStream(bos)) {
+ if (i > 0) {
+ int n;
+ while ((n = in.read(buf)) >= 0) {
+ out.write(buf, 0, n);
+ }
+ } else if (i < 0) {
+ int n;
+ while ((n = in.read(buf)) >= 0) {
+ byte[] b = new byte[n];
+ System.arraycopy(buf, 0, b, 0, n);
+ out.write(b);
+ }
+ } else {
+ int c;
+ while ((c = in.read()) != -1)
+ out.write(c);
}
- } else if (i < 0) {
- int n;
- while ((n = in.read(buf)) >= 0) {
- byte[] b = new byte[n];
- System.arraycopy(buf, 0, b, 0, n);
- out.write(b);
- }
- } else {
- int c;
- while ((c = in.read()) != -1)
- out.write(c);
+ out.flush();
+ byte[] actualBytes = bos.toByteArray();
+ Assert.assertEquals("bufsize=" + size, encode(expectBytes),
+ encode(actualBytes));
}
- out.flush();
- in.close();
- out.close();
- byte[] actualBytes = bos.toByteArray();
- Assert.assertEquals("bufsize=" + size, encode(expectBytes),
- encode(actualBytes));
}
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoLFInputStreamTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoLFInputStreamTest.java
index 38199d8aaf..5058165802 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoLFInputStreamTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoLFInputStreamTest.java
@@ -44,7 +44,7 @@
package org.eclipse.jgit.util.io;
-import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
import static org.junit.Assert.assertEquals;
import java.io.ByteArrayInputStream;
@@ -97,38 +97,41 @@ public class AutoLFInputStreamTest {
private static void test(byte[] input, byte[] expected,
boolean detectBinary) throws IOException {
- final InputStream bis1 = new ByteArrayInputStream(input);
- final InputStream cis1 = new AutoLFInputStream(bis1, detectBinary);
- int index1 = 0;
- for (int b = cis1.read(); b != -1; b = cis1.read()) {
- assertEquals(expected[index1], (byte) b);
- index1++;
- }
-
- assertEquals(expected.length, index1);
-
- for (int bufferSize = 1; bufferSize < 10; bufferSize++) {
- final byte[] buffer = new byte[bufferSize];
- final InputStream bis2 = new ByteArrayInputStream(input);
- final InputStream cis2 = new AutoLFInputStream(bis2, detectBinary);
+ try (InputStream bis1 = new ByteArrayInputStream(input);
+ InputStream cis1 = new AutoLFInputStream(bis1, detectBinary)) {
+ int index1 = 0;
+ for (int b = cis1.read(); b != -1; b = cis1.read()) {
+ assertEquals(expected[index1], (byte) b);
+ index1++;
+ }
- int read = 0;
- for (int readNow = cis2.read(buffer, 0, buffer.length); readNow != -1
- && read < expected.length; readNow = cis2.read(buffer, 0,
- buffer.length)) {
- for (int index2 = 0; index2 < readNow; index2++) {
- assertEquals(expected[read + index2], buffer[index2]);
+ assertEquals(expected.length, index1);
+
+ for (int bufferSize = 1; bufferSize < 10; bufferSize++) {
+ final byte[] buffer = new byte[bufferSize];
+ try (InputStream bis2 = new ByteArrayInputStream(input);
+ InputStream cis2 = new AutoLFInputStream(bis2,
+ detectBinary)) {
+
+ int read = 0;
+ for (int readNow = cis2.read(buffer, 0,
+ buffer.length); readNow != -1
+ && read < expected.length; readNow = cis2
+ .read(buffer, 0, buffer.length)) {
+ for (int index2 = 0; index2 < readNow; index2++) {
+ assertEquals(expected[read + index2],
+ buffer[index2]);
+ }
+ read += readNow;
+ }
+
+ assertEquals(expected.length, read);
}
- read += readNow;
}
-
- assertEquals(expected.length, read);
- cis2.close();
}
- cis1.close();
}
private static byte[] asBytes(String in) {
- return in.getBytes(UTF_8);
+ return in.getBytes(CHARSET);
}
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/UnionInputStreamTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/UnionInputStreamTest.java
index 6b5ef7ec64..b824fae9fd 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/UnionInputStreamTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/UnionInputStreamTest.java
@@ -58,13 +58,13 @@ import org.junit.Test;
public class UnionInputStreamTest {
@Test
public void testEmptyStream() throws IOException {
- final UnionInputStream u = new UnionInputStream();
- assertTrue(u.isEmpty());
- assertEquals(-1, u.read());
- assertEquals(-1, u.read(new byte[1], 0, 1));
- assertEquals(0, u.available());
- assertEquals(0, u.skip(1));
- u.close();
+ try (UnionInputStream u = new UnionInputStream()) {
+ assertTrue(u.isEmpty());
+ assertEquals(-1, u.read());
+ assertEquals(-1, u.read(new byte[1], 0, 1));
+ assertEquals(0, u.available());
+ assertEquals(0, u.skip(1));
+ }
}
@Test
@@ -211,25 +211,24 @@ public class UnionInputStreamTest {
@Test
public void testCloseDuringClose() throws IOException {
- final UnionInputStream u = new UnionInputStream();
final boolean closed[] = new boolean[2];
- u.add(new ByteArrayInputStream(new byte[] { 1 }) {
- @Override
- public void close() {
- closed[0] = true;
- }
- });
- u.add(new ByteArrayInputStream(new byte[] { 2 }) {
- @Override
- public void close() {
- closed[1] = true;
- }
- });
+ try (UnionInputStream u = new UnionInputStream()) {
+ u.add(new ByteArrayInputStream(new byte[] { 1 }) {
+ @Override
+ public void close() {
+ closed[0] = true;
+ }
+ });
+ u.add(new ByteArrayInputStream(new byte[] { 2 }) {
+ @Override
+ public void close() {
+ closed[1] = true;
+ }
+ });
- assertFalse(closed[0]);
- assertFalse(closed[1]);
-
- u.close();
+ assertFalse(closed[0]);
+ assertFalse(closed[1]);
+ }
assertTrue(closed[0]);
assertTrue(closed[1]);
@@ -237,6 +236,7 @@ public class UnionInputStreamTest {
@Test
public void testExceptionDuringClose() {
+ @SuppressWarnings("resource") // We are testing the close() method
final UnionInputStream u = new UnionInputStream();
u.add(new ByteArrayInputStream(new byte[] { 1 }) {
@Override
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/sha1/SHA1Test.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/sha1/SHA1Test.java
index e6045a91bd..3c612e1bdd 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/sha1/SHA1Test.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/sha1/SHA1Test.java
@@ -43,7 +43,7 @@
package org.eclipse.jgit.util.sha1;
-import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -95,15 +95,15 @@ public class SHA1Test {
.fromString("a9993e364706816aba3e25717850c26c9cd0d89d");
MessageDigest m = MessageDigest.getInstance("SHA-1");
- m.update(TEST1.getBytes(UTF_8));
+ m.update(TEST1.getBytes(CHARSET));
ObjectId m1 = ObjectId.fromRaw(m.digest());
SHA1 s = SHA1.newInstance();
- s.update(TEST1.getBytes(UTF_8));
+ s.update(TEST1.getBytes(CHARSET));
ObjectId s1 = ObjectId.fromRaw(s.digest());
s.reset();
- s.update(TEST1.getBytes(UTF_8));
+ s.update(TEST1.getBytes(CHARSET));
ObjectId s2 = s.toObjectId();
assertEquals(m1, s1);
@@ -117,15 +117,15 @@ public class SHA1Test {
.fromString("84983e441c3bd26ebaae4aa1f95129e5e54670f1");
MessageDigest m = MessageDigest.getInstance("SHA-1");
- m.update(TEST2.getBytes(UTF_8));
+ m.update(TEST2.getBytes(CHARSET));
ObjectId m1 = ObjectId.fromRaw(m.digest());
SHA1 s = SHA1.newInstance();
- s.update(TEST2.getBytes(UTF_8));
+ s.update(TEST2.getBytes(CHARSET));
ObjectId s1 = ObjectId.fromRaw(s.digest());
s.reset();
- s.update(TEST2.getBytes(UTF_8));
+ s.update(TEST2.getBytes(CHARSET));
ObjectId s2 = s.toObjectId();
assertEquals(m1, s1);