Browse Source
Change-Id: Ieec4f51aedadf5734ae0e3f4e8713248a3c4fc52 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>stable-4.2
Matthias Sohn
9 years ago
195 changed files with 9435 additions and 3893 deletions
@ -0,0 +1,15 @@
|
||||
[buildfile] |
||||
includes = //tools/default.defs |
||||
|
||||
[java] |
||||
src_roots = src, resources, tst |
||||
|
||||
[project] |
||||
ignore = .git |
||||
|
||||
[cache] |
||||
mode = dir |
||||
|
||||
[download] |
||||
maven_repo = http://repo1.maven.org/maven2 |
||||
in_build = true |
@ -0,0 +1,45 @@
|
||||
java_library( |
||||
name = 'jgit', |
||||
exported_deps = ['//org.eclipse.jgit:jgit'], |
||||
visibility = ['PUBLIC'], |
||||
) |
||||
|
||||
genrule( |
||||
name = 'jgit_src', |
||||
cmd = 'ln -s $(location //org.eclipse.jgit:jgit_src) $OUT', |
||||
out = 'jgit_src.zip', |
||||
visibility = ['PUBLIC'], |
||||
) |
||||
|
||||
java_library( |
||||
name = 'jgit-servlet', |
||||
exported_deps = [ |
||||
':jgit', |
||||
'//org.eclipse.jgit.http.server:jgit-servlet' |
||||
], |
||||
visibility = ['PUBLIC'], |
||||
) |
||||
|
||||
java_library( |
||||
name = 'jgit-archive', |
||||
exported_deps = [ |
||||
':jgit', |
||||
'//org.eclipse.jgit.archive:jgit-archive' |
||||
], |
||||
visibility = ['PUBLIC'], |
||||
) |
||||
|
||||
java_library( |
||||
name = 'junit', |
||||
exported_deps = [ |
||||
':jgit', |
||||
'//org.eclipse.jgit.junit:junit' |
||||
], |
||||
visibility = ['PUBLIC'], |
||||
) |
||||
|
||||
genrule( |
||||
name = 'jgit_bin', |
||||
cmd = 'ln -s $(location //org.eclipse.jgit.pgm:jgit) $OUT', |
||||
out = 'jgit_bin', |
||||
) |
@ -0,0 +1,125 @@
|
||||
maven_jar( |
||||
name = 'jsch', |
||||
bin_sha1 = '658b682d5c817b27ae795637dfec047c63d29935', |
||||
src_sha1 = '791359d94d6edcace686a56d0727ee093a2f7c33', |
||||
group = 'com.jcraft', |
||||
artifact = 'jsch', |
||||
version = '0.1.53', |
||||
) |
||||
|
||||
maven_jar( |
||||
name = 'javaewah', |
||||
bin_sha1 = 'eceaf316a8faf0e794296ebe158ae110c7d72a5a', |
||||
src_sha1 = 'a50d78eb630e05439461f3130b94b3bcd1ea6f03', |
||||
group = 'com.googlecode.javaewah', |
||||
artifact = 'JavaEWAH', |
||||
version = '0.7.9', |
||||
) |
||||
|
||||
maven_jar( |
||||
name = 'httpcomponents', |
||||
bin_sha1 = '4c47155e3e6c9a41a28db36680b828ced53b8af4', |
||||
src_sha1 = 'af4d76be0c46ee26b0d9d1d4a34d244a633cac84', |
||||
group = 'org.apache.httpcomponents', |
||||
artifact = 'httpclient', |
||||
version = '4.3.6', |
||||
) |
||||
|
||||
maven_jar( |
||||
name = 'httpcore', |
||||
bin_sha1 = 'f91b7a4aadc5cf486df6e4634748d7dd7a73f06d', |
||||
src_sha1 = '1b0aa62a6a91e9fa00c16f0a4a2c874804ed3b1e', |
||||
group = 'org.apache.httpcomponents', |
||||
artifact = 'httpcore', |
||||
version = '4.3.3', |
||||
) |
||||
|
||||
maven_jar( |
||||
name = 'commons-logging', |
||||
bin_sha1 = 'f6f66e966c70a83ffbdb6f17a0919eaf7c8aca7f', |
||||
src_sha1 = '28bb0405fddaf04f15058fbfbe01fe2780d7d3b6', |
||||
group = 'commons-logging', |
||||
artifact = 'commons-logging', |
||||
version = '1.1.3', |
||||
) |
||||
|
||||
maven_jar( |
||||
name = 'slf4j-api', |
||||
bin_sha1 = '0081d61b7f33ebeab314e07de0cc596f8e858d97', |
||||
src_sha1 = '58d38f68d4a867d4552ae27960bb348d7eaa1297', |
||||
group = 'org.slf4j', |
||||
artifact = 'slf4j-api', |
||||
version = '1.7.2', |
||||
) |
||||
|
||||
maven_jar( |
||||
name = 'slf4j-simple', |
||||
bin_sha1 = '760055906d7353ba4f7ce1b8908bc6b2e91f39fa', |
||||
src_sha1 = '09474919128b3a7fcf21a5f9c907f5251f234544', |
||||
group = 'org.slf4j', |
||||
artifact = 'slf4j-simple', |
||||
version = '1.7.2', |
||||
) |
||||
|
||||
maven_jar( |
||||
name = 'servlet-api', |
||||
bin_sha1 = '3cd63d075497751784b2fa84be59432f4905bf7c', |
||||
src_sha1 = 'ab3976d4574c48d22dc1abf6a9e8bd0fdf928223', |
||||
group = 'javax.servlet', |
||||
artifact = 'javax.servlet-api', |
||||
version = '3.1.0', |
||||
) |
||||
|
||||
maven_jar( |
||||
name = 'commons-compress', |
||||
bin_sha1 = 'c7d9b580aff9e9f1998361f16578e63e5c064699', |
||||
src_sha1 = '396b81bdfd0fb617178e1707ef64832215307c78', |
||||
group = 'org.apache.commons', |
||||
artifact = 'commons-compress', |
||||
version = '1.6', |
||||
) |
||||
|
||||
maven_jar( |
||||
name = 'tukaani-xz', |
||||
bin_sha1 = '66db21c8484120cb6a51b5b3ea47b6f383942bec', |
||||
src_sha1 = '6396220725701d767c553902c41120d7bf38e9f5', |
||||
group = 'org.tukaani', |
||||
artifact = 'xz', |
||||
version = '1.3', |
||||
) |
||||
|
||||
maven_jar( |
||||
name = 'args4j', |
||||
bin_sha1 = '139441471327b9cc6d56436cb2a31e60eb6ed2ba', |
||||
src_sha1 = '22631b78cc8f60a6918557e8cbdb33e90f63a77f', |
||||
group = 'args4j', |
||||
artifact = 'args4j', |
||||
version = '2.0.15', |
||||
) |
||||
|
||||
maven_jar( |
||||
name = 'junit', |
||||
bin_sha1 = '4e031bb61df09069aeb2bffb4019e7a5034a4ee0', |
||||
src_sha1 = '28e0ad201304e4a4abf999ca0570b7cffc352c3c', |
||||
group = 'junit', |
||||
artifact = 'junit', |
||||
version = '4.11', |
||||
) |
||||
|
||||
maven_jar( |
||||
name = 'hamcrest-library', |
||||
bin_sha1 = '4785a3c21320980282f9f33d0d1264a69040538f', |
||||
src_sha1 = '047a7ee46628ab7133129cd7cef1e92657bc275e', |
||||
group = 'org.hamcrest', |
||||
artifact = 'hamcrest-library', |
||||
version = '1.3', |
||||
) |
||||
|
||||
maven_jar( |
||||
name = 'hamcrest-core', |
||||
bin_sha1 = '42a25dc3219429f0e5d060061f71acb49bf010a0', |
||||
src_sha1 = '1dc37250fbc78e23a65a67fbbaf71d2e9cbc3c0b', |
||||
group = 'org.hamcrest', |
||||
artifact = 'hamcrest-core', |
||||
version = '1.3', |
||||
) |
@ -0,0 +1,56 @@
|
||||
VERSION = '9.2.13.v20150730' |
||||
GROUP = 'org.eclipse.jetty' |
||||
|
||||
maven_jar( |
||||
name = 'servlet', |
||||
bin_sha1 = '5ad6e38015a97ae9a60b6c2ad744ccfa9cf93a50', |
||||
src_sha1 = '78fbec19321150552d91f9e079c2f2ca33222b01', |
||||
group = GROUP, |
||||
artifact = 'jetty-servlet', |
||||
version = VERSION, |
||||
) |
||||
|
||||
maven_jar( |
||||
name = 'security', |
||||
bin_sha1 = 'cc7c7f27ec4cc279253be1675d9e47e58b995943', |
||||
src_sha1 = '75632ebdf8bd651faafb97106c92496db59e165d', |
||||
group = GROUP, |
||||
artifact = 'jetty-security', |
||||
version = VERSION, |
||||
) |
||||
|
||||
maven_jar( |
||||
name = 'server', |
||||
bin_sha1 = '5be7d1da0a7abffd142de3091d160717c120b6ab', |
||||
src_sha1 = '203e123f83efe2a5b8a9c74854c7897fe3563302', |
||||
group = GROUP, |
||||
artifact = 'jetty-server', |
||||
version = VERSION, |
||||
) |
||||
|
||||
maven_jar( |
||||
name = 'http', |
||||
bin_sha1 = '23a745d9177ef67ef53cc46b9b70c5870082efc2', |
||||
src_sha1 = '5f87f7ff2057cd4b0995bc4fffe17b2aff64c130', |
||||
group = GROUP, |
||||
artifact = 'jetty-http', |
||||
version = VERSION, |
||||
) |
||||
|
||||
maven_jar( |
||||
name = 'io', |
||||
bin_sha1 = '7a351e6a1b63dfd56b6632623f7ca2793ffb67ad', |
||||
src_sha1 = 'bbd61a84b748fc295456e1c5c3070aaf40a68f62', |
||||
group = GROUP, |
||||
artifact = 'jetty-io', |
||||
version = VERSION, |
||||
) |
||||
|
||||
maven_jar( |
||||
name = 'util', |
||||
bin_sha1 = 'c101476360a7cdd0670462de04053507d5e70c97', |
||||
src_sha1 = '15ceecce141971b4e0facb861b3d10120ad6ce03', |
||||
group = GROUP, |
||||
artifact = 'jetty-util', |
||||
version = VERSION, |
||||
) |
@ -0,0 +1,13 @@
|
||||
java_library( |
||||
name = 'jgit-archive', |
||||
srcs = glob( |
||||
['src/**'], |
||||
excludes = ['src/org/eclipse/jgit/archive/FormatActivator.java'], |
||||
), |
||||
resources = glob(['resources/**']), |
||||
provided_deps = [ |
||||
'//org.eclipse.jgit:jgit', |
||||
'//lib:commons-compress', |
||||
], |
||||
visibility = ['PUBLIC'], |
||||
) |
@ -0,0 +1,12 @@
|
||||
java_library( |
||||
name = 'http-apache', |
||||
srcs = glob(['src/**']), |
||||
resources = glob(['resources/**']), |
||||
deps = [ |
||||
'//org.eclipse.jgit:jgit', |
||||
'//lib:commons-logging', |
||||
'//lib:httpcomponents', |
||||
'//lib:httpcore', |
||||
], |
||||
visibility = ['PUBLIC'], |
||||
) |
@ -0,0 +1,10 @@
|
||||
java_library( |
||||
name = 'jgit-servlet', |
||||
srcs = glob(['src/**']), |
||||
resources = glob(['resources/**']), |
||||
provided_deps = [ |
||||
'//org.eclipse.jgit:jgit', |
||||
'//lib:servlet-api', |
||||
], |
||||
visibility = ['PUBLIC'], |
||||
) |
@ -0,0 +1,40 @@
|
||||
TESTS = glob(['tst/**/*.java']) |
||||
|
||||
for t in TESTS: |
||||
n = t[len('tst/'):len(t)-len('.java')].replace('/', '.') |
||||
java_test( |
||||
name = n, |
||||
labels = ['http'], |
||||
srcs = [t], |
||||
deps = [ |
||||
':helpers', |
||||
'//org.eclipse.jgit:jgit', |
||||
'//org.eclipse.jgit.http.apache:http-apache', |
||||
'//org.eclipse.jgit.http.server:jgit-servlet', |
||||
'//org.eclipse.jgit.junit:junit', |
||||
'//org.eclipse.jgit.junit.http:junit-http', |
||||
'//lib:hamcrest-core', |
||||
'//lib:hamcrest-library', |
||||
'//lib:junit', |
||||
'//lib:servlet-api', |
||||
'//lib/jetty:http', |
||||
'//lib/jetty:io', |
||||
'//lib/jetty:server', |
||||
'//lib/jetty:servlet', |
||||
'//lib/jetty:security', |
||||
'//lib/jetty:util', |
||||
], |
||||
source_under_test = ['//org.eclipse.jgit.http.server:jgit-servlet'], |
||||
) |
||||
|
||||
java_library( |
||||
name = 'helpers', |
||||
srcs = glob(['src/**/*.java']), |
||||
deps = [ |
||||
'//org.eclipse.jgit:jgit', |
||||
'//org.eclipse.jgit.http.server:jgit-servlet', |
||||
'//org.eclipse.jgit.junit:junit', |
||||
'//org.eclipse.jgit.junit.http:junit-http', |
||||
'//lib:junit', |
||||
], |
||||
) |
@ -0,0 +1,18 @@
|
||||
java_library( |
||||
name = 'junit-http', |
||||
srcs = glob(['src/**']), |
||||
resources = glob(['resources/**']), |
||||
provided_deps = [ |
||||
'//org.eclipse.jgit:jgit', |
||||
'//org.eclipse.jgit.http.server:jgit-servlet', |
||||
'//org.eclipse.jgit.junit:junit', |
||||
'//lib:junit', |
||||
'//lib:servlet-api', |
||||
'//lib/jetty:http', |
||||
'//lib/jetty:server', |
||||
'//lib/jetty:servlet', |
||||
'//lib/jetty:security', |
||||
'//lib/jetty:util', |
||||
], |
||||
visibility = ['PUBLIC'], |
||||
) |
@ -0,0 +1,10 @@
|
||||
java_library( |
||||
name = 'junit', |
||||
srcs = glob(['src/**']), |
||||
resources = glob(['resources/**']), |
||||
provided_deps = [ |
||||
'//org.eclipse.jgit:jgit', |
||||
'//lib:junit', |
||||
], |
||||
visibility = ['PUBLIC'], |
||||
) |
@ -0,0 +1,38 @@
|
||||
TESTS = glob(['tst/**/*.java']) |
||||
|
||||
for t in TESTS: |
||||
n = t[len('tst/'):len(t)-len('.java')].replace('/', '.') |
||||
java_test( |
||||
name = n, |
||||
labels = ['pgm'], |
||||
srcs = [t], |
||||
deps = [ |
||||
':helpers', |
||||
'//org.eclipse.jgit:jgit', |
||||
'//org.eclipse.jgit.archive:jgit-archive', |
||||
'//org.eclipse.jgit.junit:junit', |
||||
'//org.eclipse.jgit.pgm:pgm', |
||||
'//lib:hamcrest-core', |
||||
'//lib:hamcrest-library', |
||||
'//lib:javaewah', |
||||
'//lib:junit', |
||||
'//lib:slf4j-api', |
||||
'//lib:slf4j-simple', |
||||
'//lib:commons-compress', |
||||
'//lib:tukaani-xz', |
||||
], |
||||
source_under_test = ['//org.eclipse.jgit.pgm:pgm'], |
||||
vm_args = ['-Xmx256m', '-Dfile.encoding=UTF-8'], |
||||
) |
||||
|
||||
java_library( |
||||
name = 'helpers', |
||||
srcs = glob(['src/**/*.java']), |
||||
deps = [ |
||||
'//org.eclipse.jgit:jgit', |
||||
'//org.eclipse.jgit.pgm:pgm', |
||||
'//org.eclipse.jgit.junit:junit', |
||||
'//lib:args4j', |
||||
'//lib:junit', |
||||
], |
||||
) |
@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> |
||||
<launchConfiguration type="org.eclipse.jdt.junit.launchconfig"> |
||||
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS"> |
||||
<listEntry value="/org.eclipse.jgit.pgm.test/tst"/> |
||||
</listAttribute> |
||||
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES"> |
||||
<listEntry value="2"/> |
||||
</listAttribute> |
||||
<booleanAttribute key="org.eclipse.debug.core.appendEnvironmentVariables" value="true"/> |
||||
<mapAttribute key="org.eclipse.debug.core.environmentVariables"> |
||||
<mapEntry key="LANG" value="de_DE.UTF-8"/> |
||||
</mapAttribute> |
||||
<listAttribute key="org.eclipse.debug.ui.favoriteGroups"> |
||||
<listEntry value="org.eclipse.debug.ui.launchGroup.debug"/> |
||||
<listEntry value="org.eclipse.debug.ui.launchGroup.run"/> |
||||
</listAttribute> |
||||
<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value="=org.eclipse.jgit.pgm.test/tst"/> |
||||
<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/> |
||||
<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/> |
||||
<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit4"/> |
||||
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_START_ON_FIRST_THREAD" value="true"/> |
||||
<listAttribute key="org.eclipse.jdt.launching.CLASSPATH"> |
||||
<listEntry value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <runtimeClasspathEntry containerPath="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7" path="1" type="4"/> "/> |
||||
<listEntry value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <runtimeClasspathEntry id="org.eclipse.jdt.launching.classpathentry.defaultClasspath"> <memento exportedEntriesOnly="false" project="org.eclipse.jgit.pgm.test"/> </runtimeClasspathEntry> "/> |
||||
</listAttribute> |
||||
<booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="false"/> |
||||
<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> |
||||
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value=""/> |
||||
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.eclipse.jgit.pgm.test"/> |
||||
</launchConfiguration> |
@ -0,0 +1,100 @@
|
||||
/* |
||||
* Copyright (C) 2015, Andrey Loskutov <loskutov@gmx.de> |
||||
* 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.pgm; |
||||
|
||||
import static org.junit.Assert.assertEquals; |
||||
|
||||
import org.eclipse.jgit.lib.CLIRepositoryTestCase; |
||||
import org.junit.Test; |
||||
|
||||
public class CommitTest extends CLIRepositoryTestCase { |
||||
|
||||
@Test |
||||
public void testCommitPath() throws Exception { |
||||
writeTrashFile("a", "a"); |
||||
writeTrashFile("b", "a"); |
||||
String result = toString(execute("git add a")); |
||||
assertEquals("", result); |
||||
|
||||
result = toString(execute("git status -- a")); |
||||
assertEquals(toString("On branch master", "Changes to be committed:", |
||||
"new file: a"), result); |
||||
|
||||
result = toString(execute("git status -- b")); |
||||
assertEquals(toString("On branch master", "Untracked files:", "b"), |
||||
result); |
||||
|
||||
result = toString(execute("git commit a -m 'added a'")); |
||||
assertEquals( |
||||
"[master 8cb3ef7e5171aaee1792df6302a5a0cd30425f7a] added a", |
||||
result); |
||||
|
||||
result = toString(execute("git status -- a")); |
||||
assertEquals("On branch master", result); |
||||
|
||||
result = toString(execute("git status -- b")); |
||||
assertEquals(toString("On branch master", "Untracked files:", "b"), |
||||
result); |
||||
} |
||||
|
||||
@Test |
||||
public void testCommitAll() throws Exception { |
||||
writeTrashFile("a", "a"); |
||||
writeTrashFile("b", "a"); |
||||
String result = toString(execute("git add a b")); |
||||
assertEquals("", result); |
||||
|
||||
result = toString(execute("git status -- a b")); |
||||
assertEquals(toString("On branch master", "Changes to be committed:", |
||||
"new file: a", "new file: b"), result); |
||||
|
||||
result = toString(execute("git commit -m 'added a b'")); |
||||
assertEquals( |
||||
"[master 3c93fa8e3a28ee26690498be78016edcb3a38c73] added a b", |
||||
result); |
||||
|
||||
result = toString(execute("git status -- a b")); |
||||
assertEquals("On branch master", result); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,70 @@
|
||||
include_defs('//tools/git.defs') |
||||
|
||||
java_library( |
||||
name = 'pgm', |
||||
srcs = glob(['src/**']), |
||||
resources = glob(['resources/**']), |
||||
deps = [ |
||||
':services', |
||||
'//org.eclipse.jgit:jgit', |
||||
'//org.eclipse.jgit.archive:jgit-archive', |
||||
'//org.eclipse.jgit.http.apache:http-apache', |
||||
'//org.eclipse.jgit.ui:ui', |
||||
'//lib:args4j', |
||||
], |
||||
visibility = ['PUBLIC'], |
||||
) |
||||
|
||||
prebuilt_jar( |
||||
name = 'services', |
||||
binary_jar = ':services__jar', |
||||
) |
||||
|
||||
genrule( |
||||
name = 'services__jar', |
||||
cmd = 'cd $SRCDIR ; zip -qr $OUT .', |
||||
srcs = glob(['META-INF/services/*']), |
||||
out = 'services.jar', |
||||
) |
||||
|
||||
genrule( |
||||
name = 'jgit', |
||||
cmd = ''.join([ |
||||
'mkdir $TMP/META-INF &&', |
||||
'cp $(location :binary_manifest) $TMP/META-INF/MANIFEST.MF &&', |
||||
'cp $(location :jgit_jar) $TMP/jgit.jar &&', |
||||
'cd $TMP && zip $TMP/jgit.jar META-INF/MANIFEST.MF &&', |
||||
'cat $SRCDIR/jgit.sh $TMP/jgit.jar >$OUT &&', |
||||
'chmod a+x $OUT', |
||||
]), |
||||
srcs = ['jgit.sh'], |
||||
out = 'jgit', |
||||
visibility = ['PUBLIC'], |
||||
) |
||||
|
||||
java_binary( |
||||
name = 'jgit_jar', |
||||
deps = [ |
||||
':pgm', |
||||
'//lib:slf4j-simple', |
||||
'//lib:tukaani-xz', |
||||
], |
||||
blacklist = [ |
||||
'META-INF/DEPENDENCIES', |
||||
'META-INF/maven/.*', |
||||
], |
||||
) |
||||
|
||||
genrule( |
||||
name = 'binary_manifest', |
||||
cmd = ';'.join(['echo "%s: %s" >>$OUT' % e for e in [ |
||||
('Manifest-Version', '1.0'), |
||||
('Main-Class', 'org.eclipse.jgit.pgm.Main'), |
||||
('Bundle-Version', git_version()), |
||||
('Implementation-Title', 'JGit Command Line Interface'), |
||||
('Implementation-Vendor', 'Eclipse.org - JGit'), |
||||
('Implementation-Vendor-URL', 'http://www.eclipse.org/jgit/'), |
||||
('Implementation-Vendor-Id', 'org.eclipse.jgit'), |
||||
]] + ['echo >>$OUT']), |
||||
out = 'MANIFEST.MF', |
||||
) |
@ -0,0 +1,145 @@
|
||||
/* |
||||
* Copyright (C) 2015, Google Inc. |
||||
* 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.pgm.debug; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
import org.eclipse.jgit.internal.storage.reftree.RefTree; |
||||
import org.eclipse.jgit.internal.storage.reftree.RefTreeDatabase; |
||||
import org.eclipse.jgit.lib.CommitBuilder; |
||||
import org.eclipse.jgit.lib.ObjectId; |
||||
import org.eclipse.jgit.lib.ObjectInserter; |
||||
import org.eclipse.jgit.lib.ObjectReader; |
||||
import org.eclipse.jgit.lib.PersonIdent; |
||||
import org.eclipse.jgit.lib.Ref; |
||||
import org.eclipse.jgit.lib.RefDatabase; |
||||
import org.eclipse.jgit.lib.RefUpdate; |
||||
import org.eclipse.jgit.pgm.Command; |
||||
import org.eclipse.jgit.pgm.TextBuiltin; |
||||
import org.eclipse.jgit.revwalk.RevWalk; |
||||
|
||||
@Command(usage = "usage_RebuildRefTree") |
||||
class RebuildRefTree extends TextBuiltin { |
||||
private String txnNamespace; |
||||
private String txnCommitted; |
||||
|
||||
@Override |
||||
protected void run() throws Exception { |
||||
try (ObjectReader reader = db.newObjectReader(); |
||||
RevWalk rw = new RevWalk(reader); |
||||
ObjectInserter inserter = db.newObjectInserter()) { |
||||
RefDatabase refDb = db.getRefDatabase(); |
||||
if (refDb instanceof RefTreeDatabase) { |
||||
RefTreeDatabase d = (RefTreeDatabase) refDb; |
||||
refDb = d.getBootstrap(); |
||||
txnNamespace = d.getTxnNamespace(); |
||||
txnCommitted = d.getTxnCommitted(); |
||||
} else { |
||||
RefTreeDatabase d = new RefTreeDatabase(db, refDb); |
||||
txnNamespace = d.getTxnNamespace(); |
||||
txnCommitted = d.getTxnCommitted(); |
||||
} |
||||
|
||||
errw.format("Rebuilding %s from %s", //$NON-NLS-1$
|
||||
txnCommitted, refDb.getClass().getSimpleName()); |
||||
errw.println(); |
||||
errw.flush(); |
||||
|
||||
CommitBuilder b = new CommitBuilder(); |
||||
Ref ref = refDb.exactRef(txnCommitted); |
||||
RefUpdate update = refDb.newUpdate(txnCommitted, true); |
||||
ObjectId oldTreeId; |
||||
|
||||
if (ref != null && ref.getObjectId() != null) { |
||||
ObjectId oldId = ref.getObjectId(); |
||||
update.setExpectedOldObjectId(oldId); |
||||
b.setParentId(oldId); |
||||
oldTreeId = rw.parseCommit(oldId).getTree(); |
||||
} else { |
||||
update.setExpectedOldObjectId(ObjectId.zeroId()); |
||||
oldTreeId = ObjectId.zeroId(); |
||||
} |
||||
|
||||
RefTree tree = rebuild(refDb.getRefs(RefDatabase.ALL)); |
||||
b.setTreeId(tree.writeTree(inserter)); |
||||
b.setAuthor(new PersonIdent(db)); |
||||
b.setCommitter(b.getAuthor()); |
||||
if (b.getTreeId().equals(oldTreeId)) { |
||||
return; |
||||
} |
||||
|
||||
update.setNewObjectId(inserter.insert(b)); |
||||
inserter.flush(); |
||||
|
||||
RefUpdate.Result result = update.update(rw); |
||||
switch (result) { |
||||
case NEW: |
||||
case FAST_FORWARD: |
||||
break; |
||||
default: |
||||
throw die(String.format("%s: %s", update.getName(), result)); //$NON-NLS-1$
|
||||
} |
||||
} |
||||
} |
||||
|
||||
private RefTree rebuild(Map<String, Ref> refMap) { |
||||
RefTree tree = RefTree.newEmptyTree(); |
||||
List<org.eclipse.jgit.internal.storage.reftree.Command> cmds |
||||
= new ArrayList<>(); |
||||
|
||||
for (Ref r : refMap.values()) { |
||||
if (r.getName().equals(txnCommitted) |
||||
|| r.getName().startsWith(txnNamespace)) { |
||||
continue; |
||||
} |
||||
cmds.add(new org.eclipse.jgit.internal.storage.reftree.Command( |
||||
null, |
||||
db.peel(r))); |
||||
} |
||||
tree.apply(cmds); |
||||
return tree; |
||||
} |
||||
} |
@ -0,0 +1,52 @@
|
||||
package org.eclipse.jgit.pgm.opt; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
import org.eclipse.jgit.pgm.internal.CLIText; |
||||
import org.kohsuke.args4j.CmdLineException; |
||||
import org.kohsuke.args4j.CmdLineParser; |
||||
import org.kohsuke.args4j.OptionDef; |
||||
import org.kohsuke.args4j.spi.OptionHandler; |
||||
import org.kohsuke.args4j.spi.Parameters; |
||||
import org.kohsuke.args4j.spi.Setter; |
||||
|
||||
/** |
||||
* Handler which allows to parse option with few values |
||||
* |
||||
* @since 4.2 |
||||
*/ |
||||
public class OptionWithValuesListHandler extends OptionHandler<List<?>> { |
||||
|
||||
/** |
||||
* @param parser |
||||
* @param option |
||||
* @param setter |
||||
*/ |
||||
public OptionWithValuesListHandler(CmdLineParser parser, |
||||
OptionDef option, Setter<List<?>> setter) { |
||||
super(parser, option, setter); |
||||
} |
||||
|
||||
@Override |
||||
public int parseArguments(Parameters params) throws CmdLineException { |
||||
final List<String> list = new ArrayList<>(); |
||||
for (int idx = 0; idx < params.size(); idx++) { |
||||
final String p; |
||||
try { |
||||
p = params.getParameter(idx); |
||||
} catch (CmdLineException cle) { |
||||
break; |
||||
} |
||||
list.add(p); |
||||
} |
||||
setter.addValue(list); |
||||
return list.size(); |
||||
} |
||||
|
||||
@Override |
||||
public String getDefaultMetaVariable() { |
||||
return CLIText.get().metaVar_values; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,95 @@
|
||||
PKG = 'tst/org/eclipse/jgit/' |
||||
HELPERS = glob(['src/**/*.java']) + [PKG + c for c in [ |
||||
'api/AbstractRemoteCommandTest.java', |
||||
'diff/AbstractDiffTestCase.java', |
||||
'internal/storage/file/GcTestCase.java', |
||||
'internal/storage/file/PackIndexTestCase.java', |
||||
'internal/storage/file/XInputStream.java', |
||||
'nls/GermanTranslatedBundle.java', |
||||
'nls/MissingPropertyBundle.java', |
||||
'nls/NoPropertiesBundle.java', |
||||
'nls/NonTranslatedBundle.java', |
||||
'revwalk/RevQueueTestCase.java', |
||||
'revwalk/RevWalkTestCase.java', |
||||
'transport/SpiTransport.java', |
||||
'treewalk/FileTreeIteratorWithTimeControl.java', |
||||
'treewalk/filter/AlwaysCloneTreeFilter.java', |
||||
'test/resources/SampleDataRepositoryTestCase.java', |
||||
'util/CPUTimeStopWatch.java', |
||||
'util/io/Strings.java', |
||||
]] |
||||
|
||||
DATA = [ |
||||
PKG + 'lib/empty.gitindex.dat', |
||||
PKG + 'lib/sorttest.gitindex.dat', |
||||
] |
||||
|
||||
TESTS = glob( |
||||
['tst/**/*.java'], |
||||
excludes = HELPERS + DATA, |
||||
) |
||||
|
||||
DEPS = { |
||||
PKG + 'nls/RootLocaleTest.java': [ |
||||
'//org.eclipse.jgit.pgm:pgm', |
||||
'//org.eclipse.jgit.ui:ui', |
||||
], |
||||
} |
||||
|
||||
for src in TESTS: |
||||
name = src[len('tst/'):len(src)-len('.java')].replace('/', '.') |
||||
labels = [] |
||||
if name.startswith('org.eclipse.jgit.'): |
||||
l = name[len('org.eclipse.jgit.'):] |
||||
if l.startswith('internal.storage.'): |
||||
l = l[len('internal.storage.'):] |
||||
i = l.find('.') |
||||
if i > 0: |
||||
labels.append(l[:i]) |
||||
else: |
||||
labels.append(i) |
||||
if 'lib' not in labels: |
||||
labels.append('lib') |
||||
|
||||
java_test( |
||||
name = name, |
||||
labels = labels, |
||||
srcs = [src], |
||||
deps = [ |
||||
':helpers', |
||||
':tst_rsrc', |
||||
'//org.eclipse.jgit:jgit', |
||||
'//org.eclipse.jgit.junit:junit', |
||||
'//lib:hamcrest-core', |
||||
'//lib:hamcrest-library', |
||||
'//lib:javaewah', |
||||
'//lib:junit', |
||||
'//lib:slf4j-api', |
||||
'//lib:slf4j-simple', |
||||
] + DEPS.get(src, []), |
||||
source_under_test = ['//org.eclipse.jgit:jgit'], |
||||
vm_args = ['-Xmx256m', '-Dfile.encoding=UTF-8'], |
||||
) |
||||
|
||||
java_library( |
||||
name = 'helpers', |
||||
srcs = HELPERS, |
||||
resources = DATA, |
||||
deps = [ |
||||
'//org.eclipse.jgit:jgit', |
||||
'//org.eclipse.jgit.junit:junit', |
||||
'//lib:junit', |
||||
], |
||||
) |
||||
|
||||
prebuilt_jar( |
||||
name = 'tst_rsrc', |
||||
binary_jar = ':tst_rsrc_jar', |
||||
) |
||||
|
||||
genrule( |
||||
name = 'tst_rsrc_jar', |
||||
cmd = 'cd $SRCDIR/tst-rsrc ; zip -qr $OUT .', |
||||
srcs = glob(['tst-rsrc/**']), |
||||
out = 'tst_rsrc.jar', |
||||
) |
@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> |
||||
<launchConfiguration type="org.eclipse.jdt.junit.launchconfig"> |
||||
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS"> |
||||
<listEntry value="/org.eclipse.jgit.test/tst"/> |
||||
</listAttribute> |
||||
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES"> |
||||
<listEntry value="2"/> |
||||
</listAttribute> |
||||
<booleanAttribute key="org.eclipse.debug.core.appendEnvironmentVariables" value="true"/> |
||||
<mapAttribute key="org.eclipse.debug.core.environmentVariables"> |
||||
<mapEntry key="LANG" value="de_DE.UTF-8"/> |
||||
</mapAttribute> |
||||
<listAttribute key="org.eclipse.debug.ui.favoriteGroups"> |
||||
<listEntry value="org.eclipse.debug.ui.launchGroup.debug"/> |
||||
<listEntry value="org.eclipse.debug.ui.launchGroup.run"/> |
||||
</listAttribute> |
||||
<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value="=org.eclipse.jgit.test/tst"/> |
||||
<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/> |
||||
<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/> |
||||
<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit4"/> |
||||
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_START_ON_FIRST_THREAD" value="true"/> |
||||
<listAttribute key="org.eclipse.jdt.launching.CLASSPATH"> |
||||
<listEntry value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <runtimeClasspathEntry containerPath="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6" path="1" type="4"/> "/> |
||||
<listEntry value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <runtimeClasspathEntry id="org.eclipse.jdt.launching.classpathentry.defaultClasspath"> <memento exportedEntriesOnly="false" project="org.eclipse.jgit.test"/> </runtimeClasspathEntry> "/> |
||||
</listAttribute> |
||||
<booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="false"/> |
||||
<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> |
||||
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value=""/> |
||||
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.eclipse.jgit.test"/> |
||||
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Xmx256m"/> |
||||
</launchConfiguration> |
@ -0,0 +1,685 @@
|
||||
/* |
||||
* Copyright (C) 2010, 2013, 2016 Google Inc. |
||||
* 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.internal.storage.reftree; |
||||
|
||||
import static org.eclipse.jgit.lib.Constants.HEAD; |
||||
import static org.eclipse.jgit.lib.Constants.R_HEADS; |
||||
import static org.eclipse.jgit.lib.Constants.R_TAGS; |
||||
import static org.eclipse.jgit.lib.Ref.Storage.LOOSE; |
||||
import static org.eclipse.jgit.lib.Ref.Storage.PACKED; |
||||
import static org.eclipse.jgit.lib.RefDatabase.ALL; |
||||
import static org.eclipse.jgit.transport.ReceiveCommand.Result.LOCK_FAILURE; |
||||
import static org.eclipse.jgit.transport.ReceiveCommand.Result.OK; |
||||
import static org.eclipse.jgit.transport.ReceiveCommand.Result.REJECTED_NONFASTFORWARD; |
||||
import static org.eclipse.jgit.transport.ReceiveCommand.Result.REJECTED_OTHER_REASON; |
||||
import static org.junit.Assert.assertEquals; |
||||
import static org.junit.Assert.assertFalse; |
||||
import static org.junit.Assert.assertNotEquals; |
||||
import static org.junit.Assert.assertNotNull; |
||||
import static org.junit.Assert.assertNull; |
||||
import static org.junit.Assert.assertSame; |
||||
import static org.junit.Assert.assertTrue; |
||||
import static org.junit.Assert.fail; |
||||
|
||||
import java.io.IOException; |
||||
import java.text.MessageFormat; |
||||
import java.util.Arrays; |
||||
import java.util.Collections; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
import org.eclipse.jgit.internal.JGitText; |
||||
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.AnyObjectId; |
||||
import org.eclipse.jgit.lib.BatchRefUpdate; |
||||
import org.eclipse.jgit.lib.CommitBuilder; |
||||
import org.eclipse.jgit.lib.NullProgressMonitor; |
||||
import org.eclipse.jgit.lib.ObjectId; |
||||
import org.eclipse.jgit.lib.ObjectIdRef; |
||||
import org.eclipse.jgit.lib.ObjectInserter; |
||||
import org.eclipse.jgit.lib.ObjectReader; |
||||
import org.eclipse.jgit.lib.Ref; |
||||
import org.eclipse.jgit.lib.RefDatabase; |
||||
import org.eclipse.jgit.lib.RefUpdate; |
||||
import org.eclipse.jgit.lib.SymbolicRef; |
||||
import org.eclipse.jgit.revwalk.RevCommit; |
||||
import org.eclipse.jgit.revwalk.RevTag; |
||||
import org.eclipse.jgit.revwalk.RevWalk; |
||||
import org.eclipse.jgit.transport.ReceiveCommand; |
||||
import org.junit.Before; |
||||
import org.junit.Test; |
||||
|
||||
public class RefTreeDatabaseTest { |
||||
private InMemRefTreeRepo repo; |
||||
private RefTreeDatabase refdb; |
||||
private RefDatabase bootstrap; |
||||
|
||||
private TestRepository<InMemRefTreeRepo> testRepo; |
||||
private RevCommit A; |
||||
private RevCommit B; |
||||
private RevTag v1_0; |
||||
|
||||
@Before |
||||
public void setUp() throws Exception { |
||||
repo = new InMemRefTreeRepo(new DfsRepositoryDescription("test")); |
||||
bootstrap = refdb.getBootstrap(); |
||||
|
||||
testRepo = new TestRepository<>(repo); |
||||
A = testRepo.commit().create(); |
||||
B = testRepo.commit(testRepo.getRevWalk().parseCommit(A)); |
||||
v1_0 = testRepo.tag("v1_0", B); |
||||
testRepo.getRevWalk().parseBody(v1_0); |
||||
} |
||||
|
||||
@Test |
||||
public void testSupportsAtomic() { |
||||
assertTrue(refdb.performsAtomicTransactions()); |
||||
} |
||||
|
||||
@Test |
||||
public void testGetRefs_EmptyDatabase() throws IOException { |
||||
assertTrue("no references", refdb.getRefs(ALL).isEmpty()); |
||||
assertTrue("no references", refdb.getRefs(R_HEADS).isEmpty()); |
||||
assertTrue("no references", refdb.getRefs(R_TAGS).isEmpty()); |
||||
} |
||||
|
||||
@Test |
||||
public void testGetRefs_HeadOnOneBranch() throws IOException { |
||||
symref(HEAD, "refs/heads/master"); |
||||
update("refs/heads/master", A); |
||||
|
||||
Map<String, Ref> all = refdb.getRefs(ALL); |
||||
assertEquals(2, all.size()); |
||||
assertTrue("has HEAD", all.containsKey(HEAD)); |
||||
assertTrue("has master", all.containsKey("refs/heads/master")); |
||||
|
||||
Ref head = all.get(HEAD); |
||||
Ref master = all.get("refs/heads/master"); |
||||
|
||||
assertEquals(HEAD, head.getName()); |
||||
assertTrue(head.isSymbolic()); |
||||
assertSame(LOOSE, head.getStorage()); |
||||
assertSame("uses same ref as target", master, head.getTarget()); |
||||
|
||||
assertEquals("refs/heads/master", master.getName()); |
||||
assertFalse(master.isSymbolic()); |
||||
assertSame(PACKED, master.getStorage()); |
||||
assertEquals(A, master.getObjectId()); |
||||
} |
||||
|
||||
@Test |
||||
public void testGetRefs_DetachedHead() throws IOException { |
||||
update(HEAD, A); |
||||
|
||||
Map<String, Ref> all = refdb.getRefs(ALL); |
||||
assertEquals(1, all.size()); |
||||
assertTrue("has HEAD", all.containsKey(HEAD)); |
||||
|
||||
Ref head = all.get(HEAD); |
||||
assertEquals(HEAD, head.getName()); |
||||
assertFalse(head.isSymbolic()); |
||||
assertSame(PACKED, head.getStorage()); |
||||
assertEquals(A, head.getObjectId()); |
||||
} |
||||
|
||||
@Test |
||||
public void testGetRefs_DeeplyNestedBranch() throws IOException { |
||||
String name = "refs/heads/a/b/c/d/e/f/g/h/i/j/k"; |
||||
update(name, A); |
||||
|
||||
Map<String, Ref> all = refdb.getRefs(ALL); |
||||
assertEquals(1, all.size()); |
||||
|
||||
Ref r = all.get(name); |
||||
assertEquals(name, r.getName()); |
||||
assertFalse(r.isSymbolic()); |
||||
assertSame(PACKED, r.getStorage()); |
||||
assertEquals(A, r.getObjectId()); |
||||
} |
||||
|
||||
@Test |
||||
public void testGetRefs_HeadBranchNotBorn() throws IOException { |
||||
update("refs/heads/A", A); |
||||
update("refs/heads/B", B); |
||||
|
||||
Map<String, Ref> all = refdb.getRefs(ALL); |
||||
assertEquals(2, all.size()); |
||||
assertFalse("no HEAD", all.containsKey(HEAD)); |
||||
|
||||
Ref a = all.get("refs/heads/A"); |
||||
Ref b = all.get("refs/heads/B"); |
||||
|
||||
assertEquals(A, a.getObjectId()); |
||||
assertEquals(B, b.getObjectId()); |
||||
|
||||
assertEquals("refs/heads/A", a.getName()); |
||||
assertEquals("refs/heads/B", b.getName()); |
||||
} |
||||
|
||||
@Test |
||||
public void testGetRefs_HeadsOnly() throws IOException { |
||||
update("refs/heads/A", A); |
||||
update("refs/heads/B", B); |
||||
update("refs/tags/v1.0", v1_0); |
||||
|
||||
Map<String, Ref> heads = refdb.getRefs(R_HEADS); |
||||
assertEquals(2, heads.size()); |
||||
|
||||
Ref a = heads.get("A"); |
||||
Ref b = heads.get("B"); |
||||
|
||||
assertEquals("refs/heads/A", a.getName()); |
||||
assertEquals("refs/heads/B", b.getName()); |
||||
|
||||
assertEquals(A, a.getObjectId()); |
||||
assertEquals(B, b.getObjectId()); |
||||
} |
||||
|
||||
@Test |
||||
public void testGetRefs_TagsOnly() throws IOException { |
||||
update("refs/heads/A", A); |
||||
update("refs/heads/B", B); |
||||
update("refs/tags/v1.0", v1_0); |
||||
|
||||
Map<String, Ref> tags = refdb.getRefs(R_TAGS); |
||||
assertEquals(1, tags.size()); |
||||
|
||||
Ref a = tags.get("v1.0"); |
||||
assertEquals("refs/tags/v1.0", a.getName()); |
||||
assertEquals(v1_0, a.getObjectId()); |
||||
assertTrue(a.isPeeled()); |
||||
assertEquals(v1_0.getObject(), a.getPeeledObjectId()); |
||||
} |
||||
|
||||
@Test |
||||
public void testGetRefs_HeadsSymref() throws IOException { |
||||
symref("refs/heads/other", "refs/heads/master"); |
||||
update("refs/heads/master", A); |
||||
|
||||
Map<String, Ref> heads = refdb.getRefs(R_HEADS); |
||||
assertEquals(2, heads.size()); |
||||
|
||||
Ref master = heads.get("master"); |
||||
Ref other = heads.get("other"); |
||||
|
||||
assertEquals("refs/heads/master", master.getName()); |
||||
assertEquals(A, master.getObjectId()); |
||||
|
||||
assertEquals("refs/heads/other", other.getName()); |
||||
assertEquals(A, other.getObjectId()); |
||||
assertSame(master, other.getTarget()); |
||||
} |
||||
|
||||
@Test |
||||
public void testGetRefs_InvalidPrefixes() throws IOException { |
||||
update("refs/heads/A", A); |
||||
|
||||
assertTrue("empty refs/heads", refdb.getRefs("refs/heads").isEmpty()); |
||||
assertTrue("empty objects", refdb.getRefs("objects").isEmpty()); |
||||
assertTrue("empty objects/", refdb.getRefs("objects/").isEmpty()); |
||||
} |
||||
|
||||
@Test |
||||
public void testGetRefs_DiscoversNew() throws IOException { |
||||
update("refs/heads/master", A); |
||||
Map<String, Ref> orig = refdb.getRefs(ALL); |
||||
|
||||
update("refs/heads/next", B); |
||||
Map<String, Ref> next = refdb.getRefs(ALL); |
||||
|
||||
assertEquals(1, orig.size()); |
||||
assertEquals(2, next.size()); |
||||
|
||||
assertFalse(orig.containsKey("refs/heads/next")); |
||||
assertTrue(next.containsKey("refs/heads/next")); |
||||
|
||||
assertEquals(A, next.get("refs/heads/master").getObjectId()); |
||||
assertEquals(B, next.get("refs/heads/next").getObjectId()); |
||||
} |
||||
|
||||
@Test |
||||
public void testGetRefs_DiscoversModified() throws IOException { |
||||
symref(HEAD, "refs/heads/master"); |
||||
update("refs/heads/master", A); |
||||
|
||||
Map<String, Ref> all = refdb.getRefs(ALL); |
||||
assertEquals(A, all.get(HEAD).getObjectId()); |
||||
|
||||
update("refs/heads/master", B); |
||||
all = refdb.getRefs(ALL); |
||||
assertEquals(B, all.get(HEAD).getObjectId()); |
||||
assertEquals(B, refdb.exactRef(HEAD).getObjectId()); |
||||
} |
||||
|
||||
@Test |
||||
public void testGetRefs_CycleInSymbolicRef() throws IOException { |
||||
symref("refs/1", "refs/2"); |
||||
symref("refs/2", "refs/3"); |
||||
symref("refs/3", "refs/4"); |
||||
symref("refs/4", "refs/5"); |
||||
symref("refs/5", "refs/end"); |
||||
update("refs/end", A); |
||||
|
||||
Map<String, Ref> all = refdb.getRefs(ALL); |
||||
Ref r = all.get("refs/1"); |
||||
assertNotNull("has 1", r); |
||||
|
||||
assertEquals("refs/1", r.getName()); |
||||
assertEquals(A, r.getObjectId()); |
||||
assertTrue(r.isSymbolic()); |
||||
|
||||
r = r.getTarget(); |
||||
assertEquals("refs/2", r.getName()); |
||||
assertEquals(A, r.getObjectId()); |
||||
assertTrue(r.isSymbolic()); |
||||
|
||||
r = r.getTarget(); |
||||
assertEquals("refs/3", r.getName()); |
||||
assertEquals(A, r.getObjectId()); |
||||
assertTrue(r.isSymbolic()); |
||||
|
||||
r = r.getTarget(); |
||||
assertEquals("refs/4", r.getName()); |
||||
assertEquals(A, r.getObjectId()); |
||||
assertTrue(r.isSymbolic()); |
||||
|
||||
r = r.getTarget(); |
||||
assertEquals("refs/5", r.getName()); |
||||
assertEquals(A, r.getObjectId()); |
||||
assertTrue(r.isSymbolic()); |
||||
|
||||
r = r.getTarget(); |
||||
assertEquals("refs/end", r.getName()); |
||||
assertEquals(A, r.getObjectId()); |
||||
assertFalse(r.isSymbolic()); |
||||
|
||||
symref("refs/5", "refs/6"); |
||||
symref("refs/6", "refs/end"); |
||||
all = refdb.getRefs(ALL); |
||||
assertNull("mising 1 due to cycle", all.get("refs/1")); |
||||
assertEquals(A, all.get("refs/2").getObjectId()); |
||||
assertEquals(A, all.get("refs/3").getObjectId()); |
||||
assertEquals(A, all.get("refs/4").getObjectId()); |
||||
assertEquals(A, all.get("refs/5").getObjectId()); |
||||
assertEquals(A, all.get("refs/6").getObjectId()); |
||||
assertEquals(A, all.get("refs/end").getObjectId()); |
||||
} |
||||
|
||||
@Test |
||||
public void testGetRef_NonExistingBranchConfig() throws IOException { |
||||
assertNull("find branch config", refdb.getRef("config")); |
||||
assertNull("find branch config", refdb.getRef("refs/heads/config")); |
||||
} |
||||
|
||||
@Test |
||||
public void testGetRef_FindBranchConfig() throws IOException { |
||||
update("refs/heads/config", A); |
||||
|
||||
for (String t : new String[] { "config", "refs/heads/config" }) { |
||||
Ref r = refdb.getRef(t); |
||||
assertNotNull("find branch config (" + t + ")", r); |
||||
assertEquals("for " + t, "refs/heads/config", r.getName()); |
||||
assertEquals("for " + t, A, r.getObjectId()); |
||||
} |
||||
} |
||||
|
||||
@Test |
||||
public void testFirstExactRef() throws IOException { |
||||
update("refs/heads/A", A); |
||||
update("refs/tags/v1.0", v1_0); |
||||
|
||||
Ref a = refdb.firstExactRef("refs/heads/A", "refs/tags/v1.0"); |
||||
Ref one = refdb.firstExactRef("refs/tags/v1.0", "refs/heads/A"); |
||||
|
||||
assertEquals("refs/heads/A", a.getName()); |
||||
assertEquals("refs/tags/v1.0", one.getName()); |
||||
|
||||
assertEquals(A, a.getObjectId()); |
||||
assertEquals(v1_0, one.getObjectId()); |
||||
} |
||||
|
||||
@Test |
||||
public void testExactRef_DiscoversModified() throws IOException { |
||||
symref(HEAD, "refs/heads/master"); |
||||
update("refs/heads/master", A); |
||||
assertEquals(A, refdb.exactRef(HEAD).getObjectId()); |
||||
|
||||
update("refs/heads/master", B); |
||||
assertEquals(B, refdb.exactRef(HEAD).getObjectId()); |
||||
} |
||||
|
||||
@Test |
||||
public void testIsNameConflicting() throws IOException { |
||||
update("refs/heads/a/b", A); |
||||
update("refs/heads/q", B); |
||||
|
||||
// new references cannot replace an existing container
|
||||
assertTrue(refdb.isNameConflicting("refs")); |
||||
assertTrue(refdb.isNameConflicting("refs/heads")); |
||||
assertTrue(refdb.isNameConflicting("refs/heads/a")); |
||||
|
||||
// existing reference is not conflicting
|
||||
assertFalse(refdb.isNameConflicting("refs/heads/a/b")); |
||||
|
||||
// new references are not conflicting
|
||||
assertFalse(refdb.isNameConflicting("refs/heads/a/d")); |
||||
assertFalse(refdb.isNameConflicting("refs/heads/master")); |
||||
|
||||
// existing reference must not be used as a container
|
||||
assertTrue(refdb.isNameConflicting("refs/heads/a/b/c")); |
||||
assertTrue(refdb.isNameConflicting("refs/heads/q/master")); |
||||
|
||||
// refs/txn/ names always conflict.
|
||||
assertTrue(refdb.isNameConflicting(refdb.getTxnCommitted())); |
||||
assertTrue(refdb.isNameConflicting("refs/txn/foo")); |
||||
} |
||||
|
||||
@Test |
||||
public void testUpdate_RefusesRefsTxnNamespace() throws IOException { |
||||
ObjectId txnId = getTxnCommitted(); |
||||
|
||||
RefUpdate u = refdb.newUpdate("refs/txn/tmp", false); |
||||
u.setNewObjectId(B); |
||||
assertEquals(RefUpdate.Result.LOCK_FAILURE, u.update()); |
||||
assertEquals(txnId, getTxnCommitted()); |
||||
|
||||
ReceiveCommand cmd = command(null, B, "refs/txn/tmp"); |
||||
BatchRefUpdate batch = refdb.newBatchUpdate(); |
||||
batch.addCommand(cmd); |
||||
batch.execute(new RevWalk(repo), NullProgressMonitor.INSTANCE); |
||||
|
||||
assertEquals(REJECTED_OTHER_REASON, cmd.getResult()); |
||||
assertEquals(MessageFormat.format(JGitText.get().invalidRefName, |
||||
"refs/txn/tmp"), cmd.getMessage()); |
||||
assertEquals(txnId, getTxnCommitted()); |
||||
} |
||||
|
||||
@Test |
||||
public void testUpdate_RefusesDotLockInRefName() throws IOException { |
||||
ObjectId txnId = getTxnCommitted(); |
||||
|
||||
RefUpdate u = refdb.newUpdate("refs/heads/pu.lock", false); |
||||
u.setNewObjectId(B); |
||||
assertEquals(RefUpdate.Result.REJECTED, u.update()); |
||||
assertEquals(txnId, getTxnCommitted()); |
||||
|
||||
ReceiveCommand cmd = command(null, B, "refs/heads/pu.lock"); |
||||
BatchRefUpdate batch = refdb.newBatchUpdate(); |
||||
batch.addCommand(cmd); |
||||
batch.execute(new RevWalk(repo), NullProgressMonitor.INSTANCE); |
||||
|
||||
assertEquals(REJECTED_OTHER_REASON, cmd.getResult()); |
||||
assertEquals(JGitText.get().funnyRefname, cmd.getMessage()); |
||||
assertEquals(txnId, getTxnCommitted()); |
||||
} |
||||
|
||||
@Test |
||||
public void testBatchRefUpdate_NonFastForwardAborts() throws IOException { |
||||
update("refs/heads/master", A); |
||||
update("refs/heads/masters", B); |
||||
ObjectId txnId = getTxnCommitted(); |
||||
|
||||
List<ReceiveCommand> commands = Arrays.asList( |
||||
command(A, B, "refs/heads/master"), |
||||
command(B, A, "refs/heads/masters")); |
||||
BatchRefUpdate batchUpdate = refdb.newBatchUpdate(); |
||||
batchUpdate.addCommand(commands); |
||||
batchUpdate.execute(new RevWalk(repo), NullProgressMonitor.INSTANCE); |
||||
assertEquals(txnId, getTxnCommitted()); |
||||
|
||||
assertEquals(REJECTED_NONFASTFORWARD, |
||||
commands.get(1).getResult()); |
||||
assertEquals(REJECTED_OTHER_REASON, |
||||
commands.get(0).getResult()); |
||||
assertEquals(JGitText.get().transactionAborted, |
||||
commands.get(0).getMessage()); |
||||
} |
||||
|
||||
@Test |
||||
public void testBatchRefUpdate_ForceUpdate() throws IOException { |
||||
update("refs/heads/master", A); |
||||
update("refs/heads/masters", B); |
||||
ObjectId txnId = getTxnCommitted(); |
||||
|
||||
List<ReceiveCommand> commands = Arrays.asList( |
||||
command(A, B, "refs/heads/master"), |
||||
command(B, A, "refs/heads/masters")); |
||||
BatchRefUpdate batchUpdate = refdb.newBatchUpdate(); |
||||
batchUpdate.setAllowNonFastForwards(true); |
||||
batchUpdate.addCommand(commands); |
||||
batchUpdate.execute(new RevWalk(repo), NullProgressMonitor.INSTANCE); |
||||
assertNotEquals(txnId, getTxnCommitted()); |
||||
|
||||
Map<String, Ref> refs = refdb.getRefs(ALL); |
||||
assertEquals(OK, commands.get(0).getResult()); |
||||
assertEquals(OK, commands.get(1).getResult()); |
||||
assertEquals( |
||||
"[refs/heads/master, refs/heads/masters]", |
||||
refs.keySet().toString()); |
||||
assertEquals(B.getId(), refs.get("refs/heads/master").getObjectId()); |
||||
assertEquals(A.getId(), refs.get("refs/heads/masters").getObjectId()); |
||||
} |
||||
|
||||
@Test |
||||
public void testBatchRefUpdate_NonFastForwardDoesNotDoExpensiveMergeCheck() |
||||
throws IOException { |
||||
update("refs/heads/master", B); |
||||
ObjectId txnId = getTxnCommitted(); |
||||
|
||||
List<ReceiveCommand> commands = Arrays.asList( |
||||
command(B, A, "refs/heads/master")); |
||||
BatchRefUpdate batchUpdate = refdb.newBatchUpdate(); |
||||
batchUpdate.setAllowNonFastForwards(true); |
||||
batchUpdate.addCommand(commands); |
||||
batchUpdate.execute(new RevWalk(repo) { |
||||
@Override |
||||
public boolean isMergedInto(RevCommit base, RevCommit tip) { |
||||
fail("isMergedInto() should not be called"); |
||||
return false; |
||||
} |
||||
}, NullProgressMonitor.INSTANCE); |
||||
assertNotEquals(txnId, getTxnCommitted()); |
||||
|
||||
Map<String, Ref> refs = refdb.getRefs(ALL); |
||||
assertEquals(OK, commands.get(0).getResult()); |
||||
assertEquals(A.getId(), refs.get("refs/heads/master").getObjectId()); |
||||
} |
||||
|
||||
@Test |
||||
public void testBatchRefUpdate_ConflictCausesAbort() throws IOException { |
||||
update("refs/heads/master", A); |
||||
update("refs/heads/masters", B); |
||||
ObjectId txnId = getTxnCommitted(); |
||||
|
||||
List<ReceiveCommand> commands = Arrays.asList( |
||||
command(A, B, "refs/heads/master"), |
||||
command(null, A, "refs/heads/master/x"), |
||||
command(null, A, "refs/heads")); |
||||
BatchRefUpdate batchUpdate = refdb.newBatchUpdate(); |
||||
batchUpdate.setAllowNonFastForwards(true); |
||||
batchUpdate.addCommand(commands); |
||||
batchUpdate.execute(new RevWalk(repo), NullProgressMonitor.INSTANCE); |
||||
assertEquals(txnId, getTxnCommitted()); |
||||
|
||||
assertEquals(LOCK_FAILURE, commands.get(0).getResult()); |
||||
|
||||
assertEquals(REJECTED_OTHER_REASON, commands.get(1).getResult()); |
||||
assertEquals(JGitText.get().transactionAborted, |
||||
commands.get(1).getMessage()); |
||||
|
||||
assertEquals(REJECTED_OTHER_REASON, commands.get(2).getResult()); |
||||
assertEquals(JGitText.get().transactionAborted, |
||||
commands.get(2).getMessage()); |
||||
} |
||||
|
||||
@Test |
||||
public void testBatchRefUpdate_NoConflictIfDeleted() throws IOException { |
||||
update("refs/heads/master", A); |
||||
update("refs/heads/masters", B); |
||||
ObjectId txnId = getTxnCommitted(); |
||||
|
||||
List<ReceiveCommand> commands = Arrays.asList( |
||||
command(A, B, "refs/heads/master"), |
||||
command(null, A, "refs/heads/masters/x"), |
||||
command(B, null, "refs/heads/masters")); |
||||
BatchRefUpdate batchUpdate = refdb.newBatchUpdate(); |
||||
batchUpdate.setAllowNonFastForwards(true); |
||||
batchUpdate.addCommand(commands); |
||||
batchUpdate.execute(new RevWalk(repo), NullProgressMonitor.INSTANCE); |
||||
assertNotEquals(txnId, getTxnCommitted()); |
||||
|
||||
assertEquals(OK, commands.get(0).getResult()); |
||||
assertEquals(OK, commands.get(1).getResult()); |
||||
assertEquals(OK, commands.get(2).getResult()); |
||||
|
||||
Map<String, Ref> refs = refdb.getRefs(ALL); |
||||
assertEquals( |
||||
"[refs/heads/master, refs/heads/masters/x]", |
||||
refs.keySet().toString()); |
||||
assertEquals(A.getId(), refs.get("refs/heads/masters/x").getObjectId()); |
||||
} |
||||
|
||||
private ObjectId getTxnCommitted() throws IOException { |
||||
Ref r = bootstrap.exactRef(refdb.getTxnCommitted()); |
||||
if (r != null && r.getObjectId() != null) { |
||||
return r.getObjectId(); |
||||
} |
||||
return ObjectId.zeroId(); |
||||
} |
||||
|
||||
private static ReceiveCommand command(AnyObjectId a, AnyObjectId b, |
||||
String name) { |
||||
return new ReceiveCommand( |
||||
a != null ? a.copy() : ObjectId.zeroId(), |
||||
b != null ? b.copy() : ObjectId.zeroId(), |
||||
name); |
||||
} |
||||
|
||||
private void symref(final String name, final String dst) |
||||
throws IOException { |
||||
commit(new Function() { |
||||
@Override |
||||
public boolean apply(ObjectReader reader, RefTree tree) |
||||
throws IOException { |
||||
Ref old = tree.exactRef(reader, name); |
||||
Command n = new Command( |
||||
old, |
||||
new SymbolicRef( |
||||
name, |
||||
new ObjectIdRef.Unpeeled(Ref.Storage.NEW, dst, null))); |
||||
return tree.apply(Collections.singleton(n)); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
private void update(final String name, final ObjectId id) |
||||
throws IOException { |
||||
commit(new Function() { |
||||
@Override |
||||
public boolean apply(ObjectReader reader, RefTree tree) |
||||
throws IOException { |
||||
Ref old = tree.exactRef(reader, name); |
||||
Command n; |
||||
try (RevWalk rw = new RevWalk(repo)) { |
||||
n = new Command(old, Command.toRef(rw, id, name, true)); |
||||
} |
||||
return tree.apply(Collections.singleton(n)); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
interface Function { |
||||
boolean apply(ObjectReader reader, RefTree tree) throws IOException; |
||||
} |
||||
|
||||
private void commit(Function fun) throws IOException { |
||||
try (ObjectReader reader = repo.newObjectReader(); |
||||
ObjectInserter inserter = repo.newObjectInserter(); |
||||
RevWalk rw = new RevWalk(reader)) { |
||||
RefUpdate u = bootstrap.newUpdate(refdb.getTxnCommitted(), false); |
||||
CommitBuilder cb = new CommitBuilder(); |
||||
testRepo.setAuthorAndCommitter(cb); |
||||
|
||||
Ref ref = bootstrap.exactRef(refdb.getTxnCommitted()); |
||||
RefTree tree; |
||||
if (ref != null && ref.getObjectId() != null) { |
||||
tree = RefTree.read(reader, rw.parseTree(ref.getObjectId())); |
||||
cb.setParentId(ref.getObjectId()); |
||||
u.setExpectedOldObjectId(ref.getObjectId()); |
||||
} else { |
||||
tree = RefTree.newEmptyTree(); |
||||
u.setExpectedOldObjectId(ObjectId.zeroId()); |
||||
} |
||||
|
||||
assertTrue(fun.apply(reader, tree)); |
||||
cb.setTreeId(tree.writeTree(inserter)); |
||||
u.setNewObjectId(inserter.insert(cb)); |
||||
inserter.flush(); |
||||
switch (u.update(rw)) { |
||||
case NEW: |
||||
case FAST_FORWARD: |
||||
break; |
||||
default: |
||||
fail("Expected " + u.getName() + " to update"); |
||||
} |
||||
} |
||||
} |
||||
|
||||
private class InMemRefTreeRepo extends InMemoryRepository { |
||||
private final RefTreeDatabase refs; |
||||
|
||||
InMemRefTreeRepo(DfsRepositoryDescription repoDesc) { |
||||
super(repoDesc); |
||||
refs = new RefTreeDatabase(this, super.getRefDatabase(), |
||||
"refs/txn/committed"); |
||||
RefTreeDatabaseTest.this.refdb = refs; |
||||
} |
||||
|
||||
public RefDatabase getRefDatabase() { |
||||
return refs; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,303 @@
|
||||
/* |
||||
* Copyright (C) 2016, Google Inc. |
||||
* 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.internal.storage.reftree; |
||||
|
||||
import static org.eclipse.jgit.lib.Constants.HEAD; |
||||
import static org.eclipse.jgit.lib.Constants.R_HEADS; |
||||
import static org.eclipse.jgit.lib.Constants.R_TAGS; |
||||
import static org.eclipse.jgit.lib.Ref.Storage.LOOSE; |
||||
import static org.eclipse.jgit.lib.Ref.Storage.NEW; |
||||
import static org.eclipse.jgit.transport.ReceiveCommand.Result.LOCK_FAILURE; |
||||
import static org.eclipse.jgit.transport.ReceiveCommand.Result.NOT_ATTEMPTED; |
||||
import static org.eclipse.jgit.transport.ReceiveCommand.Result.REJECTED_OTHER_REASON; |
||||
import static org.junit.Assert.assertEquals; |
||||
import static org.junit.Assert.assertFalse; |
||||
import static org.junit.Assert.assertNotNull; |
||||
import static org.junit.Assert.assertNull; |
||||
import static org.junit.Assert.assertSame; |
||||
import static org.junit.Assert.assertTrue; |
||||
|
||||
import java.io.IOException; |
||||
import java.util.Arrays; |
||||
import java.util.Collections; |
||||
|
||||
import org.eclipse.jgit.errors.MissingObjectException; |
||||
import org.eclipse.jgit.internal.JGitText; |
||||
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.ObjectId; |
||||
import org.eclipse.jgit.lib.ObjectIdRef; |
||||
import org.eclipse.jgit.lib.ObjectInserter; |
||||
import org.eclipse.jgit.lib.ObjectReader; |
||||
import org.eclipse.jgit.lib.Ref; |
||||
import org.eclipse.jgit.lib.SymbolicRef; |
||||
import org.eclipse.jgit.revwalk.RevBlob; |
||||
import org.eclipse.jgit.revwalk.RevTag; |
||||
import org.eclipse.jgit.revwalk.RevWalk; |
||||
import org.eclipse.jgit.transport.ReceiveCommand; |
||||
import org.junit.Before; |
||||
import org.junit.Test; |
||||
|
||||
public class RefTreeTest { |
||||
private static final String R_MASTER = R_HEADS + "master"; |
||||
private InMemoryRepository repo; |
||||
private TestRepository<InMemoryRepository> git; |
||||
|
||||
@Before |
||||
public void setUp() throws IOException { |
||||
repo = new InMemoryRepository(new DfsRepositoryDescription("RefTree")); |
||||
git = new TestRepository<>(repo); |
||||
} |
||||
|
||||
@Test |
||||
public void testEmptyTree() throws IOException { |
||||
RefTree tree = RefTree.newEmptyTree(); |
||||
try (ObjectReader reader = repo.newObjectReader()) { |
||||
assertNull(HEAD, tree.exactRef(reader, HEAD)); |
||||
assertNull("master", tree.exactRef(reader, R_MASTER)); |
||||
} |
||||
} |
||||
|
||||
@Test |
||||
public void testApplyThenReadMaster() throws Exception { |
||||
RefTree tree = RefTree.newEmptyTree(); |
||||
RevBlob id = git.blob("A"); |
||||
Command cmd = new Command(null, ref(R_MASTER, id)); |
||||
assertTrue(tree.apply(Collections.singletonList(cmd))); |
||||
assertSame(NOT_ATTEMPTED, cmd.getResult()); |
||||
|
||||
try (ObjectReader reader = repo.newObjectReader()) { |
||||
Ref m = tree.exactRef(reader, R_MASTER); |
||||
assertNotNull(R_MASTER, m); |
||||
assertEquals(R_MASTER, m.getName()); |
||||
assertEquals(id, m.getObjectId()); |
||||
assertTrue("peeled", m.isPeeled()); |
||||
} |
||||
} |
||||
|
||||
@Test |
||||
public void testUpdateMaster() throws Exception { |
||||
RefTree tree = RefTree.newEmptyTree(); |
||||
RevBlob id1 = git.blob("A"); |
||||
Command cmd1 = new Command(null, ref(R_MASTER, id1)); |
||||
assertTrue(tree.apply(Collections.singletonList(cmd1))); |
||||
assertSame(NOT_ATTEMPTED, cmd1.getResult()); |
||||
|
||||
RevBlob id2 = git.blob("B"); |
||||
Command cmd2 = new Command(ref(R_MASTER, id1), ref(R_MASTER, id2)); |
||||
assertTrue(tree.apply(Collections.singletonList(cmd2))); |
||||
assertSame(NOT_ATTEMPTED, cmd2.getResult()); |
||||
|
||||
try (ObjectReader reader = repo.newObjectReader()) { |
||||
Ref m = tree.exactRef(reader, R_MASTER); |
||||
assertNotNull(R_MASTER, m); |
||||
assertEquals(R_MASTER, m.getName()); |
||||
assertEquals(id2, m.getObjectId()); |
||||
assertTrue("peeled", m.isPeeled()); |
||||
} |
||||
} |
||||
|
||||
@Test |
||||
public void testHeadSymref() throws Exception { |
||||
RefTree tree = RefTree.newEmptyTree(); |
||||
RevBlob id = git.blob("A"); |
||||
Command cmd1 = new Command(null, ref(R_MASTER, id)); |
||||
Command cmd2 = new Command(null, symref(HEAD, R_MASTER)); |
||||
assertTrue(tree.apply(Arrays.asList(new Command[] { cmd1, cmd2 }))); |
||||
assertSame(NOT_ATTEMPTED, cmd1.getResult()); |
||||
assertSame(NOT_ATTEMPTED, cmd2.getResult()); |
||||
|
||||
try (ObjectReader reader = repo.newObjectReader()) { |
||||
Ref m = tree.exactRef(reader, HEAD); |
||||
assertNotNull(HEAD, m); |
||||
assertEquals(HEAD, m.getName()); |
||||
assertTrue("symbolic", m.isSymbolic()); |
||||
assertNotNull(m.getTarget()); |
||||
assertEquals(R_MASTER, m.getTarget().getName()); |
||||
assertEquals(id, m.getTarget().getObjectId()); |
||||
} |
||||
|
||||
// Writing flushes some buffers, re-read from blob.
|
||||
ObjectId newId = write(tree); |
||||
try (ObjectReader reader = repo.newObjectReader(); |
||||
RevWalk rw = new RevWalk(reader)) { |
||||
tree = RefTree.read(reader, rw.parseTree(newId)); |
||||
Ref m = tree.exactRef(reader, HEAD); |
||||
assertEquals(R_MASTER, m.getTarget().getName()); |
||||
} |
||||
} |
||||
|
||||
@Test |
||||
public void testTagIsPeeled() throws Exception { |
||||
String name = "v1.0"; |
||||
RefTree tree = RefTree.newEmptyTree(); |
||||
RevBlob id = git.blob("A"); |
||||
RevTag tag = git.tag(name, id); |
||||
|
||||
String ref = R_TAGS + name; |
||||
Command cmd = create(ref, tag); |
||||
assertTrue(tree.apply(Collections.singletonList(cmd))); |
||||
assertSame(NOT_ATTEMPTED, cmd.getResult()); |
||||
|
||||
try (ObjectReader reader = repo.newObjectReader()) { |
||||
Ref m = tree.exactRef(reader, ref); |
||||
assertNotNull(ref, m); |
||||
assertEquals(ref, m.getName()); |
||||
assertEquals(tag, m.getObjectId()); |
||||
assertTrue("peeled", m.isPeeled()); |
||||
assertEquals(id, m.getPeeledObjectId()); |
||||
} |
||||
} |
||||
|
||||
@Test |
||||
public void testApplyAlreadyExists() throws Exception { |
||||
RefTree tree = RefTree.newEmptyTree(); |
||||
RevBlob a = git.blob("A"); |
||||
Command cmd = new Command(null, ref(R_MASTER, a)); |
||||
assertTrue(tree.apply(Collections.singletonList(cmd))); |
||||
ObjectId treeId = write(tree); |
||||
|
||||
RevBlob b = git.blob("B"); |
||||
Command cmd1 = create(R_MASTER, b); |
||||
Command cmd2 = create(R_MASTER, b); |
||||
assertFalse(tree.apply(Arrays.asList(new Command[] { cmd1, cmd2 }))); |
||||
assertSame(LOCK_FAILURE, cmd1.getResult()); |
||||
assertSame(REJECTED_OTHER_REASON, cmd2.getResult()); |
||||
assertEquals(JGitText.get().transactionAborted, cmd2.getMessage()); |
||||
assertEquals(treeId, write(tree)); |
||||
} |
||||
|
||||
@Test |
||||
public void testApplyWrongOldId() throws Exception { |
||||
RefTree tree = RefTree.newEmptyTree(); |
||||
RevBlob a = git.blob("A"); |
||||
Command cmd = new Command(null, ref(R_MASTER, a)); |
||||
assertTrue(tree.apply(Collections.singletonList(cmd))); |
||||
ObjectId treeId = write(tree); |
||||
|
||||
RevBlob b = git.blob("B"); |
||||
RevBlob c = git.blob("C"); |
||||
Command cmd1 = update(R_MASTER, b, c); |
||||
Command cmd2 = create(R_MASTER, b); |
||||
assertFalse(tree.apply(Arrays.asList(new Command[] { cmd1, cmd2 }))); |
||||
assertSame(LOCK_FAILURE, cmd1.getResult()); |
||||
assertSame(REJECTED_OTHER_REASON, cmd2.getResult()); |
||||
assertEquals(JGitText.get().transactionAborted, cmd2.getMessage()); |
||||
assertEquals(treeId, write(tree)); |
||||
} |
||||
|
||||
@Test |
||||
public void testApplyWrongOldIdButAlreadyCurrentIsNoOp() throws Exception { |
||||
RefTree tree = RefTree.newEmptyTree(); |
||||
RevBlob a = git.blob("A"); |
||||
Command cmd = new Command(null, ref(R_MASTER, a)); |
||||
assertTrue(tree.apply(Collections.singletonList(cmd))); |
||||
ObjectId treeId = write(tree); |
||||
|
||||
RevBlob b = git.blob("B"); |
||||
cmd = update(R_MASTER, b, a); |
||||
assertTrue(tree.apply(Collections.singletonList(cmd))); |
||||
assertEquals(treeId, write(tree)); |
||||
} |
||||
|
||||
@Test |
||||
public void testApplyCannotCreateSubdirectory() throws Exception { |
||||
RefTree tree = RefTree.newEmptyTree(); |
||||
RevBlob a = git.blob("A"); |
||||
Command cmd = new Command(null, ref(R_MASTER, a)); |
||||
assertTrue(tree.apply(Collections.singletonList(cmd))); |
||||
ObjectId treeId = write(tree); |
||||
|
||||
RevBlob b = git.blob("B"); |
||||
Command cmd1 = create(R_MASTER + "/fail", b); |
||||
assertFalse(tree.apply(Collections.singletonList(cmd1))); |
||||
assertSame(LOCK_FAILURE, cmd1.getResult()); |
||||
assertEquals(treeId, write(tree)); |
||||
} |
||||
|
||||
@Test |
||||
public void testApplyCannotCreateParentRef() throws Exception { |
||||
RefTree tree = RefTree.newEmptyTree(); |
||||
RevBlob a = git.blob("A"); |
||||
Command cmd = new Command(null, ref(R_MASTER, a)); |
||||
assertTrue(tree.apply(Collections.singletonList(cmd))); |
||||
ObjectId treeId = write(tree); |
||||
|
||||
RevBlob b = git.blob("B"); |
||||
Command cmd1 = create("refs/heads", b); |
||||
assertFalse(tree.apply(Collections.singletonList(cmd1))); |
||||
assertSame(LOCK_FAILURE, cmd1.getResult()); |
||||
assertEquals(treeId, write(tree)); |
||||
} |
||||
|
||||
private static Ref ref(String name, ObjectId id) { |
||||
return new ObjectIdRef.PeeledNonTag(LOOSE, name, id); |
||||
} |
||||
|
||||
private static Ref symref(String name, String dest) { |
||||
Ref d = new ObjectIdRef.PeeledNonTag(NEW, dest, null); |
||||
return new SymbolicRef(name, d); |
||||
} |
||||
|
||||
private Command create(String name, ObjectId id) |
||||
throws MissingObjectException, IOException { |
||||
return update(name, ObjectId.zeroId(), id); |
||||
} |
||||
|
||||
private Command update(String name, ObjectId oldId, ObjectId newId) |
||||
throws MissingObjectException, IOException { |
||||
try (RevWalk rw = new RevWalk(repo)) { |
||||
return new Command(rw, new ReceiveCommand(oldId, newId, name)); |
||||
} |
||||
} |
||||
|
||||
private ObjectId write(RefTree tree) throws IOException { |
||||
try (ObjectInserter ins = repo.newObjectInserter()) { |
||||
ObjectId id = tree.writeTree(ins); |
||||
ins.flush(); |
||||
return id; |
||||
} |
||||
} |
||||
} |
File diff suppressed because it is too large
Load Diff
@ -1,319 +0,0 @@
|
||||
/* |
||||
* Copyright (C) 2008, Robin Rosenberg <robin.rosenberg@dewire.com> |
||||
* Copyright (C) 2006-2008, Shawn O. Pearce <spearce@spearce.org> |
||||
* 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.lib; |
||||
|
||||
import static org.junit.Assert.assertEquals; |
||||
import static org.junit.Assert.assertFalse; |
||||
import static org.junit.Assert.assertNotNull; |
||||
import static org.junit.Assert.assertSame; |
||||
import static org.junit.Assert.assertTrue; |
||||
|
||||
import java.io.IOException; |
||||
import java.io.UnsupportedEncodingException; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
import org.eclipse.jgit.test.resources.SampleDataRepositoryTestCase; |
||||
import org.junit.Test; |
||||
|
||||
@SuppressWarnings("deprecation") |
||||
public class T0002_TreeTest extends SampleDataRepositoryTestCase { |
||||
private static final ObjectId SOME_FAKE_ID = ObjectId.fromString( |
||||
"0123456789abcdef0123456789abcdef01234567"); |
||||
|
||||
private static int compareNamesUsingSpecialCompare(String a, String b) |
||||
throws UnsupportedEncodingException { |
||||
char lasta = '\0'; |
||||
byte[] abytes; |
||||
if (a.length() > 0 && a.charAt(a.length()-1) == '/') { |
||||
lasta = '/'; |
||||
a = a.substring(0, a.length() - 1); |
||||
} |
||||
abytes = a.getBytes("ISO-8859-1"); |
||||
char lastb = '\0'; |
||||
byte[] bbytes; |
||||
if (b.length() > 0 && b.charAt(b.length()-1) == '/') { |
||||
lastb = '/'; |
||||
b = b.substring(0, b.length() - 1); |
||||
} |
||||
bbytes = b.getBytes("ISO-8859-1"); |
||||
return Tree.compareNames(abytes, bbytes, lasta, lastb); |
||||
} |
||||
|
||||
@Test |
||||
public void test000_sort_01() throws UnsupportedEncodingException { |
||||
assertEquals(0, compareNamesUsingSpecialCompare("a","a")); |
||||
} |
||||
|
||||
@Test |
||||
public void test000_sort_02() throws UnsupportedEncodingException { |
||||
assertEquals(-1, compareNamesUsingSpecialCompare("a","b")); |
||||
assertEquals(1, compareNamesUsingSpecialCompare("b","a")); |
||||
} |
||||
|
||||
@Test |
||||
public void test000_sort_03() throws UnsupportedEncodingException { |
||||
assertEquals(1, compareNamesUsingSpecialCompare("a:","a")); |
||||
assertEquals(1, compareNamesUsingSpecialCompare("a/","a")); |
||||
assertEquals(-1, compareNamesUsingSpecialCompare("a","a/")); |
||||
assertEquals(-1, compareNamesUsingSpecialCompare("a","a:")); |
||||
assertEquals(1, compareNamesUsingSpecialCompare("a:","a/")); |
||||
assertEquals(-1, compareNamesUsingSpecialCompare("a/","a:")); |
||||
} |
||||
|
||||
@Test |
||||
public void test000_sort_04() throws UnsupportedEncodingException { |
||||
assertEquals(-1, compareNamesUsingSpecialCompare("a.a","a/a")); |
||||
assertEquals(1, compareNamesUsingSpecialCompare("a/a","a.a")); |
||||
} |
||||
|
||||
@Test |
||||
public void test000_sort_05() throws UnsupportedEncodingException { |
||||
assertEquals(-1, compareNamesUsingSpecialCompare("a.","a/")); |
||||
assertEquals(1, compareNamesUsingSpecialCompare("a/","a.")); |
||||
|
||||
} |
||||
|
||||
@Test |
||||
public void test001_createEmpty() throws IOException { |
||||
final Tree t = new Tree(db); |
||||
assertTrue("isLoaded", t.isLoaded()); |
||||
assertTrue("isModified", t.isModified()); |
||||
assertTrue("no parent", t.getParent() == null); |
||||
assertTrue("isRoot", t.isRoot()); |
||||
assertTrue("no name", t.getName() == null); |
||||
assertTrue("no nameUTF8", t.getNameUTF8() == null); |
||||
assertTrue("has entries array", t.members() != null); |
||||
assertEquals("entries is empty", 0, t.members().length); |
||||
assertEquals("full name is empty", "", t.getFullName()); |
||||
assertTrue("no id", t.getId() == null); |
||||
assertTrue("database is r", t.getRepository() == db); |
||||
assertTrue("no foo child", t.findTreeMember("foo") == null); |
||||
assertTrue("no foo child", t.findBlobMember("foo") == null); |
||||
} |
||||
|
||||
@Test |
||||
public void test002_addFile() throws IOException { |
||||
final Tree t = new Tree(db); |
||||
t.setId(SOME_FAKE_ID); |
||||
assertTrue("has id", t.getId() != null); |
||||
assertFalse("not modified", t.isModified()); |
||||
|
||||
final String n = "bob"; |
||||
final FileTreeEntry f = t.addFile(n); |
||||
assertNotNull("have file", f); |
||||
assertEquals("name matches", n, f.getName()); |
||||
assertEquals("name matches", f.getName(), new String(f.getNameUTF8(), |
||||
"UTF-8")); |
||||
assertEquals("full name matches", n, f.getFullName()); |
||||
assertTrue("no id", f.getId() == null); |
||||
assertTrue("is modified", t.isModified()); |
||||
assertTrue("has no id", t.getId() == null); |
||||
assertTrue("found bob", t.findBlobMember(f.getName()) == f); |
||||
|
||||
final TreeEntry[] i = t.members(); |
||||
assertNotNull("members array not null", i); |
||||
assertTrue("iterator is not empty", i != null && i.length > 0); |
||||
assertTrue("iterator returns file", i != null && i[0] == f); |
||||
assertTrue("iterator is empty", i != null && i.length == 1); |
||||
} |
||||
|
||||
@Test |
||||
public void test004_addTree() throws IOException { |
||||
final Tree t = new Tree(db); |
||||
t.setId(SOME_FAKE_ID); |
||||
assertTrue("has id", t.getId() != null); |
||||
assertFalse("not modified", t.isModified()); |
||||
|
||||
final String n = "bob"; |
||||
final Tree f = t.addTree(n); |
||||
assertNotNull("have tree", f); |
||||
assertEquals("name matches", n, f.getName()); |
||||
assertEquals("name matches", f.getName(), new String(f.getNameUTF8(), |
||||
"UTF-8")); |
||||
assertEquals("full name matches", n, f.getFullName()); |
||||
assertTrue("no id", f.getId() == null); |
||||
assertTrue("parent matches", f.getParent() == t); |
||||
assertTrue("repository matches", f.getRepository() == db); |
||||
assertTrue("isLoaded", f.isLoaded()); |
||||
assertFalse("has items", f.members().length > 0); |
||||
assertFalse("is root", f.isRoot()); |
||||
assertTrue("parent is modified", t.isModified()); |
||||
assertTrue("parent has no id", t.getId() == null); |
||||
assertTrue("found bob child", t.findTreeMember(f.getName()) == f); |
||||
|
||||
final TreeEntry[] i = t.members(); |
||||
assertTrue("iterator is not empty", i.length > 0); |
||||
assertTrue("iterator returns file", i[0] == f); |
||||
assertEquals("iterator is empty", 1, i.length); |
||||
} |
||||
|
||||
@Test |
||||
public void test005_addRecursiveFile() throws IOException { |
||||
final Tree t = new Tree(db); |
||||
final FileTreeEntry f = t.addFile("a/b/c"); |
||||
assertNotNull("created f", f); |
||||
assertEquals("c", f.getName()); |
||||
assertEquals("b", f.getParent().getName()); |
||||
assertEquals("a", f.getParent().getParent().getName()); |
||||
assertTrue("t is great-grandparent", t == f.getParent().getParent() |
||||
.getParent()); |
||||
} |
||||
|
||||
@Test |
||||
public void test005_addRecursiveTree() throws IOException { |
||||
final Tree t = new Tree(db); |
||||
final Tree f = t.addTree("a/b/c"); |
||||
assertNotNull("created f", f); |
||||
assertEquals("c", f.getName()); |
||||
assertEquals("b", f.getParent().getName()); |
||||
assertEquals("a", f.getParent().getParent().getName()); |
||||
assertTrue("t is great-grandparent", t == f.getParent().getParent() |
||||
.getParent()); |
||||
} |
||||
|
||||
@Test |
||||
public void test006_addDeepTree() throws IOException { |
||||
final Tree t = new Tree(db); |
||||
|
||||
final Tree e = t.addTree("e"); |
||||
assertNotNull("have e", e); |
||||
assertTrue("e.parent == t", e.getParent() == t); |
||||
final Tree f = t.addTree("f"); |
||||
assertNotNull("have f", f); |
||||
assertTrue("f.parent == t", f.getParent() == t); |
||||
final Tree g = f.addTree("g"); |
||||
assertNotNull("have g", g); |
||||
assertTrue("g.parent == f", g.getParent() == f); |
||||
final Tree h = g.addTree("h"); |
||||
assertNotNull("have h", h); |
||||
assertTrue("h.parent = g", h.getParent() == g); |
||||
|
||||
h.setId(SOME_FAKE_ID); |
||||
assertTrue("h not modified", !h.isModified()); |
||||
g.setId(SOME_FAKE_ID); |
||||
assertTrue("g not modified", !g.isModified()); |
||||
f.setId(SOME_FAKE_ID); |
||||
assertTrue("f not modified", !f.isModified()); |
||||
e.setId(SOME_FAKE_ID); |
||||
assertTrue("e not modified", !e.isModified()); |
||||
t.setId(SOME_FAKE_ID); |
||||
assertTrue("t not modified.", !t.isModified()); |
||||
|
||||
assertEquals("full path of h ok", "f/g/h", h.getFullName()); |
||||
assertTrue("Can find h", t.findTreeMember(h.getFullName()) == h); |
||||
assertTrue("Can't find f/z", t.findBlobMember("f/z") == null); |
||||
assertTrue("Can't find y/z", t.findBlobMember("y/z") == null); |
||||
|
||||
final FileTreeEntry i = h.addFile("i"); |
||||
assertNotNull(i); |
||||
assertEquals("full path of i ok", "f/g/h/i", i.getFullName()); |
||||
assertTrue("Can find i", t.findBlobMember(i.getFullName()) == i); |
||||
assertTrue("h modified", h.isModified()); |
||||
assertTrue("g modified", g.isModified()); |
||||
assertTrue("f modified", f.isModified()); |
||||
assertTrue("e not modified", !e.isModified()); |
||||
assertTrue("t modified", t.isModified()); |
||||
|
||||
assertTrue("h no id", h.getId() == null); |
||||
assertTrue("g no id", g.getId() == null); |
||||
assertTrue("f no id", f.getId() == null); |
||||
assertTrue("e has id", e.getId() != null); |
||||
assertTrue("t no id", t.getId() == null); |
||||
} |
||||
|
||||
@Test |
||||
public void test007_manyFileLookup() throws IOException { |
||||
final Tree t = new Tree(db); |
||||
final List<FileTreeEntry> files = new ArrayList<FileTreeEntry>(26 * 26); |
||||
for (char level1 = 'a'; level1 <= 'z'; level1++) { |
||||
for (char level2 = 'a'; level2 <= 'z'; level2++) { |
||||
final String n = "." + level1 + level2 + "9"; |
||||
final FileTreeEntry f = t.addFile(n); |
||||
assertNotNull("File " + n + " added.", f); |
||||
assertEquals(n, f.getName()); |
||||
files.add(f); |
||||
} |
||||
} |
||||
assertEquals(files.size(), t.memberCount()); |
||||
final TreeEntry[] ents = t.members(); |
||||
assertNotNull(ents); |
||||
assertEquals(files.size(), ents.length); |
||||
for (int k = 0; k < ents.length; k++) { |
||||
assertTrue("File " + files.get(k).getName() |
||||
+ " is at " + k + ".", files.get(k) == ents[k]); |
||||
} |
||||
} |
||||
|
||||
@Test |
||||
public void test008_SubtreeInternalSorting() throws IOException { |
||||
final Tree t = new Tree(db); |
||||
final FileTreeEntry e0 = t.addFile("a-b"); |
||||
final FileTreeEntry e1 = t.addFile("a-"); |
||||
final FileTreeEntry e2 = t.addFile("a=b"); |
||||
final Tree e3 = t.addTree("a"); |
||||
final FileTreeEntry e4 = t.addFile("a="); |
||||
|
||||
final TreeEntry[] ents = t.members(); |
||||
assertSame(e1, ents[0]); |
||||
assertSame(e0, ents[1]); |
||||
assertSame(e3, ents[2]); |
||||
assertSame(e4, ents[3]); |
||||
assertSame(e2, ents[4]); |
||||
} |
||||
|
||||
@Test |
||||
public void test009_SymlinkAndGitlink() throws IOException { |
||||
final Tree symlinkTree = mapTree("symlink"); |
||||
assertTrue("Symlink entry exists", symlinkTree.existsBlob("symlink.txt")); |
||||
final Tree gitlinkTree = mapTree("gitlink"); |
||||
assertTrue("Gitlink entry exists", gitlinkTree.existsBlob("submodule")); |
||||
} |
||||
|
||||
private Tree mapTree(String name) throws IOException { |
||||
ObjectId id = db.resolve(name + "^{tree}"); |
||||
return new Tree(db, id, db.open(id).getCachedBytes()); |
||||
} |
||||
} |
@ -0,0 +1,118 @@
|
||||
/* |
||||
* Copyright (C) 2016, Google Inc. |
||||
* 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.util; |
||||
|
||||
import static org.eclipse.jgit.util.Paths.compare; |
||||
import static org.eclipse.jgit.util.Paths.compareSameName; |
||||
import static org.junit.Assert.assertEquals; |
||||
import static org.junit.Assert.assertNull; |
||||
|
||||
import org.eclipse.jgit.lib.Constants; |
||||
import org.eclipse.jgit.lib.FileMode; |
||||
import org.junit.Test; |
||||
|
||||
public class PathsTest { |
||||
@Test |
||||
public void testStripTrailingSeparator() { |
||||
assertNull(Paths.stripTrailingSeparator(null)); |
||||
assertEquals("", Paths.stripTrailingSeparator("")); |
||||
assertEquals("a", Paths.stripTrailingSeparator("a")); |
||||
assertEquals("a/boo", Paths.stripTrailingSeparator("a/boo")); |
||||
assertEquals("a/boo", Paths.stripTrailingSeparator("a/boo/")); |
||||
assertEquals("a/boo", Paths.stripTrailingSeparator("a/boo//")); |
||||
assertEquals("a/boo", Paths.stripTrailingSeparator("a/boo///")); |
||||
} |
||||
|
||||
@Test |
||||
public void testPathCompare() { |
||||
byte[] a = Constants.encode("afoo/bar.c"); |
||||
byte[] b = Constants.encode("bfoo/bar.c"); |
||||
|
||||
assertEquals(0, compare(a, 1, a.length, 0, b, 1, b.length, 0)); |
||||
assertEquals(-1, compare(a, 0, a.length, 0, b, 0, b.length, 0)); |
||||
assertEquals(1, compare(b, 0, b.length, 0, a, 0, a.length, 0)); |
||||
|
||||
a = Constants.encode("a"); |
||||
b = Constants.encode("aa"); |
||||
assertEquals(-97, compare(a, 0, a.length, 0, b, 0, b.length, 0)); |
||||
assertEquals(0, compare(a, 0, a.length, 0, b, 0, 1, 0)); |
||||
assertEquals(0, compare(a, 0, a.length, 0, b, 1, 2, 0)); |
||||
assertEquals(0, compareSameName(a, 0, a.length, b, 1, b.length, 0)); |
||||
assertEquals(0, compareSameName(a, 0, a.length, b, 0, 1, 0)); |
||||
assertEquals(-50, compareSameName(a, 0, a.length, b, 0, b.length, 0)); |
||||
assertEquals(97, compareSameName(b, 0, b.length, a, 0, a.length, 0)); |
||||
|
||||
a = Constants.encode("a"); |
||||
b = Constants.encode("a"); |
||||
assertEquals(0, compare( |
||||
a, 0, a.length, FileMode.TREE.getBits(), |
||||
b, 0, b.length, FileMode.TREE.getBits())); |
||||
assertEquals(0, compare( |
||||
a, 0, a.length, FileMode.REGULAR_FILE.getBits(), |
||||
b, 0, b.length, FileMode.REGULAR_FILE.getBits())); |
||||
assertEquals(-47, compare( |
||||
a, 0, a.length, FileMode.REGULAR_FILE.getBits(), |
||||
b, 0, b.length, FileMode.TREE.getBits())); |
||||
assertEquals(47, compare( |
||||
a, 0, a.length, FileMode.TREE.getBits(), |
||||
b, 0, b.length, FileMode.REGULAR_FILE.getBits())); |
||||
|
||||
assertEquals(0, compareSameName( |
||||
a, 0, a.length, |
||||
b, 0, b.length, FileMode.TREE.getBits())); |
||||
assertEquals(0, compareSameName( |
||||
a, 0, a.length, |
||||
b, 0, b.length, FileMode.REGULAR_FILE.getBits())); |
||||
|
||||
a = Constants.encode("a.c"); |
||||
b = Constants.encode("a"); |
||||
byte[] c = Constants.encode("a0c"); |
||||
assertEquals(-1, compare( |
||||
a, 0, a.length, FileMode.REGULAR_FILE.getBits(), |
||||
b, 0, b.length, FileMode.TREE.getBits())); |
||||
assertEquals(-1, compare( |
||||
b, 0, b.length, FileMode.TREE.getBits(), |
||||
c, 0, c.length, FileMode.REGULAR_FILE.getBits())); |
||||
} |
||||
} |
@ -0,0 +1,7 @@
|
||||
java_library( |
||||
name = 'ui', |
||||
srcs = glob(['src/**']), |
||||
resources = glob(['resources/**']), |
||||
deps = ['//org.eclipse.jgit:jgit'], |
||||
visibility = ['PUBLIC'], |
||||
) |
@ -0,0 +1,20 @@
|
||||
SRCS = glob(['src/**']) |
||||
RESOURCES = glob(['resources/**']) |
||||
|
||||
java_library( |
||||
name = 'jgit', |
||||
srcs = SRCS, |
||||
resources = RESOURCES, |
||||
deps = [ |
||||
'//lib:javaewah', |
||||
'//lib:jsch', |
||||
'//lib:httpcomponents', |
||||
'//lib:slf4j-api', |
||||
], |
||||
visibility = ['PUBLIC'], |
||||
) |
||||
|
||||
java_sources( |
||||
name = 'jgit_src', |
||||
srcs = SRCS + RESOURCES, |
||||
) |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue