diff options
author | Matthias Sohn | 2022-07-06 15:29:23 +0000 |
---|---|---|
committer | Matthias Sohn | 2022-07-06 17:07:45 +0000 |
commit | 3fc0ec18228d392aecf5d15198e001815726b5d5 (patch) | |
tree | eec583d62bdde6f49101024e5f20878f90bde5cd | |
parent | c6a64ecae7ea5519bb6460b38d7ec65a83dc6303 (diff) | |
parent | f6935d8cd2e00d5923917ff869354e443da66014 (diff) | |
download | jgit-next.tar.gz jgit-next.tar.xz jgit-next.zip |
Merge branch 'master' into nextnext
* master: (193 commits)
Add aarch64 environment to target platform configuration
JGit blame very slow for large merge commits that rename files
UploadPack: don't prematurely terminate timer in case of error
Do not create reflog for remote tracking branches during clone
UploadPack: do not check reachability of visible SHA1s
Fix warnings about non-externalized string literals
[sshd] Correct signature for RSA keys from an SSH agent
Run tests that checks araxis output only on Linux
Add missing package import javax.management to org.eclipse.jgit
Add 4.25 target platform for Eclipse 2022-09
Suppress API errors raised for new API introduced in 5.13.1
Eclipse 4.24 was released, adapt p2 URL accordingly
Fix DefaultCharset bug pattern flagged by error prone
Use SystemReader#getDefaultCharset to read console input
Annotate the exception with the possible failure reason when Bitmaps are not enabled.
Prepare 5.13.2-SNAPSHOT builds
JGit v5.13.1.202206130422-r
AmazonS3: Add support for AWS API signature version 4
Fix typo in DiffTools#compare javadoc
Update jgit-last-release-version to 6.2.0.202206071550-r
...
Change-Id: I561a0178f6bc512e8ce7d75f1870a044cb051fac
295 files changed, 16694 insertions, 2412 deletions
@@ -3,8 +3,33 @@ build --repository_cache=~/.gerritcodereview/bazel-cache/repository build --experimental_strict_action_env build --action_env=PATH build --disk_cache=~/.gerritcodereview/bazel-cache/cas -build --java_toolchain //tools:error_prone_warnings_toolchain + +# Builds using remote_jdk11, executes using remote_jdk11 or local_jdk +build --java_language_version=11 +build --java_runtime_version=remotejdk_11 +build --tool_java_language_version=11 +build --tool_java_runtime_version=remotejdk_11 + +# Builds and executes on RBE using remotejdk_11 +build:remote --java_language_version=11 +build:remote --java_runtime_version=remotejdk_11 +build:remote --tool_java_language_version=11 +build:remote --tool_java_runtime_version=remotejdk_11 + +# Builds using remote_jdk17, executes using remote_jdk11 or local_jdk +build:java17 --java_language_version=17 +build:java17 --java_runtime_version=remotejdk_17 +build:java17 --tool_java_language_version=17 +build:java17 --tool_java_runtime_version=remotejdk_17 + +# Builds and executes on RBE using remotejdk_17 +build:remote17 --java_language_version=17 +build:remote17 --java_runtime_version=remotejdk_17 +build:remote17 --tool_java_language_version=17 +build:remote17 --tool_java_runtime_version=remotejdk_17 test --build_tests_only test --test_output=errors +import %workspace%/tools/remote-bazelrc + diff --git a/.bazelversion b/.bazelversion index fcdb2e109f..0062ac9718 100644 --- a/.bazelversion +++ b/.bazelversion @@ -1 +1 @@ -4.0.0 +5.0.0 @@ -12,6 +12,7 @@ Roberto Tyley <roberto.tyley@guardian.co.uk> roberto <roberto.tyl Saša Živkov <sasa.zivkov@sap.com> Sasa Zivkov <sasa.zivkov@sap.com> Saša Živkov <sasa.zivkov@sap.com> Saša Živkov <zivkov@gmail.com> Saša Živkov <sasa.zivkov@sap.com> Sasa Zivkov <zivkov@gmail.com> +Sebastian Schuberth <sschuberth@gmail.com> Sebastian Schuberth <sebastian.schuberth@bosch.io> Shawn Pearce <spearce@spearce.org> Shawn O. Pearce <sop@google.com> Shawn Pearce <spearce@spearce.org> Shawn Pearce <sop@google.com> Shawn Pearce <spearce@spearce.org> Shawn O. Pearce <spearce@spearce.org> diff --git a/DEPENDENCIES b/DEPENDENCIES index ebbe4805aa..be7ab17cb4 100644 --- a/DEPENDENCIES +++ b/DEPENDENCIES @@ -1,69 +1,70 @@ maven/mavencentral/args4j/args4j/2.33, MIT, approved, CQ11068 -maven/mavencentral/com.google.code.gson/gson/2.8.7, Apache-2.0, approved, CQ23496 -maven/mavencentral/com.googlecode.javaewah/JavaEWAH/1.1.12, Apache-2.0, approved, CQ11658 +maven/mavencentral/com.google.code.gson/gson/2.8.9, Apache-2.0, approved, CQ23496 +maven/mavencentral/com.googlecode.javaewah/JavaEWAH/1.1.13, Apache-2.0, approved, CQ11658 maven/mavencentral/com.jcraft/jsch/0.1.55, BSD-3-Clause, approved, CQ19435 -maven/mavencentral/com.jcraft/jzlib/1.1.1, BSD-2-Clause, approved, CQ6218 +maven/mavencentral/com.jcraft/jzlib/1.1.3, BSD-2-Clause, approved, CQ6218 maven/mavencentral/commons-codec/commons-codec/1.11, Apache-2.0 AND BSD-3-Clause, approved, CQ15971 maven/mavencentral/commons-logging/commons-logging/1.2, Apache-2.0, approved, CQ10162 -maven/mavencentral/javax.servlet/javax.servlet-api/3.1.0, Apache-2.0 AND (CDDL-1.1 OR GPL-2.0 WITH Classpath-exception-2.0), approved, CQ7248 -maven/mavencentral/junit/junit/4.13, , approved, CQ22796 -maven/mavencentral/log4j/log4j/1.2.15, Apache-2.0, approved, CQ7837 +maven/mavencentral/javax.servlet/javax.servlet-api/4.0.0, (CDDL-1.1 OR GPL-2.0-only WITH Classpath-exception-2.0) AND Apache-2.0, approved, CQ16125 +maven/mavencentral/junit/junit/4.13.2, EPL-2.0, approved, CQ23636 maven/mavencentral/net.bytebuddy/byte-buddy-agent/1.9.0, Apache-2.0, approved, clearlydefined maven/mavencentral/net.bytebuddy/byte-buddy/1.9.0, Apache-2.0, approved, clearlydefined maven/mavencentral/net.i2p.crypto/eddsa/0.3.0, CC0-1.0, approved, CQ22537 +maven/mavencentral/net.java.dev.jna/jna-platform/5.8.0, Apache-2.0 OR LGPL-2.1-or-later, approved, CQ23218 +maven/mavencentral/net.java.dev.jna/jna/5.8.0, Apache-2.0 OR LGPL-2.1-or-later, approved, CQ23217 maven/mavencentral/net.sf.jopt-simple/jopt-simple/4.6, MIT, approved, clearlydefined -maven/mavencentral/org.apache.ant/ant-launcher/1.10.10, Apache-2.0 AND W3C AND LicenseRef-Public-Domain, approved, CQ15560 -maven/mavencentral/org.apache.ant/ant/1.10.10, Apache-2.0 AND W3C AND LicenseRef-Public-Domain, approved, CQ15560 -maven/mavencentral/org.apache.commons/commons-compress/1.20, Apache-2.0 AND BSD-3-Clause AND LicenseRef-Public-Domain, approved, CQ21771 +maven/mavencentral/org.apache.ant/ant-launcher/1.10.12, Apache-2.0 AND W3C AND LicenseRef-Public-Domain, approved, CQ15560 +maven/mavencentral/org.apache.ant/ant/1.10.12, Apache-2.0 AND W3C AND LicenseRef-Public-Domain, approved, CQ15560 +maven/mavencentral/org.apache.commons/commons-compress/1.21, Apache-2.0 AND BSD-3-Clause AND bzip2-1.0.6 AND LicenseRef-Public-Domain, approved, CQ23710 maven/mavencentral/org.apache.commons/commons-math3/3.2, Apache-2.0, approved, clearlydefined maven/mavencentral/org.apache.httpcomponents/httpclient/4.5.13, Apache-2.0 AND LicenseRef-Public-Domain, approved, CQ23527 maven/mavencentral/org.apache.httpcomponents/httpcore/4.4.14, Apache-2.0, approved, CQ23528 -maven/mavencentral/org.apache.sshd/sshd-common/2.7.0, Apache-2.0 and ISC, approved, CQ23469 -maven/mavencentral/org.apache.sshd/sshd-core/2.7.0, Apache-2.0, approved, CQ23469 -maven/mavencentral/org.apache.sshd/sshd-osgi/2.7.0, Apache-2.0 and ISC, approved, CQ23469 -maven/mavencentral/org.apache.sshd/sshd-sftp/2.7.0, Apache-2.0, approved, CQ23470 +maven/mavencentral/org.apache.sshd/sshd-common/2.8.0, Apache-2.0 AND ISC, approved, #2349 +maven/mavencentral/org.apache.sshd/sshd-core/2.8.0, Apache-2.0, approved, #2331 +maven/mavencentral/org.apache.sshd/sshd-osgi/2.8.0, Apache-2.0, approved, CQ23892 +maven/mavencentral/org.apache.sshd/sshd-sftp/2.8.0, Apache-2.0, approved, CQ23893 maven/mavencentral/org.assertj/assertj-core/3.20.2, Apache-2.0, approved, clearlydefined -maven/mavencentral/org.bouncycastle/bcpg-jdk15on/1.69, MIT and Apache-2.0, approved, CQ23472 -maven/mavencentral/org.bouncycastle/bcpkix-jdk15on/1.69, MIT, approved, CQ23473 -maven/mavencentral/org.bouncycastle/bcprov-jdk15on/1.69, MIT, approved, CQ23471 -maven/mavencentral/org.bouncycastle/bcutil-jdk15on/1.69, MIT, approved, CQ23474 -maven/mavencentral/org.eclipse.jetty/jetty-http/9.4.43.v20210629, , approved, eclipse -maven/mavencentral/org.eclipse.jetty/jetty-io/9.4.43.v20210629, , approved, eclipse -maven/mavencentral/org.eclipse.jetty/jetty-security/9.4.43.v20210629, , approved, eclipse -maven/mavencentral/org.eclipse.jetty/jetty-server/9.4.43.v20210629, , approved, eclipse -maven/mavencentral/org.eclipse.jetty/jetty-servlet/9.4.43.v20210629, , approved, eclipse -maven/mavencentral/org.eclipse.jetty/jetty-util-ajax/9.4.43.v20210629, , approved, eclipse -maven/mavencentral/org.eclipse.jetty/jetty-util/9.4.43.v20210629, , approved, eclipse -maven/mavencentral/org.eclipse.jgit/org.eclipse.jgit.ant.test/5.13.0-SNAPSHOT, , approved, eclipse -maven/mavencentral/org.eclipse.jgit/org.eclipse.jgit.ant/5.13.0-SNAPSHOT, , approved, eclipse -maven/mavencentral/org.eclipse.jgit/org.eclipse.jgit.archive/5.13.0-SNAPSHOT, , approved, eclipse -maven/mavencentral/org.eclipse.jgit/org.eclipse.jgit.gpg.bc/5.13.0-SNAPSHOT, , approved, eclipse -maven/mavencentral/org.eclipse.jgit/org.eclipse.jgit.http.apache/5.13.0-SNAPSHOT, , approved, eclipse -maven/mavencentral/org.eclipse.jgit/org.eclipse.jgit.http.server/5.13.0-SNAPSHOT, , approved, eclipse -maven/mavencentral/org.eclipse.jgit/org.eclipse.jgit.http.test/5.13.0-SNAPSHOT, , approved, eclipse -maven/mavencentral/org.eclipse.jgit/org.eclipse.jgit.junit.http/5.13.0-SNAPSHOT, , approved, eclipse -maven/mavencentral/org.eclipse.jgit/org.eclipse.jgit.junit.ssh/5.13.0-SNAPSHOT, , approved, eclipse -maven/mavencentral/org.eclipse.jgit/org.eclipse.jgit.junit/5.13.0-SNAPSHOT, , approved, eclipse -maven/mavencentral/org.eclipse.jgit/org.eclipse.jgit.lfs.server.test/5.13.0-SNAPSHOT, , approved, eclipse -maven/mavencentral/org.eclipse.jgit/org.eclipse.jgit.lfs.server/5.13.0-SNAPSHOT, , approved, eclipse -maven/mavencentral/org.eclipse.jgit/org.eclipse.jgit.lfs.test/5.13.0-SNAPSHOT, , approved, eclipse -maven/mavencentral/org.eclipse.jgit/org.eclipse.jgit.lfs/5.13.0-SNAPSHOT, , approved, eclipse -maven/mavencentral/org.eclipse.jgit/org.eclipse.jgit.pgm.test/5.13.0-SNAPSHOT, , approved, eclipse -maven/mavencentral/org.eclipse.jgit/org.eclipse.jgit.pgm/5.13.0-SNAPSHOT, , approved, eclipse -maven/mavencentral/org.eclipse.jgit/org.eclipse.jgit.ssh.apache.test/5.13.0-SNAPSHOT, , approved, eclipse -maven/mavencentral/org.eclipse.jgit/org.eclipse.jgit.ssh.apache/5.13.0-SNAPSHOT, , approved, eclipse -maven/mavencentral/org.eclipse.jgit/org.eclipse.jgit.ssh.jsch/5.13.0-SNAPSHOT, , approved, eclipse -maven/mavencentral/org.eclipse.jgit/org.eclipse.jgit.test/5.13.0-SNAPSHOT, , approved, eclipse -maven/mavencentral/org.eclipse.jgit/org.eclipse.jgit.ui/5.13.0-SNAPSHOT, , approved, eclipse -maven/mavencentral/org.eclipse.jgit/org.eclipse.jgit/5.13.0-SNAPSHOT, , approved, eclipse -maven/mavencentral/org.hamcrest/hamcrest-core/1.3, BSD-2-Clause, approved, CQ7063 -maven/mavencentral/org.hamcrest/hamcrest/2.2, BSD-2-Clause, approved, clearlydefined -maven/mavencentral/org.mockito/mockito-core/2.23.0, MIT, approved, CQ17976 +maven/mavencentral/org.bouncycastle/bcpg-jdk15on/1.70, Apache-2.0, approved, #1713 +maven/mavencentral/org.bouncycastle/bcpkix-jdk15on/1.70, MIT, approved, clearlydefined +maven/mavencentral/org.bouncycastle/bcprov-jdk15on/1.70, MIT, approved, #1712 +maven/mavencentral/org.bouncycastle/bcutil-jdk15on/1.70, MIT, approved, clearlydefined +maven/mavencentral/org.eclipse.jetty.toolchain/jetty-servlet-api/4.0.6, EPL-2.0 OR Apache-2.0, approved, rt.jetty +maven/mavencentral/org.eclipse.jetty/jetty-http/10.0.6, EPL-2.0 OR Apache-2.0, approved, rt.jetty +maven/mavencentral/org.eclipse.jetty/jetty-io/10.0.6, EPL-2.0 OR Apache-2.0, approved, rt.jetty +maven/mavencentral/org.eclipse.jetty/jetty-security/10.0.6, EPL-2.0 OR Apache-2.0, approved, rt.jetty +maven/mavencentral/org.eclipse.jetty/jetty-server/10.0.6, EPL-2.0 OR Apache-2.0, approved, rt.jetty +maven/mavencentral/org.eclipse.jetty/jetty-servlet/10.0.6, EPL-2.0 OR Apache-2.0, approved, rt.jetty +maven/mavencentral/org.eclipse.jetty/jetty-util/10.0.6, EPL-2.0 OR Apache-2.0, approved, rt.jetty +maven/mavencentral/org.eclipse.jgit/org.eclipse.jgit.ant.test/6.2.0-SNAPSHOT, BSD-3-Clause, approved, technology.jgit +maven/mavencentral/org.eclipse.jgit/org.eclipse.jgit.ant/6.2.0-SNAPSHOT, BSD-3-Clause, approved, technology.jgit +maven/mavencentral/org.eclipse.jgit/org.eclipse.jgit.archive/6.2.0-SNAPSHOT, BSD-3-Clause, approved, technology.jgit +maven/mavencentral/org.eclipse.jgit/org.eclipse.jgit.gpg.bc/6.2.0-SNAPSHOT, BSD-3-Clause, approved, technology.jgit +maven/mavencentral/org.eclipse.jgit/org.eclipse.jgit.http.apache/6.2.0-SNAPSHOT, BSD-3-Clause, approved, technology.jgit +maven/mavencentral/org.eclipse.jgit/org.eclipse.jgit.http.server/6.2.0-SNAPSHOT, BSD-3-Clause, approved, technology.jgit +maven/mavencentral/org.eclipse.jgit/org.eclipse.jgit.http.test/6.2.0-SNAPSHOT, BSD-3-Clause, approved, technology.jgit +maven/mavencentral/org.eclipse.jgit/org.eclipse.jgit.junit.http/6.2.0-SNAPSHOT, BSD-3-Clause, approved, technology.jgit +maven/mavencentral/org.eclipse.jgit/org.eclipse.jgit.junit.ssh/6.2.0-SNAPSHOT, BSD-3-Clause, approved, technology.jgit +maven/mavencentral/org.eclipse.jgit/org.eclipse.jgit.junit/6.2.0-SNAPSHOT, BSD-3-Clause, approved, technology.jgit +maven/mavencentral/org.eclipse.jgit/org.eclipse.jgit.lfs.server.test/6.2.0-SNAPSHOT, BSD-3-Clause, approved, technology.jgit +maven/mavencentral/org.eclipse.jgit/org.eclipse.jgit.lfs.server/6.2.0-SNAPSHOT, BSD-3-Clause, approved, technology.jgit +maven/mavencentral/org.eclipse.jgit/org.eclipse.jgit.lfs.test/6.2.0-SNAPSHOT, BSD-3-Clause, approved, technology.jgit +maven/mavencentral/org.eclipse.jgit/org.eclipse.jgit.lfs/6.2.0-SNAPSHOT, BSD-3-Clause, approved, technology.jgit +maven/mavencentral/org.eclipse.jgit/org.eclipse.jgit.pgm.test/6.2.0-SNAPSHOT, BSD-3-Clause, approved, technology.jgit +maven/mavencentral/org.eclipse.jgit/org.eclipse.jgit.pgm/6.2.0-SNAPSHOT, BSD-3-Clause, approved, technology.jgit +maven/mavencentral/org.eclipse.jgit/org.eclipse.jgit.ssh.apache.agent/6.2.0-SNAPSHOT, BSD-3-Clause, approved, technology.jgit +maven/mavencentral/org.eclipse.jgit/org.eclipse.jgit.ssh.apache.test/6.2.0-SNAPSHOT, BSD-3-Clause, approved, technology.jgit +maven/mavencentral/org.eclipse.jgit/org.eclipse.jgit.ssh.apache/6.2.0-SNAPSHOT, BSD-3-Clause, approved, technology.jgit +maven/mavencentral/org.eclipse.jgit/org.eclipse.jgit.ssh.jsch/6.2.0-SNAPSHOT, BSD-3-Clause, approved, technology.jgit +maven/mavencentral/org.eclipse.jgit/org.eclipse.jgit.test/6.2.0-SNAPSHOT, BSD-3-Clause, approved, technology.jgit +maven/mavencentral/org.eclipse.jgit/org.eclipse.jgit.ui/6.2.0-SNAPSHOT, BSD-3-Clause, approved, technology.jgit +maven/mavencentral/org.eclipse.jgit/org.eclipse.jgit/6.2.0-SNAPSHOT, BSD-3-Clause, approved, technology.jgit +maven/mavencentral/org.hamcrest/hamcrest-core/1.3, BSD-2-Clause, approved, CQ11429 +maven/mavencentral/org.mockito/mockito-core/2.23.0, Apache-2.0 AND MIT, approved, #958 maven/mavencentral/org.objenesis/objenesis/2.6, Apache-2.0, approved, CQ15478 -maven/mavencentral/org.openjdk.jmh/jmh-core/1.32, GPL-2.0, approved, CQ23499 -maven/mavencentral/org.openjdk.jmh/jmh-generator-annprocess/1.32, GPL-2.0, approved, CQ23500 -maven/mavencentral/org.osgi/org.osgi.core/4.3.1, Apache-2.0, approved, CQ10111 -maven/mavencentral/org.slf4j/jcl-over-slf4j/1.7.30, Apache-2.0, approved, CQ12843 +maven/mavencentral/org.openjdk.jmh/jmh-core/1.32, GPL-2.0-only with Classpath-exception-2.0, approved, #959 +maven/mavencentral/org.openjdk.jmh/jmh-generator-annprocess/1.32, GPL-2.0-only with Classpath-exception-2.0, approved, #962 +maven/mavencentral/org.osgi/org.osgi.core/6.0.0, Apache-2.0, approved, #1794 +maven/mavencentral/org.slf4j/jcl-over-slf4j/1.7.32, Apache-2.0, approved, CQ12843 maven/mavencentral/org.slf4j/slf4j-api/1.7.30, MIT, approved, CQ13368 -maven/mavencentral/org.slf4j/slf4j-log4j12/1.7.30, MIT, approved, CQ7665 +maven/mavencentral/org.slf4j/slf4j-simple/1.7.30, MIT, approved, CQ7952 maven/mavencentral/org.tukaani/xz/1.9, LicenseRef-Public-Domain, approved, CQ23498 @@ -1,23 +1,6 @@ workspace(name = "jgit") load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") - -http_archive( - name = "bazel_skylib", - sha256 = "2ea8a5ed2b448baf4a6855d3ce049c4c452a6470b1efd1504fdb7c1c134d220a", - strip_prefix = "bazel-skylib-0.8.0", - urls = ["https://github.com/bazelbuild/bazel-skylib/archive/0.8.0.tar.gz"], -) - -# Check Bazel version when invoked by Bazel directly -load("//tools:bazelisk_version.bzl", "bazelisk_version") - -bazelisk_version(name = "bazelisk_version") - -load("@bazelisk_version//:check.bzl", "check_bazel_version") - -check_bazel_version() - load("//tools:bazlets.bzl", "load_bazlets") load_bazlets(commit = "f30a992da9fc855dce819875afb59f9dd6f860cd") @@ -28,32 +11,18 @@ load( ) http_archive( - name = "openjdk15_linux_archive", - build_file_content = """ -java_runtime(name = 'runtime', srcs = glob(['**']), visibility = ['//visibility:public']) -exports_files(["WORKSPACE"], visibility = ["//visibility:public"]) -""", - sha256 = "0a38f1138c15a4f243b75eb82f8ef40855afcc402e3c2a6de97ce8235011b1ad", - strip_prefix = "zulu15.27.17-ca-jdk15.0.0-linux_x64", + name = "rbe_jdk11", + sha256 = "766796de71916118e528b9f4334c29c9c9b4e926227bf3264dee555e6a4306c8", + strip_prefix = "rbe_autoconfig-2.0.0", urls = [ - "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu15.27.17-ca-jdk15.0.0-linux_x64.tar.gz", - "https://cdn.azul.com/zulu/bin/zulu15.27.17-ca-jdk15.0.0-linux_x64.tar.gz", + "https://gerrit-bazel.storage.googleapis.com/rbe_autoconfig/v2.0.0.tar.gz", + "https://github.com/davido/rbe_autoconfig/archive/v2.0.0.tar.gz", ], ) -http_archive( - name = "openjdk15_darwin_archive", - build_file_content = """ -java_runtime(name = 'runtime', srcs = glob(['**']), visibility = ['//visibility:public']) -exports_files(["WORKSPACE"], visibility = ["//visibility:public"]) -""", - sha256 = "f80b2e0512d9d8a92be24497334c974bfecc8c898fc215ce0e76594f00437482", - strip_prefix = "zulu15.27.17-ca-jdk15.0.0-macosx_x64", - urls = [ - "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu15.27.17-ca-jdk15.0.0-macosx_x64.tar.gz", - "https://cdn.azul.com/zulu/bin/zulu15.27.17-ca-jdk15.0.0-macosx_x64.tar.gz", - ], -) +register_toolchains("//tools:error_prone_warnings_toolchain_java11_definition") + +register_toolchains("//tools:error_prone_warnings_toolchain_java17_definition") JMH_VERS = "1.32" @@ -99,8 +68,8 @@ maven_jar( maven_jar( name = "jzlib", - artifact = "com.jcraft:jzlib:1.1.1", - sha1 = "a1551373315ffc2f96130a0e5704f74e151777ba", + artifact = "com.jcraft:jzlib:1.1.3", + sha1 = "c01428efa717624f7aabf4df319939dda9646b2d", ) maven_jar( @@ -123,14 +92,14 @@ maven_jar( maven_jar( name = "sshd-osgi", - artifact = "org.apache.sshd:sshd-osgi:2.7.0", - sha1 = "a101aad0f79ad424498098f7e91c39d3d92177c1", + artifact = "org.apache.sshd:sshd-osgi:2.8.0", + sha1 = "b2a59b73c045f40d5722b9160d4f909a646d86c9", ) maven_jar( name = "sshd-sftp", - artifact = "org.apache.sshd:sshd-sftp:2.7.0", - sha1 = "0c9eff7145e20b338c1dd6aca36ba93ed7c0147c", + artifact = "org.apache.sshd:sshd-sftp:2.8.0", + sha1 = "d3cd9bc8d335b3ed1a86d2965deb4d202de27442", ) maven_jar( @@ -171,8 +140,8 @@ maven_jar( maven_jar( name = "servlet-api", - artifact = "javax.servlet:javax.servlet-api:3.1.0", - sha1 = "3cd63d075497751784b2fa84be59432f4905bf7c", + artifact = "javax.servlet:javax.servlet-api:4.0.0", + sha1 = "60200affc2fe0165136ed3690faf00b66aed581a", ) maven_jar( @@ -239,8 +208,8 @@ maven_jar( maven_jar( name = "gson", - artifact = "com.google.code.gson:gson:2.8.8", - sha1 = "431fc3cbc0ff81abdbfde070062741089c3ba874", + artifact = "com.google.code.gson:gson:2.8.9", + sha1 = "8a432c1d6825781e21a02db2e2c33c5fde2833b9", ) JETTY_VER = "10.0.6" @@ -294,32 +263,32 @@ maven_jar( src_sha1 = "f35f5525a5d30dc1237b85457d758d578e3ce8d0", ) -BOUNCYCASTLE_VER = "1.69" +BOUNCYCASTLE_VER = "1.70" maven_jar( name = "bcpg", artifact = "org.bouncycastle:bcpg-jdk15on:" + BOUNCYCASTLE_VER, - sha1 = "d99a08c3f651b26e8eb668e941b0bbd2c09ece08", - src_sha1 = "de1fc261b44a8eb60583413a31ffc98ce3dce38b", + sha1 = "062f72ec06f31a6c31a3f3355fce0384b21126d7", + src_sha1 = "9dee73ad926752ee3b421a7dc4531287166ccf36", ) maven_jar( name = "bcprov", artifact = "org.bouncycastle:bcprov-jdk15on:" + BOUNCYCASTLE_VER, - sha1 = "91e1628251cf3ca90093ce9d0fe67e5b7dab3850", - src_sha1 = "67dc6476845f6b29cb520b5df61db65ae56718e4", + sha1 = "4636a0d01f74acaf28082fb62b317f1080118371", + src_sha1 = "6245e15dd47e5fc33cff275df61662e0a8e5958f", ) maven_jar( name = "bcutil", artifact = "org.bouncycastle:bcutil-jdk15on:" + BOUNCYCASTLE_VER, - sha1 = "c3edf93d346e97f64f041e448e7455c39c7eff64", - src_sha1 = "deeb3fbbf373e05e2a20941f9a8ce90e9aeab3d2", + sha1 = "54280e7195a7430d7911ded93fc01e07300b9526", + src_sha1 = "4af4a6c92b8ea07885b27d8536b81b855497f4eb", ) maven_jar( name = "bcpkix", artifact = "org.bouncycastle:bcpkix-jdk15on:" + BOUNCYCASTLE_VER, - sha1 = "45c36fb72fafb0b688c6af795e6cc803f6f79ee5", - src_sha1 = "8bc5214401459bd91eea816b516079da38374e90", + sha1 = "f81e5af49571a9d5a109a88f239a73ce87055417", + src_sha1 = "42f9de53a91b20bc06e88482c57fd97e5a84250d", ) @@ -97,7 +97,7 @@ java_library( java_library( name = "jna", visibility = [ - "//org.eclipse.jgit.ssh.apache.agent:__pkg__", + "//org.eclipse.jgit.ssh.apache.agent:__pkg__", ], exports = ["@jna//jar"], ) @@ -105,7 +105,7 @@ java_library( java_library( name = "jna-platform", visibility = [ - "//org.eclipse.jgit.ssh.apache.agent:__pkg__", + "//org.eclipse.jgit.ssh.apache.agent:__pkg__", ], exports = ["@jna-platform//jar"], ) @@ -277,7 +277,6 @@ java_library( java_library( name = "slf4j-simple", - testonly = 1, visibility = ["//visibility:public"], exports = ["@slf4j-simple//jar"], ) diff --git a/org.eclipse.jgit.ant/pom.xml b/org.eclipse.jgit.ant/pom.xml index c5d92fc607..adbee5c74b 100644 --- a/org.eclipse.jgit.ant/pom.xml +++ b/org.eclipse.jgit.ant/pom.xml @@ -38,6 +38,7 @@ <dependency> <groupId>org.apache.ant</groupId> <artifactId>ant</artifactId> + <version>1.10.12</version> </dependency> </dependencies> diff --git a/org.eclipse.jgit.benchmarks/src/org/eclipse/jgit/benchmarks/GetRefsBenchmark.java b/org.eclipse.jgit.benchmarks/src/org/eclipse/jgit/benchmarks/GetRefsBenchmark.java new file mode 100644 index 0000000000..62627e66f6 --- /dev/null +++ b/org.eclipse.jgit.benchmarks/src/org/eclipse/jgit/benchmarks/GetRefsBenchmark.java @@ -0,0 +1,181 @@ +/* + * Copyright (C) 2021, Luca Milanesio <luca.milanesio@gmail.com> and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Distribution License v. 1.0 which is available at + * https://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: BSD-3-Clause + */ +package org.eclipse.jgit.benchmarks; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ThreadLocalRandom; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.stream.Collectors; +import java.util.stream.IntStream; + +import org.eclipse.jgit.api.Git; +import org.eclipse.jgit.api.errors.GitAPIException; +import org.eclipse.jgit.internal.storage.dfs.DfsRepositoryDescription; +import org.eclipse.jgit.internal.storage.dfs.InMemoryRepository; +import org.eclipse.jgit.internal.storage.file.FileRepository; +import org.eclipse.jgit.lib.*; +import org.eclipse.jgit.revwalk.RevCommit; +import org.eclipse.jgit.revwalk.RevWalk; +import org.eclipse.jgit.transport.ReceiveCommand; +import org.eclipse.jgit.util.FS; +import org.eclipse.jgit.util.FileUtils; +import org.openjdk.jmh.annotations.Benchmark; +import org.openjdk.jmh.annotations.BenchmarkMode; +import org.openjdk.jmh.annotations.Measurement; +import org.openjdk.jmh.annotations.Mode; +import org.openjdk.jmh.annotations.OutputTimeUnit; +import org.openjdk.jmh.annotations.Param; +import org.openjdk.jmh.annotations.Scope; +import org.openjdk.jmh.annotations.Setup; +import org.openjdk.jmh.annotations.State; +import org.openjdk.jmh.annotations.TearDown; +import org.openjdk.jmh.annotations.Warmup; +import org.openjdk.jmh.infra.Blackhole; +import org.openjdk.jmh.runner.Runner; +import org.openjdk.jmh.runner.RunnerException; +import org.openjdk.jmh.runner.options.Options; +import org.openjdk.jmh.runner.options.OptionsBuilder; + +import static org.eclipse.jgit.transport.ReceiveCommand.Type.CREATE; +import static org.eclipse.jgit.transport.ReceiveCommand.Type.UPDATE; + +@State(Scope.Thread) +public class GetRefsBenchmark { + + ThreadLocalRandom branchIndex = ThreadLocalRandom.current(); + + @State(Scope.Benchmark) + public static class BenchmarkState { + + @Param({ "true", "false" }) + boolean useRefTable; + + @Param({ "100", "2500", "10000", "50000" }) + int numBranches; + + @Param({ "true", "false" }) + boolean trustFolderStat; + + List<String> branches = new ArrayList<>(numBranches); + + Path testDir; + + Repository repo; + + @Setup + @SuppressWarnings("boxing") + public void setupBenchmark() throws IOException, GitAPIException { + String firstBranch = "firstbranch"; + testDir = Files.createDirectory(Paths.get("testrepos")); + String repoName = "branches-" + numBranches + "-trustFolderStat-" + + trustFolderStat + "-" + refDatabaseType(); + Path workDir = testDir.resolve(repoName); + Path repoPath = workDir.resolve(".git"); + Git git = Git.init().setDirectory(workDir.toFile()).call(); + RevCommit firstCommit = git.commit().setMessage("First commit") + .call(); + git.branchCreate().setName(firstBranch).call(); + + StoredConfig cfg = git.getRepository().getConfig(); + if (useRefTable) { + ((FileRepository) git.getRepository()).convertRefStorage( + ConfigConstants.CONFIG_REF_STORAGE_REFTABLE, false, + false); + } else { + cfg.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null, + ConfigConstants.CONFIG_KEY_TRUSTFOLDERSTAT, + trustFolderStat); + } + cfg.setInt(ConfigConstants.CONFIG_RECEIVE_SECTION, null, + "maxCommandBytes", Integer.MAX_VALUE); + cfg.save(); + + repo = RepositoryCache.open(RepositoryCache.FileKey + .lenient(repoPath.toFile(), FS.DETECTED)); + + System.out.println("Preparing test"); + System.out.println("- repository: \t\t" + repoPath); + System.out.println("- refDatabase: \t\t" + refDatabaseType()); + System.out.println("- trustFolderStat: \t" + trustFolderStat); + System.out.println("- branches: \t\t" + numBranches); + + BatchRefUpdate u = repo.getRefDatabase().newBatchUpdate(); + + branches = IntStream.range(0, numBranches) + .mapToObj(i -> "branch/" + i % 100 + "/" + i) + .collect(Collectors.toList()); + for (String branch : branches) { + u.addCommand(new ReceiveCommand(ObjectId.zeroId(), + firstCommit.toObjectId(), Constants.R_HEADS + branch, + CREATE)); + } + + System.out.println(); + System.out.print( + String.format("Creating %d branches ... ", numBranches)); + + try (RevWalk rw = new RevWalk(repo)) { + u.execute(rw, new TextProgressMonitor()); + } + System.out.println("DONE"); + } + + private String refDatabaseType() { + return useRefTable ? "reftable" : "refdir"; + } + + @TearDown + public void teardown() throws IOException { + repo.close(); + FileUtils.delete(testDir.toFile(), + FileUtils.RECURSIVE | FileUtils.RETRY); + } + } + + @Benchmark + @BenchmarkMode({ Mode.AverageTime }) + @OutputTimeUnit(TimeUnit.MICROSECONDS) + @Warmup(iterations = 2, time = 100, timeUnit = TimeUnit.MILLISECONDS) + @Measurement(iterations = 2, time = 10, timeUnit = TimeUnit.SECONDS) + public void testGetExactRef(Blackhole blackhole, BenchmarkState state) + throws IOException { + String branchName = state.branches + .get(branchIndex.nextInt(state.numBranches)); + blackhole.consume(state.repo.exactRef(branchName)); + } + + @Benchmark + @BenchmarkMode({ Mode.AverageTime }) + @OutputTimeUnit(TimeUnit.MICROSECONDS) + @Warmup(iterations = 2, time = 100, timeUnit = TimeUnit.MILLISECONDS) + @Measurement(iterations = 2, time = 10, timeUnit = TimeUnit.SECONDS) + public void testGetRefsByPrefix(Blackhole blackhole, BenchmarkState state) + throws IOException { + String branchPrefix = "refs/heads/branch/" + branchIndex.nextInt(100) + + "/"; + blackhole.consume( + state.repo.getRefDatabase().getRefsByPrefix(branchPrefix)); + } + + public static void main(String[] args) throws RunnerException { + Options opt = new OptionsBuilder() + .include(GetRefsBenchmark.class.getSimpleName()) + // .addProfiler(StackProfiler.class) + // .addProfiler(GCProfiler.class) + .forks(1).jvmArgs("-ea").build(); + new Runner(opt).run(); + } +} diff --git a/org.eclipse.jgit.gpg.bc.test/BUILD b/org.eclipse.jgit.gpg.bc.test/BUILD index 35b125f21e..9e5813cb39 100644 --- a/org.eclipse.jgit.gpg.bc.test/BUILD +++ b/org.eclipse.jgit.gpg.bc.test/BUILD @@ -10,8 +10,8 @@ load( junit_tests( name = "bc", srcs = glob(["tst/**/*.java"]), - resource_jars = [":tst_rsrc"], tags = ["bc"], + runtime_deps = [":tst_rsrc"], deps = [ "//lib:bcpg", "//lib:bcprov", diff --git a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/GitSmartHttpTools.java b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/GitSmartHttpTools.java index 012f9a3dc0..f1155dcf57 100644 --- a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/GitSmartHttpTools.java +++ b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/GitSmartHttpTools.java @@ -158,11 +158,11 @@ public class GitSmartHttpTools { } if (isInfoRefs(req)) { - sendInfoRefsError(req, res, textForGit); + sendInfoRefsError(req, res, textForGit, httpStatus); } else if (isUploadPack(req)) { - sendUploadPackError(req, res, textForGit); + sendUploadPackError(req, res, textForGit, httpStatus); } else if (isReceivePack(req)) { - sendReceivePackError(req, res, textForGit); + sendReceivePackError(req, res, textForGit, httpStatus); } else { if (httpStatus < 400) ServletUtils.consumeRequestBody(req); @@ -171,29 +171,32 @@ public class GitSmartHttpTools { } private static void sendInfoRefsError(HttpServletRequest req, - HttpServletResponse res, String textForGit) throws IOException { + HttpServletResponse res, String textForGit, int httpStatus) + throws IOException { ByteArrayOutputStream buf = new ByteArrayOutputStream(128); PacketLineOut pck = new PacketLineOut(buf); String svc = req.getParameter("service"); pck.writeString("# service=" + svc + "\n"); pck.end(); pck.writeString("ERR " + textForGit); - send(req, res, infoRefsResultType(svc), buf.toByteArray()); + send(req, res, infoRefsResultType(svc), buf.toByteArray(), httpStatus); } private static void sendUploadPackError(HttpServletRequest req, - HttpServletResponse res, String textForGit) throws IOException { + HttpServletResponse res, String textForGit, int httpStatus) + throws IOException { // Do not use sideband. Sideband is acceptable only while packfile is // being sent. Other places, like acknowledgement section, do not // support sideband. Use an error packet. ByteArrayOutputStream buf = new ByteArrayOutputStream(128); PacketLineOut pckOut = new PacketLineOut(buf); writePacket(pckOut, textForGit); - send(req, res, UPLOAD_PACK_RESULT_TYPE, buf.toByteArray()); + send(req, res, UPLOAD_PACK_RESULT_TYPE, buf.toByteArray(), httpStatus); } private static void sendReceivePackError(HttpServletRequest req, - HttpServletResponse res, String textForGit) throws IOException { + HttpServletResponse res, String textForGit, int httpStatus) + throws IOException { ByteArrayOutputStream buf = new ByteArrayOutputStream(128); PacketLineOut pckOut = new PacketLineOut(buf); @@ -212,7 +215,7 @@ public class GitSmartHttpTools { writeSideBand(buf, textForGit); else writePacket(pckOut, textForGit); - send(req, res, RECEIVE_PACK_RESULT_TYPE, buf.toByteArray()); + send(req, res, RECEIVE_PACK_RESULT_TYPE, buf.toByteArray(), httpStatus); } private static boolean isReceivePackSideBand(HttpServletRequest req) { @@ -246,9 +249,9 @@ public class GitSmartHttpTools { } private static void send(HttpServletRequest req, HttpServletResponse res, - String type, byte[] buf) throws IOException { + String type, byte[] buf, int httpStatus) throws IOException { ServletUtils.consumeRequestBody(req); - res.setStatus(HttpServletResponse.SC_OK); + res.setStatus(httpStatus); res.setContentType(type); res.setContentLength(buf.length); try (OutputStream os = res.getOutputStream()) { diff --git a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/UploadPackServlet.java b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/UploadPackServlet.java index 2759b8a0fe..23a398f9db 100644 --- a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/UploadPackServlet.java +++ b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/UploadPackServlet.java @@ -10,6 +10,7 @@ package org.eclipse.jgit.http.server; +import static javax.servlet.http.HttpServletResponse.SC_BAD_REQUEST; import static javax.servlet.http.HttpServletResponse.SC_FORBIDDEN; import static javax.servlet.http.HttpServletResponse.SC_INTERNAL_SERVER_ERROR; import static javax.servlet.http.HttpServletResponse.SC_UNAUTHORIZED; @@ -48,6 +49,7 @@ import org.eclipse.jgit.transport.RefAdvertiser.PacketLineOutRefAdvertiser; import org.eclipse.jgit.transport.ServiceMayNotContinueException; import org.eclipse.jgit.transport.UploadPack; import org.eclipse.jgit.transport.UploadPackInternalServerErrorException; +import org.eclipse.jgit.transport.WantNotValidException; import org.eclipse.jgit.transport.resolver.ServiceNotAuthorizedException; import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException; import org.eclipse.jgit.transport.resolver.UploadPackFactory; @@ -151,6 +153,16 @@ class UploadPackServlet extends HttpServlet { } } + private static int statusCodeForThrowable(Throwable error) { + if (error instanceof ServiceNotEnabledException) { + return SC_FORBIDDEN; + } + if (error instanceof WantNotValidException) { + return SC_BAD_REQUEST; + } + return SC_INTERNAL_SERVER_ERROR; + } + private final UploadPackErrorHandler handler; UploadPackServlet(@Nullable UploadPackErrorHandler handler) { @@ -169,6 +181,7 @@ class UploadPackServlet extends HttpServlet { UploadPackRunnable r = () -> { UploadPack up = (UploadPack) req.getAttribute(ATTRIBUTE_HANDLER); + // to be explicitly closed by caller @SuppressWarnings("resource") SmartOutputStream out = new SmartOutputStream(req, rsp, false) { @Override @@ -195,6 +208,8 @@ class UploadPackServlet extends HttpServlet { log(up.getRepository(), e.getCause()); consumeRequestBody(req); out.close(); + } finally { + up.close(); } }; @@ -215,9 +230,12 @@ class UploadPackServlet extends HttpServlet { log(up.getRepository(), e); if (!rsp.isCommitted()) { rsp.reset(); - String msg = e instanceof PackProtocolException ? e.getMessage() - : null; - sendError(req, rsp, SC_INTERNAL_SERVER_ERROR, msg); + String msg = null; + if (e instanceof PackProtocolException + || e instanceof ServiceNotEnabledException) { + msg = e.getMessage(); + } + sendError(req, rsp, statusCodeForThrowable(e), msg); } } } diff --git a/org.eclipse.jgit.http.test/build.properties b/org.eclipse.jgit.http.test/build.properties index a909f1301f..a12a660466 100644 --- a/org.eclipse.jgit.http.test/build.properties +++ b/org.eclipse.jgit.http.test/build.properties @@ -4,5 +4,4 @@ output.. = bin/ bin.includes = META-INF/,\ .,\ plugin.properties -additional.bundles = org.apache.log4j,\ - org.slf4j.binding.log4j12 +additional.bundles = org.slf4j.binding.simple diff --git a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/HookMessageTest.java b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/HookMessageTest.java index db9f2ae3d7..20de2567c1 100644 --- a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/HookMessageTest.java +++ b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/HookMessageTest.java @@ -97,6 +97,7 @@ public class HookMessageTest extends AllFactoriesHttpTestCase { server.setUp(); remoteRepository = src.getRepository(); + addRepoToClose(remoteRepository); remoteURI = toURIish(app, srcName); StoredConfig cfg = remoteRepository.getConfig(); diff --git a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/HttpClientTests.java b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/HttpClientTests.java index df093c185b..3438c52c8d 100644 --- a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/HttpClientTests.java +++ b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/HttpClientTests.java @@ -23,6 +23,7 @@ import java.io.File; import java.io.OutputStream; import java.net.URI; import java.net.URL; +import java.text.MessageFormat; import java.util.List; import javax.servlet.http.HttpServletRequest; @@ -308,7 +309,10 @@ public class HttpClientTests extends AllFactoriesHttpTestCase { fail("connection opened even though service disabled"); } catch (TransportException err) { String exp = smartAuthNoneURI + ": " - + JGitText.get().serviceNotEnabledNoName; + + MessageFormat.format( + JGitText.get().serviceNotPermitted, + smartAuthNoneURI.toString() + "/", + "git-upload-pack"); assertEquals(exp, err.getMessage()); } } diff --git a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/MeasurePackSizeTest.java b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/MeasurePackSizeTest.java index 9ffa19efef..000eecdccf 100644 --- a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/MeasurePackSizeTest.java +++ b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/MeasurePackSizeTest.java @@ -90,6 +90,7 @@ public class MeasurePackSizeTest extends AllFactoriesHttpTestCase { server.setUp(); remoteRepository = src.getRepository(); + addRepoToClose(remoteRepository); remoteURI = toURIish(app, srcName); StoredConfig cfg = remoteRepository.getConfig(); diff --git a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/SmartClientSmartServerTest.java b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/SmartClientSmartServerTest.java index 887e970a0c..8f3888e4d5 100644 --- a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/SmartClientSmartServerTest.java +++ b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/SmartClientSmartServerTest.java @@ -57,7 +57,7 @@ import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.TransportConfigCallback; -import org.eclipse.jgit.errors.RemoteRepositoryException; +import org.eclipse.jgit.errors.NoRemoteRepositoryException; import org.eclipse.jgit.errors.TransportException; import org.eclipse.jgit.errors.UnsupportedCredentialItem; import org.eclipse.jgit.http.server.GitServlet; @@ -496,8 +496,9 @@ public class SmartClientSmartServerTest extends AllProtocolsHttpTestCase { try { t.openFetch(); fail("fetch connection opened"); - } catch (RemoteRepositoryException notFound) { - assertEquals(uri + ": Git repository not found", + } catch (NoRemoteRepositoryException notFound) { + assertEquals(uri + ": " + uri + + "/info/refs?service=git-upload-pack not found: Not Found", notFound.getMessage()); } } @@ -510,7 +511,7 @@ public class SmartClientSmartServerTest extends AllProtocolsHttpTestCase { assertEquals(join(uri, "info/refs"), info.getPath()); assertEquals(1, info.getParameters().size()); assertEquals("git-upload-pack", info.getParameter("service")); - assertEquals(200, info.getStatus()); + assertEquals(404, info.getStatus()); assertEquals("application/x-git-upload-pack-advertisement", info.getResponseHeader(HDR_CONTENT_TYPE)); } @@ -536,8 +537,9 @@ public class SmartClientSmartServerTest extends AllProtocolsHttpTestCase { Collections.singletonList( new RefSpec(unreachableCommit.name())))); assertTrue(e.getMessage().contains( - "want " + unreachableCommit.name() + " not valid")); + "Bad Request")); } + assertLastRequestStatusCode(400); } @Test @@ -558,8 +560,9 @@ public class SmartClientSmartServerTest extends AllProtocolsHttpTestCase { () -> t.fetch(NullProgressMonitor.INSTANCE, Collections.singletonList(new RefSpec(A.name())))); assertTrue( - e.getMessage().contains("want " + A.name() + " not valid")); + e.getMessage().contains("Bad Request")); } + assertLastRequestStatusCode(400); } @Test @@ -916,6 +919,7 @@ public class SmartClientSmartServerTest extends AllProtocolsHttpTestCase { } catch (TransportException e) { assertTrue(e.getMessage().contains("301")); } + assertLastRequestStatusCode(301); } @Test @@ -934,6 +938,7 @@ public class SmartClientSmartServerTest extends AllProtocolsHttpTestCase { assertTrue( e.getMessage().contains("http.followRedirects is false")); } + assertLastRequestStatusCode(301); } private void assertFetchRequests(List<AccessEvent> requests, int index) { @@ -1605,8 +1610,9 @@ public class SmartClientSmartServerTest extends AllProtocolsHttpTestCase { fail("Server accepted want " + id.name()); } catch (TransportException err) { assertTrue(err.getMessage() - .contains("want " + id.name() + " not valid")); + .contains("Bad Request")); } + assertLastRequestStatusCode(400); } @Test @@ -1650,7 +1656,7 @@ public class SmartClientSmartServerTest extends AllProtocolsHttpTestCase { fail("Successfully served ref with value " + c.getRef(master)); } catch (TransportException err) { assertTrue("Unexpected exception message " + err.getMessage(), - err.getMessage().contains("Internal server error")); + err.getMessage().contains("Server Error")); } } finally { noRefServer.tearDown(); @@ -1821,6 +1827,11 @@ public class SmartClientSmartServerTest extends AllProtocolsHttpTestCase { .getResponseHeader(HDR_CONTENT_TYPE)); } + private void assertLastRequestStatusCode(int statusCode) { + List<AccessEvent> requests = getRequests(); + assertEquals(statusCode, requests.get(requests.size() - 1).getStatus()); + } + private void enableReceivePack() throws IOException { final StoredConfig cfg = remoteRepository.getConfig(); cfg.setBoolean("http", null, "receivepack", true); diff --git a/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/HttpTestCase.java b/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/HttpTestCase.java index 3e7c84f667..877b918695 100644 --- a/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/HttpTestCase.java +++ b/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/HttpTestCase.java @@ -22,6 +22,7 @@ import java.util.List; import java.util.Set; import org.eclipse.jetty.servlet.ServletContextHandler; +import org.eclipse.jgit.internal.storage.file.FileRepository; import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase; import org.eclipse.jgit.junit.TestRepository; import org.eclipse.jgit.lib.AnyObjectId; @@ -80,7 +81,9 @@ public abstract class HttpTestCase extends LocalDiskRepositoryTestCase { */ protected TestRepository<Repository> createTestRepository() throws IOException { - return new TestRepository<>(createBareRepository()); + final FileRepository repository = createBareRepository(); + addRepoToClose(repository); + return new TestRepository<>(repository); } /** diff --git a/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/RecordingLogger.java b/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/RecordingLogger.java index 9c3c980ad8..af63084e93 100644 --- a/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/RecordingLogger.java +++ b/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/RecordingLogger.java @@ -180,11 +180,15 @@ public class RecordingLogger extends MarkerIgnoringBase { @Override public void warn(String format, Object arg) { - warn(format, Collections.singleton(arg)); + addWarnings(format, Collections.singleton(arg)); } @Override public void warn(String format, Object... arguments) { + addWarnings(format, arguments); + } + + private void addWarnings(String format, Object... arguments) { synchronized (warnings) { int i = 0; int index = format.indexOf("{}"); diff --git a/org.eclipse.jgit.junit.ssh/META-INF/MANIFEST.MF b/org.eclipse.jgit.junit.ssh/META-INF/MANIFEST.MF index 813195fe31..f80f86a68b 100644 --- a/org.eclipse.jgit.junit.ssh/META-INF/MANIFEST.MF +++ b/org.eclipse.jgit.junit.ssh/META-INF/MANIFEST.MF @@ -8,31 +8,31 @@ Bundle-Localization: plugin Bundle-Vendor: %Bundle-Vendor Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: JavaSE-11 -Import-Package: org.apache.sshd.common;version="[2.7.0,2.8.0)", - org.apache.sshd.common.config.keys;version="[2.7.0,2.8.0)", - org.apache.sshd.common.file.virtualfs;version="[2.7.0,2.8.0)", - org.apache.sshd.common.helpers;version="[2.7.0,2.8.0)", - org.apache.sshd.common.io;version="[2.7.0,2.8.0)", - org.apache.sshd.common.kex;version="[2.7.0,2.8.0)", - org.apache.sshd.common.keyprovider;version="[2.7.0,2.8.0)", - org.apache.sshd.common.session;version="[2.7.0,2.8.0)", - org.apache.sshd.common.signature;version="[2.7.0,2.8.0)", - org.apache.sshd.common.util.buffer;version="[2.7.0,2.8.0)", - org.apache.sshd.common.util.logging;version="[2.7.0,2.8.0)", - org.apache.sshd.common.util.security;version="[2.7.0,2.8.0)", - org.apache.sshd.common.util.threads;version="[2.7.0,2.8.0)", - org.apache.sshd.core;version="[2.7.0,2.8.0)", - org.apache.sshd.server;version="[2.7.0,2.8.0)", - org.apache.sshd.server.auth;version="[2.7.0,2.8.0)", - org.apache.sshd.server.auth.gss;version="[2.7.0,2.8.0)", - org.apache.sshd.server.auth.keyboard;version="[2.7.0,2.8.0)", - org.apache.sshd.server.auth.password;version="[2.7.0,2.8.0)", - org.apache.sshd.server.command;version="[2.7.0,2.8.0)", - org.apache.sshd.server.session;version="[2.7.0,2.8.0)", - org.apache.sshd.server.shell;version="[2.7.0,2.8.0)", - org.apache.sshd.server.subsystem;version="[2.7.0,2.8.0)", - org.apache.sshd.sftp;version="[2.7.0,2.8.0)", - org.apache.sshd.sftp.server;version="[2.7.0,2.8.0)", +Import-Package: org.apache.sshd.common;version="[2.8.0,2.9.0)", + org.apache.sshd.common.config.keys;version="[2.8.0,2.9.0)", + org.apache.sshd.common.file.virtualfs;version="[2.8.0,2.9.0)", + org.apache.sshd.common.helpers;version="[2.8.0,2.9.0)", + org.apache.sshd.common.io;version="[2.8.0,2.9.0)", + org.apache.sshd.common.kex;version="[2.8.0,2.9.0)", + org.apache.sshd.common.keyprovider;version="[2.8.0,2.9.0)", + org.apache.sshd.common.session;version="[2.8.0,2.9.0)", + org.apache.sshd.common.signature;version="[2.8.0,2.9.0)", + org.apache.sshd.common.util.buffer;version="[2.8.0,2.9.0)", + org.apache.sshd.common.util.logging;version="[2.8.0,2.9.0)", + org.apache.sshd.common.util.security;version="[2.8.0,2.9.0)", + org.apache.sshd.common.util.threads;version="[2.8.0,2.9.0)", + org.apache.sshd.core;version="[2.8.0,2.9.0)", + org.apache.sshd.server;version="[2.8.0,2.9.0)", + org.apache.sshd.server.auth;version="[2.8.0,2.9.0)", + org.apache.sshd.server.auth.gss;version="[2.8.0,2.9.0)", + org.apache.sshd.server.auth.keyboard;version="[2.8.0,2.9.0)", + org.apache.sshd.server.auth.password;version="[2.8.0,2.9.0)", + org.apache.sshd.server.command;version="[2.8.0,2.9.0)", + org.apache.sshd.server.session;version="[2.8.0,2.9.0)", + org.apache.sshd.server.shell;version="[2.8.0,2.9.0)", + org.apache.sshd.server.subsystem;version="[2.8.0,2.9.0)", + org.apache.sshd.sftp;version="[2.8.0,2.9.0)", + org.apache.sshd.sftp.server;version="[2.8.0,2.9.0)", org.eclipse.jgit.annotations;version="[7.0.0,7.1.0)", org.eclipse.jgit.api;version="[7.0.0,7.1.0)", org.eclipse.jgit.api.errors;version="[7.0.0,7.1.0)", diff --git a/org.eclipse.jgit.junit.ssh/pom.xml b/org.eclipse.jgit.junit.ssh/pom.xml index fe53847b4a..2d4caedf56 100644 --- a/org.eclipse.jgit.junit.ssh/pom.xml +++ b/org.eclipse.jgit.junit.ssh/pom.xml @@ -55,6 +55,16 @@ <groupId>org.apache.sshd</groupId> <artifactId>sshd-sftp</artifactId> <version>${apache-sshd-version}</version> + <exclusions> + <exclusion> + <groupId>org.apache.sshd</groupId> + <artifactId>sshd-core</artifactId> + </exclusion> + <exclusion> + <groupId>org.apache.sshd</groupId> + <artifactId>sshd-common</artifactId> + </exclusion> + </exclusions> </dependency> <dependency> diff --git a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java index 494d2f3bae..a3c5b1202d 100644 --- a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java +++ b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java @@ -45,6 +45,8 @@ import org.eclipse.jgit.util.FileUtils; import org.eclipse.jgit.util.SystemReader; import org.junit.After; import org.junit.Before; +import org.junit.Rule; +import org.junit.rules.TestName; /** * JUnit TestCase with specialized support for temporary local repository. @@ -84,18 +86,33 @@ public abstract class LocalDiskRepositoryTestCase { private File tmp; /** + * The current test name. + */ + @Rule + public TestName currentTest = new TestName(); + + private String getTestName() { + String name = currentTest.getMethodName(); + name = name.replaceAll("[^a-zA-Z0-9]", "_"); + name = name.replaceAll("__+", "_"); + if (name.startsWith("_")) { + name = name.substring(1); + } + return name; + } + + /** * Setup test * * @throws Exception */ @Before public void setUp() throws Exception { - tmp = File.createTempFile("jgit_test_", "_tmp"); + tmp = File.createTempFile("jgit_" + getTestName() + '_', "_tmp"); CleanupThread.deleteOnShutdown(tmp); if (!tmp.delete() || !tmp.mkdir()) { throw new IOException("Cannot create " + tmp); } - mockSystemReader = new MockSystemReader(); SystemReader.setInstance(mockSystemReader); diff --git a/org.eclipse.jgit.lfs.server.test/tst/org/eclipse/jgit/lfs/server/fs/PushTest.java b/org.eclipse.jgit.lfs.server.test/tst/org/eclipse/jgit/lfs/server/fs/PushTest.java index 70c0463e11..06708b334a 100644 --- a/org.eclipse.jgit.lfs.server.test/tst/org/eclipse/jgit/lfs/server/fs/PushTest.java +++ b/org.eclipse.jgit.lfs.server.test/tst/org/eclipse/jgit/lfs/server/fs/PushTest.java @@ -11,6 +11,7 @@ package org.eclipse.jgit.lfs.server.fs; import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import java.io.InputStream; import java.nio.file.Files; @@ -29,6 +30,7 @@ import org.eclipse.jgit.lib.StoredConfig; import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevWalk; import org.eclipse.jgit.storage.file.FileRepositoryBuilder; +import org.eclipse.jgit.transport.RefSpec; import org.eclipse.jgit.transport.URIish; import org.eclipse.jgit.treewalk.TreeWalk; import org.eclipse.jgit.treewalk.filter.PathFilter; @@ -128,4 +130,18 @@ public class PushTest extends LfsServerTest { server.getRequests().toString()); } + @Test + public void testDeleteBranch() throws Exception { + String branch = "new-branch"; + git.branchCreate().setName(branch).call(); + + String destRef = Constants.R_HEADS + branch; + git.push().setRefSpecs(new RefSpec().setSource(branch).setDestination(destRef)).call(); + + // Should not fail on push. + git.branchDelete().setBranchNames(branch).setForce(true).call(); + git.push().setRefSpecs(new RefSpec().setSource(null).setDestination(destRef)).call(); + + assertTrue(server.getRequests().isEmpty()); + } } diff --git a/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/fs/ObjectDownloadListener.java b/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/fs/ObjectDownloadListener.java index cc57947a79..d42701125e 100644 --- a/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/fs/ObjectDownloadListener.java +++ b/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/fs/ObjectDownloadListener.java @@ -81,6 +81,7 @@ public class ObjectDownloadListener implements WriteListener { * * Write file content */ + @SuppressWarnings("Finally") @Override public void onWritePossible() throws IOException { while (out.isReady()) { diff --git a/org.eclipse.jgit.lfs.test/META-INF/MANIFEST.MF b/org.eclipse.jgit.lfs.test/META-INF/MANIFEST.MF index 06f2a891df..0b93af2808 100644 --- a/org.eclipse.jgit.lfs.test/META-INF/MANIFEST.MF +++ b/org.eclipse.jgit.lfs.test/META-INF/MANIFEST.MF @@ -13,9 +13,12 @@ Import-Package: org.eclipse.jgit.api;version="[7.0.0,7.1.0)", org.eclipse.jgit.junit;version="[7.0.0,7.1.0)", org.eclipse.jgit.lfs;version="[7.0.0,7.1.0)", org.eclipse.jgit.lfs.errors;version="[7.0.0,7.1.0)", + org.eclipse.jgit.lfs.internal;version="[7.0.0,7.1.0)", org.eclipse.jgit.lfs.lib;version="[7.0.0,7.1.0)", org.eclipse.jgit.lib;version="[7.0.0,7.1.0)", org.eclipse.jgit.revwalk;version="[7.0.0,7.1.0)", + org.eclipse.jgit.transport;version="[7.0.0,7.1.0)", + org.eclipse.jgit.transport.http;version="[7.0.0,7.1.0)", org.eclipse.jgit.treewalk;version="[7.0.0,7.1.0)", org.eclipse.jgit.treewalk.filter;version="[7.0.0,7.1.0)", org.eclipse.jgit.util;version="[7.0.0,7.1.0)", diff --git a/org.eclipse.jgit.lfs.test/tst/org/eclipse/jgit/lfs/LfsConfigGitTest.java b/org.eclipse.jgit.lfs.test/tst/org/eclipse/jgit/lfs/LfsConfigGitTest.java new file mode 100644 index 0000000000..3ac41571a4 --- /dev/null +++ b/org.eclipse.jgit.lfs.test/tst/org/eclipse/jgit/lfs/LfsConfigGitTest.java @@ -0,0 +1,301 @@ +/* + * Copyright (C) 2022, Matthias Fromme <mfromme@dspace.de> + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Distribution License v. 1.0 which is available at + * https://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: BSD-3-Clause + */ +package org.eclipse.jgit.lfs; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.jgit.api.Git; +import org.eclipse.jgit.api.ResetCommand.ResetType; +import org.eclipse.jgit.attributes.FilterCommand; +import org.eclipse.jgit.attributes.FilterCommandRegistry; +import org.eclipse.jgit.junit.RepositoryTestCase; +import org.eclipse.jgit.lfs.internal.LfsConnectionFactory; +import org.eclipse.jgit.lfs.lib.Constants; +import org.eclipse.jgit.lib.ConfigConstants; +import org.eclipse.jgit.lib.Repository; +import org.eclipse.jgit.lib.StoredConfig; +import org.eclipse.jgit.transport.http.HttpConnection; +import org.eclipse.jgit.util.HttpSupport; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * Test if the lfs config is used in the correct way during checkout. + * + * Two lfs-files are created, one that comes before .gitattributes and + * .lfsconfig in git order (".aaa.txt") and one that comes after ("zzz.txt"). + * + * During checkout/reset it is tested if the correct version of the lfs config + * is used. + * + * TODO: The current behavior seems a little bit strange/unintuitive. Some files + * are checked out before and some after the config files. This leads to the + * behavior, that during a single command the config changes. Since this seems + * to be the same way in native git, the behavior is accepted for now. + * + */ +public class LfsConfigGitTest extends RepositoryTestCase { + + private static final String SMUDGE_NAME = org.eclipse.jgit.lib.Constants.BUILTIN_FILTER_PREFIX + + Constants.ATTR_FILTER_DRIVER_PREFIX + + org.eclipse.jgit.lib.Constants.ATTR_FILTER_TYPE_SMUDGE; + + private static final String LFS_SERVER_URI1 = "https://lfs.server1/test/uri"; + + private static final String EXPECTED_SERVER_URL1 = LFS_SERVER_URI1 + + Protocol.OBJECTS_LFS_ENDPOINT; + + private static final String LFS_SERVER_URI2 = "https://lfs.server2/test/uri"; + + private static final String EXPECTED_SERVER_URL2 = LFS_SERVER_URI2 + + Protocol.OBJECTS_LFS_ENDPOINT; + + private static final String LFS_SERVER_URI3 = "https://lfs.server3/test/uri"; + + private static final String EXPECTED_SERVER_URL3 = LFS_SERVER_URI3 + + Protocol.OBJECTS_LFS_ENDPOINT; + + private static final String FAKE_LFS_POINTER1 = "version https://git-lfs.github.com/spec/v1\n" + + "oid sha256:6ce9fab52ee9a6c4c097def4e049c6acdeba44c99d26e83ba80adec1473c9b2d\n" + + "size 253952\n"; + + private static final String FAKE_LFS_POINTER2 = "version https://git-lfs.github.com/spec/v1\n" + + "oid sha256:a4b711cd989863ae2038758a62672138347abbbae4076a7ad3a545fda7d08f82\n" + + "size 67072\n"; + + private static List<String> checkoutURLs = new ArrayList<>(); + + static class SmudgeFilterMock extends FilterCommand { + public SmudgeFilterMock(Repository db, InputStream in, + OutputStream out) throws IOException { + super(in, out); + HttpConnection lfsServerConn = LfsConnectionFactory.getLfsConnection(db, + HttpSupport.METHOD_POST, Protocol.OPERATION_DOWNLOAD); + checkoutURLs.add(lfsServerConn.getURL().toString()); + } + + @Override + public int run() throws IOException { + // Stupid no impl + in.transferTo(out); + return -1; + } + } + + @BeforeClass + public static void installLfs() { + FilterCommandRegistry.register(SMUDGE_NAME, SmudgeFilterMock::new); + } + + @AfterClass + public static void removeLfs() { + FilterCommandRegistry.unregister(SMUDGE_NAME); + } + + private Git git; + + @Override + @Before + public void setUp() throws Exception { + super.setUp(); + git = new Git(db); + // commit something + writeTrashFile("Test.txt", "Hello world"); + git.add().addFilepattern("Test.txt").call(); + git.commit().setMessage("Initial commit").call(); + // prepare the config for LFS + StoredConfig config = git.getRepository().getConfig(); + config.setString("filter", "lfs", "smudge", SMUDGE_NAME); + config.setString(ConfigConstants.CONFIG_CORE_SECTION, null, + ConfigConstants.CONFIG_KEY_AUTOCRLF, "false"); + config.save(); + + fileBefore = null; + fileAfter = null; + configFile = null; + gitAttributesFile = null; + } + + File fileBefore; + + File fileAfter; + + File configFile; + + File gitAttributesFile; + + private void createLfsFiles(String lfsPointer) throws Exception { + //File to be checked out before lfs config + String fileNameBefore = ".aaa.txt"; + fileBefore = writeTrashFile(fileNameBefore, lfsPointer); + git.add().addFilepattern(fileNameBefore).call(); + + // File to be checked out after lfs config + String fileNameAfter = "zzz.txt"; + fileAfter = writeTrashFile(fileNameAfter, lfsPointer); + git.add().addFilepattern(fileNameAfter).call(); + + git.commit().setMessage("Commit LFS Pointer files").call(); + } + + + private String addLfsConfigFiles(String lfsServerUrl) throws Exception { + // Add config files to the repo + String lfsConfig1 = createLfsConfig(lfsServerUrl); + git.add().addFilepattern(Constants.DOT_LFS_CONFIG).call(); + // Modify gitattributes on second call, to force checkout too. + if (gitAttributesFile == null) { + gitAttributesFile = writeTrashFile(".gitattributes", + "*.txt filter=lfs"); + } else { + gitAttributesFile = writeTrashFile(".gitattributes", + "*.txt filter=lfs\n"); + } + + git.add().addFilepattern(".gitattributes").call(); + git.commit().setMessage("Commit config files").call(); + return lfsConfig1; + } + + private String createLfsConfig(String lfsServerUrl) throws IOException { + String lfsConfig1 = "[lfs]\n url = " + lfsServerUrl; + configFile = writeTrashFile(Constants.DOT_LFS_CONFIG, lfsConfig1); + return lfsConfig1; + } + + @Test + public void checkoutLfsObjects_reset() throws Exception { + createLfsFiles(FAKE_LFS_POINTER1); + String lfsConfig1 = addLfsConfigFiles(LFS_SERVER_URI1); + + // Delete files to force action on reset + assertTrue(configFile.delete()); + assertTrue(fileBefore.delete()); + assertTrue(fileAfter.delete()); + + assertTrue(gitAttributesFile.delete()); + + // create config file with different url + createLfsConfig(LFS_SERVER_URI3); + + checkoutURLs.clear(); + git.reset().setMode(ResetType.HARD).call(); + + checkFile(configFile, lfsConfig1); + checkFile(fileBefore, FAKE_LFS_POINTER1); + checkFile(fileAfter, FAKE_LFS_POINTER1); + + assertEquals(2, checkoutURLs.size()); + // TODO: Should may be EXPECTED_SERVR_URL1 + assertEquals(EXPECTED_SERVER_URL3, checkoutURLs.get(0)); + assertEquals(EXPECTED_SERVER_URL1, checkoutURLs.get(1)); + } + + @Test + public void checkoutLfsObjects_BranchSwitch() throws Exception { + // Create a new branch "URL1" and add config files + git.checkout().setCreateBranch(true).setName("URL1").call(); + + createLfsFiles(FAKE_LFS_POINTER1); + String lfsConfig1 = addLfsConfigFiles(LFS_SERVER_URI1); + + // Create a second new branch "URL2" and add config files + git.checkout().setCreateBranch(true).setName("URL2").call(); + + createLfsFiles(FAKE_LFS_POINTER2); + String lfsConfig2 = addLfsConfigFiles(LFS_SERVER_URI2); + + checkFile(configFile, lfsConfig2); + checkFile(fileBefore, FAKE_LFS_POINTER2); + checkFile(fileAfter, FAKE_LFS_POINTER2); + + checkoutURLs.clear(); + git.checkout().setName("URL1").call(); + + checkFile(configFile, lfsConfig1); + checkFile(fileBefore, FAKE_LFS_POINTER1); + checkFile(fileAfter, FAKE_LFS_POINTER1); + + assertEquals(2, checkoutURLs.size()); + // TODO: Should may be EXPECTED_SERVR_URL1 + assertEquals(EXPECTED_SERVER_URL2, checkoutURLs.get(0)); + assertEquals(EXPECTED_SERVER_URL1, checkoutURLs.get(1)); + + checkoutURLs.clear(); + git.checkout().setName("URL2").call(); + + checkFile(configFile, lfsConfig2); + checkFile(fileBefore, FAKE_LFS_POINTER2); + checkFile(fileAfter, FAKE_LFS_POINTER2); + + assertEquals(2, checkoutURLs.size()); + // TODO: Should may be EXPECTED_SERVR_URL2 + assertEquals(EXPECTED_SERVER_URL1, checkoutURLs.get(0)); + assertEquals(EXPECTED_SERVER_URL2, checkoutURLs.get(1)); + } + + @Test + public void checkoutLfsObjects_BranchSwitch_ModifiedLocal() + throws Exception { + + // Create a new branch "URL1" and add config files + git.checkout().setCreateBranch(true).setName("URL1").call(); + + createLfsFiles(FAKE_LFS_POINTER1); + addLfsConfigFiles(LFS_SERVER_URI1); + + // Create a second new branch "URL2" and add config files + git.checkout().setCreateBranch(true).setName("URL2").call(); + + createLfsFiles(FAKE_LFS_POINTER2); + addLfsConfigFiles(LFS_SERVER_URI1); + + // create config file with different url + assertTrue(configFile.delete()); + String lfsConfig3 = createLfsConfig(LFS_SERVER_URI3); + + checkFile(configFile, lfsConfig3); + checkFile(fileBefore, FAKE_LFS_POINTER2); + checkFile(fileAfter, FAKE_LFS_POINTER2); + + checkoutURLs.clear(); + git.checkout().setName("URL1").call(); + + checkFile(fileBefore, FAKE_LFS_POINTER1); + checkFile(fileAfter, FAKE_LFS_POINTER1); + checkFile(configFile, lfsConfig3); + + assertEquals(2, checkoutURLs.size()); + + assertEquals(EXPECTED_SERVER_URL3, checkoutURLs.get(0)); + assertEquals(EXPECTED_SERVER_URL3, checkoutURLs.get(1)); + + checkoutURLs.clear(); + git.checkout().setName("URL2").call(); + + checkFile(fileBefore, FAKE_LFS_POINTER2); + checkFile(fileAfter, FAKE_LFS_POINTER2); + checkFile(configFile, lfsConfig3); + + assertEquals(2, checkoutURLs.size()); + assertEquals(EXPECTED_SERVER_URL3, checkoutURLs.get(0)); + assertEquals(EXPECTED_SERVER_URL3, checkoutURLs.get(1)); + } +} diff --git a/org.eclipse.jgit.lfs.test/tst/org/eclipse/jgit/lfs/LfsGitTest.java b/org.eclipse.jgit.lfs.test/tst/org/eclipse/jgit/lfs/LfsGitTest.java index 8964310e41..3e83c8ef49 100644 --- a/org.eclipse.jgit.lfs.test/tst/org/eclipse/jgit/lfs/LfsGitTest.java +++ b/org.eclipse.jgit.lfs.test/tst/org/eclipse/jgit/lfs/LfsGitTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021, Thomas Wolf <thomas.wolf@paranor.ch> and others + * Copyright (C) 2021, 2022 Thomas Wolf <thomas.wolf@paranor.ch> and others * * This program and the accompanying materials are made available under the * terms of the Eclipse Distribution License v. 1.0 which is available at @@ -68,6 +68,27 @@ public class LfsGitTest extends RepositoryTestCase { } @Test + public void testBranchSwitch() throws Exception { + git.branchCreate().setName("abranch").call(); + git.checkout().setName("abranch").call(); + File aFile = writeTrashFile("a.bin", "aaa"); + writeTrashFile(".gitattributes", "a.bin filter=lfs"); + git.add().addFilepattern(".").call(); + git.commit().setMessage("acommit").call(); + git.checkout().setName("master").call(); + git.branchCreate().setName("bbranch").call(); + git.checkout().setName("bbranch").call(); + File bFile = writeTrashFile("b.bin", "bbb"); + writeTrashFile(".gitattributes", "b.bin filter=lfs"); + git.add().addFilepattern(".").call(); + git.commit().setMessage("bcommit").call(); + git.checkout().setName("abranch").call(); + checkFile(aFile, "aaa"); + git.checkout().setName("bbranch").call(); + checkFile(bFile, "bbb"); + } + + @Test public void checkoutNonLfsPointer() throws Exception { String content = "size_t\nsome_function(void* ptr);\n"; File smallFile = writeTrashFile("Test.txt", content); diff --git a/org.eclipse.jgit.lfs.test/tst/org/eclipse/jgit/lfs/internal/LfsConnectionFactoryTest.java b/org.eclipse.jgit.lfs.test/tst/org/eclipse/jgit/lfs/internal/LfsConnectionFactoryTest.java new file mode 100644 index 0000000000..badcb7d7e5 --- /dev/null +++ b/org.eclipse.jgit.lfs.test/tst/org/eclipse/jgit/lfs/internal/LfsConnectionFactoryTest.java @@ -0,0 +1,317 @@ +/* + * Copyright (C) 2022 Nail Samatov <sanail@yandex.ru> and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Distribution License v. 1.0 which is available at + * https://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: BSD-3-Clause + */ +package org.eclipse.jgit.lfs.internal; + +import static org.eclipse.jgit.lib.Constants.DEFAULT_REMOTE_NAME; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThrows; +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.io.IOException; +import java.io.PrintWriter; +import java.io.StringWriter; + +import org.eclipse.jgit.api.Git; +import org.eclipse.jgit.api.RemoteAddCommand; +import org.eclipse.jgit.attributes.FilterCommandRegistry; +import org.eclipse.jgit.junit.RepositoryTestCase; +import org.eclipse.jgit.lfs.CleanFilter; +import org.eclipse.jgit.lfs.Protocol; +import org.eclipse.jgit.lfs.SmudgeFilter; +import org.eclipse.jgit.lfs.errors.LfsConfigInvalidException; +import org.eclipse.jgit.lfs.lib.Constants; +import org.eclipse.jgit.lib.ConfigConstants; +import org.eclipse.jgit.lib.Repository; +import org.eclipse.jgit.lib.StoredConfig; +import org.eclipse.jgit.transport.URIish; +import org.eclipse.jgit.transport.http.HttpConnection; +import org.eclipse.jgit.util.HttpSupport; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +public class LfsConnectionFactoryTest extends RepositoryTestCase { + + private static final String SMUDGE_NAME = org.eclipse.jgit.lib.Constants.BUILTIN_FILTER_PREFIX + + Constants.ATTR_FILTER_DRIVER_PREFIX + + org.eclipse.jgit.lib.Constants.ATTR_FILTER_TYPE_SMUDGE; + + private static final String CLEAN_NAME = org.eclipse.jgit.lib.Constants.BUILTIN_FILTER_PREFIX + + Constants.ATTR_FILTER_DRIVER_PREFIX + + org.eclipse.jgit.lib.Constants.ATTR_FILTER_TYPE_CLEAN; + + private final static String LFS_SERVER_URL1 = "https://lfs.server1/test/uri"; + + private final static String LFS_SERVER_URL2 = "https://lfs.server2/test/uri"; + + private final static String ORIGIN_URL = "https://git.server/test/uri"; + + private Git git; + + @BeforeClass + public static void installLfs() { + FilterCommandRegistry.register(SMUDGE_NAME, SmudgeFilter.FACTORY); + FilterCommandRegistry.register(CLEAN_NAME, CleanFilter.FACTORY); + } + + @AfterClass + public static void removeLfs() { + FilterCommandRegistry.unregister(SMUDGE_NAME); + FilterCommandRegistry.unregister(CLEAN_NAME); + } + + @Override + @Before + public void setUp() throws Exception { + super.setUp(); + git = new Git(db); + + // Just to have a non empty repo + writeTrashFile("Test.txt", "Hello world from the LFS Factory Test"); + git.add().addFilepattern("Test.txt").call(); + git.commit().setMessage("Initial commit").call(); + } + + @Test + public void lfsUrlFromRemoteUrlWithDotGit() throws Exception { + addRemoteUrl("https://localhost/repo.git"); + checkLfsUrl("https://localhost/repo.git/info/lfs"); + } + + @Test + public void lfsUrlFromRemoteUrlWithoutDotGit() throws Exception { + addRemoteUrl("https://localhost/repo"); + checkLfsUrl("https://localhost/repo.git/info/lfs"); + } + + @Test + public void lfsUrlFromLocalConfig() throws Exception { + addRemoteUrl("https://localhost/repo"); + + StoredConfig cfg = ((Repository) db).getConfig(); + cfg.setString(ConfigConstants.CONFIG_SECTION_LFS, + null, + ConfigConstants.CONFIG_KEY_URL, + "https://localhost/repo/lfs"); + cfg.save(); + + checkLfsUrl("https://localhost/repo/lfs"); + } + + @Test + public void lfsUrlFromOriginConfig() throws Exception { + addRemoteUrl("https://localhost/repo"); + + StoredConfig cfg = ((Repository) db).getConfig(); + cfg.setString(ConfigConstants.CONFIG_SECTION_LFS, + org.eclipse.jgit.lib.Constants.DEFAULT_REMOTE_NAME, + ConfigConstants.CONFIG_KEY_URL, + "https://localhost/repo/lfs"); + cfg.save(); + + checkLfsUrl("https://localhost/repo/lfs"); + } + + @Test + public void lfsUrlNotConfigured() throws Exception { + assertThrows(LfsConfigInvalidException.class, + () -> LfsConnectionFactory.getLfsConnection(db, + HttpSupport.METHOD_POST, Protocol.OPERATION_DOWNLOAD)); + } + + @Test + public void checkGetLfsConnection_lfsurl_lfsconfigFromWorkingDir() + throws Exception { + writeLfsConfig(); + checkLfsUrl(LFS_SERVER_URL1); + } + + @Test + public void checkGetLfsConnection_lfsurl_lfsconfigFromIndex() + throws Exception { + writeLfsConfig(); + git.add().addFilepattern(Constants.DOT_LFS_CONFIG).call(); + deleteTrashFile(Constants.DOT_LFS_CONFIG); + checkLfsUrl(LFS_SERVER_URL1); + } + + @Test + public void checkGetLfsConnection_lfsurl_lfsconfigFromHEAD() + throws Exception { + writeLfsConfig(); + git.add().addFilepattern(Constants.DOT_LFS_CONFIG).call(); + git.commit().setMessage("Commit LFS Config").call(); + + /* + * reading .lfsconfig from HEAD seems only testable using a bare repo, + * since otherwise working tree or index are used + */ + File directory = createTempDirectory("testBareRepo"); + try (Repository bareRepoDb = Git.cloneRepository() + .setDirectory(directory) + .setURI(db.getDirectory().toURI().toString()).setBare(true) + .call().getRepository()) { + + checkLfsUrl(LFS_SERVER_URL1); + } + } + + @Test + public void checkGetLfsConnection_remote_lfsconfigFromWorkingDir() + throws Exception { + addRemoteUrl(ORIGIN_URL); + writeLfsConfig(LFS_SERVER_URL1, "lfs", DEFAULT_REMOTE_NAME, "url"); + checkLfsUrl(LFS_SERVER_URL1); + } + + /** + * Test the config file precedence. + * + * Checking only with the local repository config is sufficient since from + * that point the "normal" precedence is used. + * + * @throws Exception + */ + @Test + public void checkGetLfsConnection_ConfigFilePrecedence_lfsconfigFromWorkingDir() + throws Exception { + writeLfsConfig(); + checkLfsUrl(LFS_SERVER_URL1); + + StoredConfig config = git.getRepository().getConfig(); + config.setString(ConfigConstants.CONFIG_SECTION_LFS, null, + ConfigConstants.CONFIG_KEY_URL, LFS_SERVER_URL2); + config.save(); + + checkLfsUrl(LFS_SERVER_URL2); + } + + @Test + public void checkGetLfsConnection_InvalidLfsConfig_WorkingDir() + throws Exception { + writeInvalidLfsConfig(); + LfsConfigInvalidException actualException = assertThrows( + LfsConfigInvalidException.class, () -> { + LfsConnectionFactory.getLfsConnection(db, HttpSupport.METHOD_POST, + Protocol.OPERATION_DOWNLOAD); + }); + assertTrue(getStackTrace(actualException) + .contains("Invalid line in config file")); + } + + @Test + public void checkGetLfsConnection_InvalidLfsConfig_Index() + throws Exception { + writeInvalidLfsConfig(); + git.add().addFilepattern(Constants.DOT_LFS_CONFIG).call(); + deleteTrashFile(Constants.DOT_LFS_CONFIG); + LfsConfigInvalidException actualException = assertThrows( + LfsConfigInvalidException.class, () -> { + LfsConnectionFactory.getLfsConnection(db, HttpSupport.METHOD_POST, + Protocol.OPERATION_DOWNLOAD); + }); + assertTrue(getStackTrace(actualException) + .contains("Invalid line in config file")); + } + + @Test + public void checkGetLfsConnection_InvalidLfsConfig_HEAD() throws Exception { + writeInvalidLfsConfig(); + git.add().addFilepattern(Constants.DOT_LFS_CONFIG).call(); + git.commit().setMessage("Commit LFS Config").call(); + + /* + * reading .lfsconfig from HEAD seems only testable using a bare repo, + * since otherwise working tree or index are used + */ + File directory = createTempDirectory("testBareRepo"); + try (Repository bareRepoDb = Git.cloneRepository() + .setDirectory(directory) + .setURI(db.getDirectory().toURI().toString()).setBare(true) + .call().getRepository()) { + LfsConfigInvalidException actualException = assertThrows( + LfsConfigInvalidException.class, + () -> { + LfsConnectionFactory.getLfsConnection(db, + HttpSupport.METHOD_POST, + Protocol.OPERATION_DOWNLOAD); + }); + assertTrue(getStackTrace(actualException) + .contains("Invalid line in config file")); + } + } + + private void addRemoteUrl(String remotUrl) throws Exception { + RemoteAddCommand add = git.remoteAdd(); + add.setUri(new URIish(remotUrl)); + add.setName(org.eclipse.jgit.lib.Constants.DEFAULT_REMOTE_NAME); + add.call(); + } + + /** + * Returns the stack trace of the provided exception as string + * + * @param actualException + * @return The exception stack trace as string + */ + private String getStackTrace(Exception actualException) { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + actualException.printStackTrace(pw); + return sw.toString(); + } + + private void writeLfsConfig() throws IOException { + writeLfsConfig(LFS_SERVER_URL1, "lfs", "url"); + } + + private void writeLfsConfig(String lfsUrl, String section, String name) + throws IOException { + writeLfsConfig(lfsUrl, section, null, name); + } + + /* + * Write simple lfs config with single entry. Do not use FileBasedConfig to + * avoid introducing new dependency (for now). + */ + private void writeLfsConfig(String lfsUrl, String section, + String subsection, String name) throws IOException { + StringBuilder config = new StringBuilder(); + config.append("["); + config.append(section); + if (subsection != null) { + config.append(" \""); + config.append(subsection); + config.append("\""); + } + config.append("]\n"); + config.append(" "); + config.append(name); + config.append(" = "); + config.append(lfsUrl); + writeTrashFile(Constants.DOT_LFS_CONFIG, config.toString()); + } + + private void writeInvalidLfsConfig() throws IOException { + writeTrashFile(Constants.DOT_LFS_CONFIG, + "{lfs]\n url = " + LFS_SERVER_URL1); + } + + private void checkLfsUrl(String lfsUrl) throws IOException { + HttpConnection lfsServerConn; + lfsServerConn = LfsConnectionFactory.getLfsConnection(db, + HttpSupport.METHOD_POST, Protocol.OPERATION_DOWNLOAD); + + assertEquals(lfsUrl + Protocol.OBJECTS_LFS_ENDPOINT, + lfsServerConn.getURL().toString()); + } +} diff --git a/org.eclipse.jgit.lfs/META-INF/MANIFEST.MF b/org.eclipse.jgit.lfs/META-INF/MANIFEST.MF index 1d5f76ffa9..d19f613e57 100644 --- a/org.eclipse.jgit.lfs/META-INF/MANIFEST.MF +++ b/org.eclipse.jgit.lfs/META-INF/MANIFEST.MF @@ -17,6 +17,7 @@ Import-Package: com.google.gson;version="[2.8.2,3.0.0)", org.eclipse.jgit.api.errors;version="[7.0.0,7.1.0)", org.eclipse.jgit.attributes;version="[7.0.0,7.1.0)", org.eclipse.jgit.diff;version="[7.0.0,7.1.0)", + org.eclipse.jgit.dircache;version="[7.0.0,7.1.0)", org.eclipse.jgit.errors;version="[7.0.0,7.1.0)", org.eclipse.jgit.hooks;version="[7.0.0,7.1.0)", org.eclipse.jgit.internal.storage.file;version="[7.0.0,7.1.0)", diff --git a/org.eclipse.jgit.lfs/resources/org/eclipse/jgit/lfs/internal/LfsText.properties b/org.eclipse.jgit.lfs/resources/org/eclipse/jgit/lfs/internal/LfsText.properties index 0e00f146ae..c4c0dacf42 100644 --- a/org.eclipse.jgit.lfs/resources/org/eclipse/jgit/lfs/internal/LfsText.properties +++ b/org.eclipse.jgit.lfs/resources/org/eclipse/jgit/lfs/internal/LfsText.properties @@ -1,19 +1,18 @@ corruptLongObject=The content hash ''{0}'' of the long object ''{1}'' doesn''t match its id, the corrupt object will be deleted. -incorrectLONG_OBJECT_ID_LENGTH=Incorrect LONG_OBJECT_ID_LENGTH. -inconsistentMediafileLength=Mediafile {0} has unexpected length; expected {1} but found {2}. +dotLfsConfigReadFailed=Reading .lfsconfig failed inconsistentContentLength=Unexpected content length reported by LFS server ({0}), expected {1} but reported was {2} +inconsistentMediafileLength=Mediafile {0} has unexpected length; expected {1} but found {2}. +incorrectLONG_OBJECT_ID_LENGTH=Incorrect LONG_OBJECT_ID_LENGTH. invalidLongId=Invalid id: {0} invalidLongIdLength=Invalid id length {0}; should be {1} +lfsFailedToGetRepository=failed to get repository {0} +lfsNoDownloadUrl=Need to download object from LFS server but couldn't determine LFS server URL +lfsUnauthorized=Not authorized to perform operation {0} on repository {1} lfsUnavailable=LFS is not available for repository {0} +missingLocalObject=Local Object {0} is missing protocolError=LFS Protocol Error {0}: {1} -requiredHashFunctionNotAvailable=Required hash function {0} not available. repositoryNotFound=Repository {0} not found repositoryReadOnly=Repository {0} is read-only -lfsUnavailable=LFS is not available for repository {0} -lfsUnathorized=Not authorized to perform operation {0} on repository {1} -lfsFailedToGetRepository=failed to get repository {0} -lfsNoDownloadUrl="Need to download object from LFS server but couldn't determine LFS server URL" +requiredHashFunctionNotAvailable=Required hash function {0} not available. serverFailure=When trying to open a connection to {0} the server responded with an error code. rc={1} -wrongAmoutOfDataReceived=While downloading data from the content server {0} {1} bytes have been received while {2} have been expected -userConfigInvalid="User config file {0} invalid {1}" -missingLocalObject="Local Object {0} is missing"
\ No newline at end of file +wrongAmountOfDataReceived=While downloading data from the content server {0} {1} bytes have been received while {2} have been expected
\ No newline at end of file diff --git a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/LfsPrePushHook.java b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/LfsPrePushHook.java index d6ce855794..9b3d60812a 100644 --- a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/LfsPrePushHook.java +++ b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/LfsPrePushHook.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017, Markus Duft <markus.duft@ssi-schaefer.com> and others + * Copyright (C) 2017, 2022 Markus Duft <markus.duft@ssi-schaefer.com> and others * * This program and the accompanying materials are made available under the * terms of the Eclipse Distribution License v. 1.0 which is available at @@ -101,8 +101,10 @@ public class LfsPrePushHook extends PrePushHook { } HttpConnection api = LfsConnectionFactory.getLfsConnection( getRepository(), METHOD_POST, OPERATION_UPLOAD); - Map<String, LfsPointer> oid2ptr = requestBatchUpload(api, toPush); - uploadContents(api, oid2ptr); + if (!isDryRun()) { + Map<String, LfsPointer> oid2ptr = requestBatchUpload(api, toPush); + uploadContents(api, oid2ptr); + } return EMPTY; } @@ -113,6 +115,9 @@ public class LfsPrePushHook extends PrePushHook { try (ObjectWalk walk = new ObjectWalk(getRepository())) { for (RemoteRefUpdate up : refs) { + if (up.isDelete()) { + continue; + } walk.setRewriteParents(false); excludeRemoteRefs(walk); walk.markStart(walk.parseCommit(up.getNewObjectId())); diff --git a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/SmudgeFilter.java b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/SmudgeFilter.java index 3411887567..c26a1bfbb3 100644 --- a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/SmudgeFilter.java +++ b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/SmudgeFilter.java @@ -205,7 +205,7 @@ public class SmudgeFilter extends FilterCommand { long bytesCopied = Files.copy(contentIn, path); if (bytesCopied != o.size) { throw new IOException(MessageFormat.format( - LfsText.get().wrongAmoutOfDataReceived, + LfsText.get().wrongAmountOfDataReceived, contentServerConn.getURL(), Long.valueOf(bytesCopied), Long.valueOf(o.size))); diff --git a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/errors/LfsUnauthorized.java b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/errors/LfsUnauthorized.java index 36889db8a6..0dc6aeab29 100644 --- a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/errors/LfsUnauthorized.java +++ b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/errors/LfsUnauthorized.java @@ -31,7 +31,7 @@ public class LfsUnauthorized extends LfsException { * the repository name. */ public LfsUnauthorized(String operation, String name) { - super(MessageFormat.format(LfsText.get().lfsUnathorized, operation, + super(MessageFormat.format(LfsText.get().lfsUnauthorized, operation, name)); } } diff --git a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/internal/LfsConfig.java b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/internal/LfsConfig.java new file mode 100644 index 0000000000..857ccbe056 --- /dev/null +++ b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/internal/LfsConfig.java @@ -0,0 +1,220 @@ +/* + * Copyright (C) 2022, Matthias Fromme <mfromme@dspace.de> + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Distribution License v. 1.0 which is available at + * https://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: BSD-3-Clause + */ +package org.eclipse.jgit.lfs.internal; + +import java.io.File; +import java.io.IOException; + +import org.eclipse.jgit.annotations.Nullable; +import org.eclipse.jgit.dircache.DirCacheEntry; +import org.eclipse.jgit.errors.ConfigInvalidException; +import org.eclipse.jgit.lfs.errors.LfsConfigInvalidException; +import org.eclipse.jgit.lfs.lib.Constants; +import org.eclipse.jgit.lib.BlobBasedConfig; +import org.eclipse.jgit.lib.Config; +import org.eclipse.jgit.lib.ObjectId; +import org.eclipse.jgit.lib.Repository; +import org.eclipse.jgit.revwalk.RevCommit; +import org.eclipse.jgit.revwalk.RevTree; +import org.eclipse.jgit.revwalk.RevWalk; +import org.eclipse.jgit.storage.file.FileBasedConfig; +import org.eclipse.jgit.treewalk.TreeWalk; + +import static org.eclipse.jgit.lib.Constants.HEAD; + +/** + * Encapsulate access to the {@code .lfsconfig}. + * <p> + * According to the git lfs documentation the order to find the + * {@code .lfsconfig} file is: + * </p> + * <ol> + * <li>in the root of the working tree</li> + * <li>in the index</li> + * <li>in the HEAD; for bare repositories this is the only place that is + * searched</li> + * </ol> + * <p> + * Values from the {@code .lfsconfig} are used only if not specified in another + * git config file to allow local override without modifiction of a committed + * file. + * </p> + * + * @see <a href= + * "https://github.com/git-lfs/git-lfs/blob/main/docs/man/git-lfs-config.5.ronn">Configuration + * options for git-lfs</a> + */ +public class LfsConfig { + private Repository db; + private Config delegate; + + /** + * Create a new instance of the LfsConfig. + * + * @param db + * the associated repo + */ + public LfsConfig(Repository db) { + this.db = db; + } + + /** + * Getter for the delegate to allow lazy initialization. + * + * @return the delegate {@link Config} + * @throws IOException + */ + private Config getDelegate() throws IOException { + if (delegate == null) { + delegate = this.load(); + } + return delegate; + } + + /** + * Read the .lfsconfig file from the repository + * + * An empty config is returned be empty if no lfs config exists. + * + * @return The loaded lfs config + * + * @throws IOException + */ + private Config load() throws IOException { + Config result = null; + + if (!db.isBare()) { + result = loadFromWorkingTree(); + if (result == null) { + result = loadFromIndex(); + } + } + + if (result == null) { + result = loadFromHead(); + } + + if (result == null) { + result = emptyConfig(); + } + + return result; + } + + /** + * Try to read the lfs config from a file called .lfsconfig at the top level + * of the working tree. + * + * @return the config, or <code>null</code> + * @throws IOException + */ + @Nullable + private Config loadFromWorkingTree() + throws IOException { + File lfsConfig = db.getFS().resolve(db.getWorkTree(), + Constants.DOT_LFS_CONFIG); + if (lfsConfig.isFile()) { + FileBasedConfig config = new FileBasedConfig(lfsConfig, db.getFS()); + try { + config.load(); + return config; + } catch (ConfigInvalidException e) { + throw new LfsConfigInvalidException( + LfsText.get().dotLfsConfigReadFailed, e); + } + } + return null; + } + + /** + * Try to read the lfs config from an entry called .lfsconfig contained in + * the index. + * + * @return the config, or <code>null</code> if the entry does not exist + * @throws IOException + */ + @Nullable + private Config loadFromIndex() + throws IOException { + try { + DirCacheEntry entry = db.readDirCache() + .getEntry(Constants.DOT_LFS_CONFIG); + if (entry != null) { + return new BlobBasedConfig(null, db, entry.getObjectId()); + } + } catch (ConfigInvalidException e) { + throw new LfsConfigInvalidException( + LfsText.get().dotLfsConfigReadFailed, e); + } + return null; + } + + /** + * Try to read the lfs config from an entry called .lfsconfig contained in + * the head revision. + * + * @return the config, or <code>null</code> if the file does not exist + * @throws IOException + */ + @Nullable + private Config loadFromHead() throws IOException { + try (RevWalk revWalk = new RevWalk(db)) { + ObjectId headCommitId = db.resolve(HEAD); + if (headCommitId == null) { + return null; + } + RevCommit commit = revWalk.parseCommit(headCommitId); + RevTree tree = commit.getTree(); + TreeWalk treewalk = TreeWalk.forPath(db, Constants.DOT_LFS_CONFIG, + tree); + if (treewalk != null) { + return new BlobBasedConfig(null, db, treewalk.getObjectId(0)); + } + } catch (ConfigInvalidException e) { + throw new LfsConfigInvalidException( + LfsText.get().dotLfsConfigReadFailed, e); + } + return null; + } + + /** + * Create an empty config as fallback to avoid null pointer checks. + * + * @return an empty config + */ + private Config emptyConfig() { + return new Config(); + } + + /** + * Get string value or null if not found. + * + * First tries to find the value in the git config files. If not found tries + * to find data in .lfsconfig. + * + * @param section + * the section + * @param subsection + * the subsection for the value + * @param name + * the key name + * @return a String value from the config, <code>null</code> if not found + * @throws IOException + */ + @Nullable + public String getString(final String section, final String subsection, + final String name) throws IOException { + String result = db.getConfig().getString(section, subsection, name); + if (result == null) { + result = getDelegate().getString(section, subsection, name); + } + return result; + } +} diff --git a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/internal/LfsConnectionFactory.java b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/internal/LfsConnectionFactory.java index e221913bea..12b688d157 100644 --- a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/internal/LfsConnectionFactory.java +++ b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/internal/LfsConnectionFactory.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017, Markus Duft <markus.duft@ssi-schaefer.com> and others + * Copyright (C) 2017, 2022 Markus Duft <markus.duft@ssi-schaefer.com> and others * * This program and the accompanying materials are made available under the * terms of the Eclipse Distribution License v. 1.0 which is available at @@ -39,12 +39,12 @@ import org.eclipse.jgit.transport.URIish; import org.eclipse.jgit.transport.http.HttpConnection; import org.eclipse.jgit.util.HttpSupport; import org.eclipse.jgit.util.SshSupport; +import org.eclipse.jgit.util.StringUtils; /** * Provides means to get a valid LFS connection for a given repository. */ public class LfsConnectionFactory { - private static final int SSH_AUTH_TIMEOUT_SECONDS = 30; private static final String SCHEME_HTTPS = "https"; //$NON-NLS-1$ private static final String SCHEME_SSH = "ssh"; //$NON-NLS-1$ @@ -64,7 +64,7 @@ public class LfsConnectionFactory { * be used for * @param purpose * the action, e.g. Protocol.OPERATION_DOWNLOAD - * @return the url for the lfs server. e.g. + * @return the connection for the lfs server. e.g. * "https://github.com/github/git-lfs.git/info/lfs" * @throws IOException */ @@ -92,13 +92,30 @@ public class LfsConnectionFactory { return connection; } + /** + * Get LFS Server URL. + * + * @param db + * the repository to work with + * @param purpose + * the action, e.g. Protocol.OPERATION_DOWNLOAD + * @param additionalHeaders + * additional headers that can be used to connect to LFS server + * @return the URL for the LFS server. e.g. + * "https://github.com/github/git-lfs.git/info/lfs" + * @throws IOException + * if the LFS config is invalid or cannot be accessed + * @see <a href= + * "https://github.com/git-lfs/git-lfs/blob/main/docs/api/server-discovery.md"> + * Server Discovery documentation</a> + */ private static String getLfsUrl(Repository db, String purpose, Map<String, String> additionalHeaders) - throws LfsConfigInvalidException { - StoredConfig config = db.getConfig(); + throws IOException { + LfsConfig config = new LfsConfig(db); String lfsUrl = config.getString(ConfigConstants.CONFIG_SECTION_LFS, - null, - ConfigConstants.CONFIG_KEY_URL); + null, ConfigConstants.CONFIG_KEY_URL); + Exception ex = null; if (lfsUrl == null) { String remoteUrl = null; @@ -106,6 +123,7 @@ public class LfsConnectionFactory { lfsUrl = config.getString(ConfigConstants.CONFIG_SECTION_LFS, remote, ConfigConstants.CONFIG_KEY_URL); + // This could be done better (more precise logic), but according // to https://github.com/git-lfs/git-lfs/issues/1759 git-lfs // generally only supports 'origin' in an integrated workflow. @@ -125,8 +143,6 @@ public class LfsConnectionFactory { | CommandFailedException e) { ex = e; } - } else { - lfsUrl = lfsUrl + Protocol.INFO_LFS_ENDPOINT; } } if (lfsUrl == null) { @@ -149,7 +165,8 @@ public class LfsConnectionFactory { additionalHeaders.putAll(action.header); return action.href; } - return remoteUrl + Protocol.INFO_LFS_ENDPOINT; + return StringUtils.nameWithDotGit(remoteUrl) + + Protocol.INFO_LFS_ENDPOINT; } private static Protocol.ExpiringAction getSshAuthentication( diff --git a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/internal/LfsText.java b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/internal/LfsText.java index 1ca37a9f66..8ef8f59f93 100644 --- a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/internal/LfsText.java +++ b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/internal/LfsText.java @@ -28,21 +28,21 @@ public class LfsText extends TranslationBundle { // @formatter:off /***/ public String corruptLongObject; - /***/ public String inconsistentMediafileLength; + /***/ public String dotLfsConfigReadFailed; /***/ public String inconsistentContentLength; + /***/ public String inconsistentMediafileLength; /***/ public String incorrectLONG_OBJECT_ID_LENGTH; /***/ public String invalidLongId; /***/ public String invalidLongIdLength; + /***/ public String lfsFailedToGetRepository; + /***/ public String lfsNoDownloadUrl; + /***/ public String lfsUnauthorized; /***/ public String lfsUnavailable; + /***/ public String missingLocalObject; /***/ public String protocolError; - /***/ public String requiredHashFunctionNotAvailable; /***/ public String repositoryNotFound; /***/ public String repositoryReadOnly; - /***/ public String lfsUnathorized; - /***/ public String lfsFailedToGetRepository; - /***/ public String lfsNoDownloadUrl; + /***/ public String requiredHashFunctionNotAvailable; /***/ public String serverFailure; - /***/ public String wrongAmoutOfDataReceived; - /***/ public String userConfigInvalid; - /***/ public String missingLocalObject; + /***/ public String wrongAmountOfDataReceived; } diff --git a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/lib/Constants.java b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/lib/Constants.java index 3212a63504..9b41ec31f1 100644 --- a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/lib/Constants.java +++ b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/lib/Constants.java @@ -82,6 +82,13 @@ public final class Constants { public static final String ATTR_FILTER_DRIVER_PREFIX = "lfs/"; /** + * Config file name for lfs specific configuration + * + * @since 6.1 + */ + public static final String DOT_LFS_CONFIG = ".lfsconfig"; + + /** * Create a new digest function for objects. * * @return a new digest object. diff --git a/org.eclipse.jgit.packaging/.settings/org.eclipse.core.resources.prefs b/org.eclipse.jgit.packaging/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000000..99f26c0203 --- /dev/null +++ b/org.eclipse.jgit.packaging/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/<project>=UTF-8 diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.gpg.bc.feature/.settings/org.eclipse.core.resources.prefs b/org.eclipse.jgit.packaging/org.eclipse.jgit.gpg.bc.feature/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000000..99f26c0203 --- /dev/null +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.gpg.bc.feature/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/<project>=UTF-8 diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.repository/category.xml b/org.eclipse.jgit.packaging/org.eclipse.jgit.repository/category.xml index af9523fd4f..7fa2b837e7 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.repository/category.xml +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.repository/category.xml @@ -165,12 +165,6 @@ <bundle id="org.apache.httpcomponents.httpcore.source"> <category name="JGit-dependency-bundles"/> </bundle> - <bundle id="org.apache.log4j"> - <category name="JGit-dependency-bundles"/> - </bundle> - <bundle id="org.apache.log4j.source"> - <category name="JGit-dependency-bundles"/> - </bundle> <bundle id="org.apache.sshd.osgi"> <category name="JGit-dependency-bundles"/> </bundle> @@ -219,10 +213,10 @@ <bundle id="org.slf4j.api.source"> <category name="JGit-dependency-bundles"/> </bundle> - <bundle id="org.slf4j.binding.log4j12"> + <bundle id="org.slf4j.binding.simple"> <category name="JGit-dependency-bundles"/> </bundle> - <bundle id="org.slf4j.binding.log4j12.source"> + <bundle id="org.slf4j.binding.simple.source"> <category name="JGit-dependency-bundles"/> </bundle> <bundle id="org.tukaani.xz"> diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.ssh.jsch.feature/.settings/org.eclipse.core.resources.prefs b/org.eclipse.jgit.packaging/org.eclipse.jgit.ssh.jsch.feature/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000000..99f26c0203 --- /dev/null +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.ssh.jsch.feature/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/<project>=UTF-8 diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/.settings/org.eclipse.core.resources.prefs b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000000..99f26c0203 --- /dev/null +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/<project>=UTF-8 diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.17.target b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.17.target index 6d960335dc..3d4f2378d1 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.17.target +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.17.target @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8" standalone="no"?> <?pde?> <!-- generated with https://github.com/eclipse-cbi/targetplatform-dsl --> -<target name="jgit-4.17" sequenceNumber="1638648728"> +<target name="jgit-4.17" sequenceNumber="1654550635"> <locations> <location includeMode="slicer" includeAllPlatforms="false" includeSource="true" includeConfigurePhase="true" type="InstallableUnit"> <unit id="jakarta.servlet-api" version="4.0.0"/> @@ -23,12 +23,12 @@ <repository id="jetty-10.0.x" location="https://download.eclipse.org/eclipse/jetty/10.0.6/"/> </location> <location includeMode="slicer" includeAllPlatforms="false" includeSource="true" includeConfigurePhase="true" type="InstallableUnit"> - <unit id="com.google.gson" version="2.8.8.v20211029-0838"/> - <unit id="com.google.gson.source" version="2.8.8.v20211029-0838"/> + <unit id="com.google.gson" version="2.8.9.v20220111-1409"/> + <unit id="com.google.gson.source" version="2.8.9.v20220111-1409"/> <unit id="com.jcraft.jsch" version="0.1.55.v20190404-1902"/> <unit id="com.jcraft.jsch.source" version="0.1.55.v20190404-1902"/> - <unit id="com.jcraft.jzlib" version="1.1.1.v201205102305"/> - <unit id="com.jcraft.jzlib.source" version="1.1.1.v201205102305"/> + <unit id="com.jcraft.jzlib" version="1.1.3.v20220502-1820"/> + <unit id="com.jcraft.jzlib.source" version="1.1.3.v20220502-1820"/> <unit id="com.sun.jna" version="5.8.0.v20210503-0343"/> <unit id="com.sun.jna.source" version="5.8.0.v20210503-0343"/> <unit id="com.sun.jna.platform" version="5.8.0.v20210406-1004"/> @@ -39,8 +39,8 @@ <unit id="net.bytebuddy.byte-buddy-agent" version="1.9.0.v20181106-1534"/> <unit id="net.bytebuddy.byte-buddy-agent.source" version="1.9.0.v20181106-1534"/> <unit id="net.bytebuddy.byte-buddy.source" version="1.9.0.v20181107-1410"/> - <unit id="net.i2p.crypto.eddsa" version="0.3.0.v20210923-1401"/> - <unit id="net.i2p.crypto.eddsa.source" version="0.3.0.v20210923-1401"/> + <unit id="net.i2p.crypto.eddsa" version="0.3.0.v20220506-1020"/> + <unit id="net.i2p.crypto.eddsa.source" version="0.3.0.v20220506-1020"/> <unit id="org.apache.ant" version="1.10.12.v20211102-1452"/> <unit id="org.apache.ant.source" version="1.10.12.v20211102-1452"/> <unit id="org.apache.commons.codec" version="1.14.0.v20200818-1422"/> @@ -51,24 +51,22 @@ <unit id="org.apache.commons.logging.source" version="1.2.0.v20180409-1502"/> <unit id="org.apache.httpcomponents.httpclient" version="4.5.13.v20210128-2225"/> <unit id="org.apache.httpcomponents.httpclient.source" version="4.5.13.v20210128-2225"/> - <unit id="org.apache.httpcomponents.httpcore" version="4.4.14.v20210128-2225"/> - <unit id="org.apache.httpcomponents.httpcore.source" version="4.4.14.v20210128-2225"/> - <unit id="org.apache.log4j" version="1.2.15.v201012070815"/> - <unit id="org.apache.log4j.source" version="1.2.15.v201012070815"/> - <unit id="org.apache.sshd.osgi" version="2.7.0.v20210623-0618"/> - <unit id="org.apache.sshd.osgi.source" version="2.7.0.v20210623-0618"/> - <unit id="org.apache.sshd.sftp" version="2.7.0.v20210623-0618"/> - <unit id="org.apache.sshd.sftp.source" version="2.7.0.v20210623-0618"/> + <unit id="org.apache.httpcomponents.httpcore" version="4.4.15.v20220209-2345"/> + <unit id="org.apache.httpcomponents.httpcore.source" version="4.4.15.v20220209-2345"/> + <unit id="org.apache.sshd.osgi" version="2.8.0.v20211227-1750"/> + <unit id="org.apache.sshd.osgi.source" version="2.8.0.v20211227-1750"/> + <unit id="org.apache.sshd.sftp" version="2.8.0.v20211227-1750"/> + <unit id="org.apache.sshd.sftp.source" version="2.8.0.v20211227-1750"/> <unit id="org.assertj" version="3.20.2.v20210706-1104"/> <unit id="org.assertj.source" version="3.20.2.v20210706-1104"/> - <unit id="org.bouncycastle.bcpg" version="1.69.0.v20210713-1924"/> - <unit id="org.bouncycastle.bcpg.source" version="1.69.0.v20210713-1924"/> - <unit id="org.bouncycastle.bcpkix" version="1.69.0.v20210713-1924"/> - <unit id="org.bouncycastle.bcpkix.source" version="1.69.0.v20210713-1924"/> - <unit id="org.bouncycastle.bcprov" version="1.69.0.v20210923-1401"/> - <unit id="org.bouncycastle.bcprov.source" version="1.69.0.v20210923-1401"/> - <unit id="org.bouncycastle.bcutil" version="1.69.0.v20210713-1924"/> - <unit id="org.bouncycastle.bcutil.source" version="1.69.0.v20210713-1924"/> + <unit id="org.bouncycastle.bcpg" version="1.70.0.v20220507-1208"/> + <unit id="org.bouncycastle.bcpg.source" version="1.70.0.v20220507-1208"/> + <unit id="org.bouncycastle.bcpkix" version="1.70.0.v20220105-1522"/> + <unit id="org.bouncycastle.bcpkix.source" version="1.70.0.v20220105-1522"/> + <unit id="org.bouncycastle.bcprov" version="1.70.0.v20220507-1208"/> + <unit id="org.bouncycastle.bcprov.source" version="1.70.0.v20220507-1208"/> + <unit id="org.bouncycastle.bcutil" version="1.70.0.v20220105-1522"/> + <unit id="org.bouncycastle.bcutil.source" version="1.70.0.v20220105-1522"/> <unit id="org.hamcrest" version="2.2.0.v20210711-0821"/> <unit id="org.hamcrest.source" version="2.2.0.v20210711-0821"/> <unit id="org.hamcrest.core" version="1.3.0.v20180420-1519"/> @@ -85,11 +83,11 @@ <unit id="org.objenesis.source" version="2.6.0.v20180420-1519"/> <unit id="org.slf4j.api" version="1.7.30.v20200204-2150"/> <unit id="org.slf4j.api.source" version="1.7.30.v20200204-2150"/> - <unit id="org.slf4j.binding.log4j12" version="1.7.30.v20201108-2042"/> - <unit id="org.slf4j.binding.log4j12.source" version="1.7.30.v20201108-2042"/> + <unit id="org.slf4j.binding.simple" version="1.7.30.v20200204-2150"/> + <unit id="org.slf4j.binding.simple.source" version="1.7.30.v20200204-2150"/> <unit id="org.tukaani.xz" version="1.9.0.v20210624-1259"/> <unit id="org.tukaani.xz.source" version="1.9.0.v20210624-1259"/> - <repository location="https://download.eclipse.org/tools/orbit/downloads/drops/R20211122181901/repository"/> + <repository location="https://download.eclipse.org/tools/orbit/downloads/drops/R20220531185310/repository"/> </location> <location includeMode="slicer" includeAllPlatforms="false" includeSource="true" includeConfigurePhase="true" type="InstallableUnit"> <unit id="org.eclipse.osgi" version="0.0.0"/> diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.17.tpd b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.17.tpd index cd364d3563..9c824c5fd4 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.17.tpd +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.17.tpd @@ -1,7 +1,7 @@ target "jgit-4.17" with source configurePhase include "projects/jetty-10.0.x.tpd" -include "orbit/R20211122181901-2021-12.tpd" +include "orbit/R20220531185310-2022-06.tpd" location "https://download.eclipse.org/releases/2020-09/" { org.eclipse.osgi lazy diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.18.target b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.18.target index cbe26bbf16..603fefbadf 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.18.target +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.18.target @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8" standalone="no"?> <?pde?> <!-- generated with https://github.com/eclipse-cbi/targetplatform-dsl --> -<target name="jgit-4.18" sequenceNumber="1638648728"> +<target name="jgit-4.18" sequenceNumber="1654550635"> <locations> <location includeMode="slicer" includeAllPlatforms="false" includeSource="true" includeConfigurePhase="true" type="InstallableUnit"> <unit id="jakarta.servlet-api" version="4.0.0"/> @@ -23,12 +23,12 @@ <repository id="jetty-10.0.x" location="https://download.eclipse.org/eclipse/jetty/10.0.6/"/> </location> <location includeMode="slicer" includeAllPlatforms="false" includeSource="true" includeConfigurePhase="true" type="InstallableUnit"> - <unit id="com.google.gson" version="2.8.8.v20211029-0838"/> - <unit id="com.google.gson.source" version="2.8.8.v20211029-0838"/> + <unit id="com.google.gson" version="2.8.9.v20220111-1409"/> + <unit id="com.google.gson.source" version="2.8.9.v20220111-1409"/> <unit id="com.jcraft.jsch" version="0.1.55.v20190404-1902"/> <unit id="com.jcraft.jsch.source" version="0.1.55.v20190404-1902"/> - <unit id="com.jcraft.jzlib" version="1.1.1.v201205102305"/> - <unit id="com.jcraft.jzlib.source" version="1.1.1.v201205102305"/> + <unit id="com.jcraft.jzlib" version="1.1.3.v20220502-1820"/> + <unit id="com.jcraft.jzlib.source" version="1.1.3.v20220502-1820"/> <unit id="com.sun.jna" version="5.8.0.v20210503-0343"/> <unit id="com.sun.jna.source" version="5.8.0.v20210503-0343"/> <unit id="com.sun.jna.platform" version="5.8.0.v20210406-1004"/> @@ -39,8 +39,8 @@ <unit id="net.bytebuddy.byte-buddy-agent" version="1.9.0.v20181106-1534"/> <unit id="net.bytebuddy.byte-buddy-agent.source" version="1.9.0.v20181106-1534"/> <unit id="net.bytebuddy.byte-buddy.source" version="1.9.0.v20181107-1410"/> - <unit id="net.i2p.crypto.eddsa" version="0.3.0.v20210923-1401"/> - <unit id="net.i2p.crypto.eddsa.source" version="0.3.0.v20210923-1401"/> + <unit id="net.i2p.crypto.eddsa" version="0.3.0.v20220506-1020"/> + <unit id="net.i2p.crypto.eddsa.source" version="0.3.0.v20220506-1020"/> <unit id="org.apache.ant" version="1.10.12.v20211102-1452"/> <unit id="org.apache.ant.source" version="1.10.12.v20211102-1452"/> <unit id="org.apache.commons.codec" version="1.14.0.v20200818-1422"/> @@ -51,24 +51,22 @@ <unit id="org.apache.commons.logging.source" version="1.2.0.v20180409-1502"/> <unit id="org.apache.httpcomponents.httpclient" version="4.5.13.v20210128-2225"/> <unit id="org.apache.httpcomponents.httpclient.source" version="4.5.13.v20210128-2225"/> - <unit id="org.apache.httpcomponents.httpcore" version="4.4.14.v20210128-2225"/> - <unit id="org.apache.httpcomponents.httpcore.source" version="4.4.14.v20210128-2225"/> - <unit id="org.apache.log4j" version="1.2.15.v201012070815"/> - <unit id="org.apache.log4j.source" version="1.2.15.v201012070815"/> - <unit id="org.apache.sshd.osgi" version="2.7.0.v20210623-0618"/> - <unit id="org.apache.sshd.osgi.source" version="2.7.0.v20210623-0618"/> - <unit id="org.apache.sshd.sftp" version="2.7.0.v20210623-0618"/> - <unit id="org.apache.sshd.sftp.source" version="2.7.0.v20210623-0618"/> + <unit id="org.apache.httpcomponents.httpcore" version="4.4.15.v20220209-2345"/> + <unit id="org.apache.httpcomponents.httpcore.source" version="4.4.15.v20220209-2345"/> + <unit id="org.apache.sshd.osgi" version="2.8.0.v20211227-1750"/> + <unit id="org.apache.sshd.osgi.source" version="2.8.0.v20211227-1750"/> + <unit id="org.apache.sshd.sftp" version="2.8.0.v20211227-1750"/> + <unit id="org.apache.sshd.sftp.source" version="2.8.0.v20211227-1750"/> <unit id="org.assertj" version="3.20.2.v20210706-1104"/> <unit id="org.assertj.source" version="3.20.2.v20210706-1104"/> - <unit id="org.bouncycastle.bcpg" version="1.69.0.v20210713-1924"/> - <unit id="org.bouncycastle.bcpg.source" version="1.69.0.v20210713-1924"/> - <unit id="org.bouncycastle.bcpkix" version="1.69.0.v20210713-1924"/> - <unit id="org.bouncycastle.bcpkix.source" version="1.69.0.v20210713-1924"/> - <unit id="org.bouncycastle.bcprov" version="1.69.0.v20210923-1401"/> - <unit id="org.bouncycastle.bcprov.source" version="1.69.0.v20210923-1401"/> - <unit id="org.bouncycastle.bcutil" version="1.69.0.v20210713-1924"/> - <unit id="org.bouncycastle.bcutil.source" version="1.69.0.v20210713-1924"/> + <unit id="org.bouncycastle.bcpg" version="1.70.0.v20220507-1208"/> + <unit id="org.bouncycastle.bcpg.source" version="1.70.0.v20220507-1208"/> + <unit id="org.bouncycastle.bcpkix" version="1.70.0.v20220105-1522"/> + <unit id="org.bouncycastle.bcpkix.source" version="1.70.0.v20220105-1522"/> + <unit id="org.bouncycastle.bcprov" version="1.70.0.v20220507-1208"/> + <unit id="org.bouncycastle.bcprov.source" version="1.70.0.v20220507-1208"/> + <unit id="org.bouncycastle.bcutil" version="1.70.0.v20220105-1522"/> + <unit id="org.bouncycastle.bcutil.source" version="1.70.0.v20220105-1522"/> <unit id="org.hamcrest" version="2.2.0.v20210711-0821"/> <unit id="org.hamcrest.source" version="2.2.0.v20210711-0821"/> <unit id="org.hamcrest.core" version="1.3.0.v20180420-1519"/> @@ -85,11 +83,11 @@ <unit id="org.objenesis.source" version="2.6.0.v20180420-1519"/> <unit id="org.slf4j.api" version="1.7.30.v20200204-2150"/> <unit id="org.slf4j.api.source" version="1.7.30.v20200204-2150"/> - <unit id="org.slf4j.binding.log4j12" version="1.7.30.v20201108-2042"/> - <unit id="org.slf4j.binding.log4j12.source" version="1.7.30.v20201108-2042"/> + <unit id="org.slf4j.binding.simple" version="1.7.30.v20200204-2150"/> + <unit id="org.slf4j.binding.simple.source" version="1.7.30.v20200204-2150"/> <unit id="org.tukaani.xz" version="1.9.0.v20210624-1259"/> <unit id="org.tukaani.xz.source" version="1.9.0.v20210624-1259"/> - <repository location="https://download.eclipse.org/tools/orbit/downloads/drops/R20211122181901/repository"/> + <repository location="https://download.eclipse.org/tools/orbit/downloads/drops/R20220531185310/repository"/> </location> <location includeMode="slicer" includeAllPlatforms="false" includeSource="true" includeConfigurePhase="true" type="InstallableUnit"> <unit id="org.eclipse.osgi" version="0.0.0"/> diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.18.tpd b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.18.tpd index 27f3471c1a..1dcdd9bebb 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.18.tpd +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.18.tpd @@ -1,7 +1,7 @@ target "jgit-4.18" with source configurePhase include "projects/jetty-10.0.x.tpd" -include "orbit/R20211122181901-2021-12.tpd" +include "orbit/R20220531185310-2022-06.tpd" location "https://download.eclipse.org/releases/2020-12/" { org.eclipse.osgi lazy diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.19.target b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.19.target index ceff3052c3..cc418b1c8a 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.19.target +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.19.target @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8" standalone="no"?> <?pde?> <!-- generated with https://github.com/eclipse-cbi/targetplatform-dsl --> -<target name="jgit-4.19-staging" sequenceNumber="1638648728"> +<target name="jgit-4.19-staging" sequenceNumber="1654550632"> <locations> <location includeMode="slicer" includeAllPlatforms="false" includeSource="true" includeConfigurePhase="true" type="InstallableUnit"> <unit id="jakarta.servlet-api" version="4.0.0"/> @@ -23,12 +23,12 @@ <repository id="jetty-10.0.x" location="https://download.eclipse.org/eclipse/jetty/10.0.6/"/> </location> <location includeMode="slicer" includeAllPlatforms="false" includeSource="true" includeConfigurePhase="true" type="InstallableUnit"> - <unit id="com.google.gson" version="2.8.8.v20211029-0838"/> - <unit id="com.google.gson.source" version="2.8.8.v20211029-0838"/> + <unit id="com.google.gson" version="2.8.9.v20220111-1409"/> + <unit id="com.google.gson.source" version="2.8.9.v20220111-1409"/> <unit id="com.jcraft.jsch" version="0.1.55.v20190404-1902"/> <unit id="com.jcraft.jsch.source" version="0.1.55.v20190404-1902"/> - <unit id="com.jcraft.jzlib" version="1.1.1.v201205102305"/> - <unit id="com.jcraft.jzlib.source" version="1.1.1.v201205102305"/> + <unit id="com.jcraft.jzlib" version="1.1.3.v20220502-1820"/> + <unit id="com.jcraft.jzlib.source" version="1.1.3.v20220502-1820"/> <unit id="com.sun.jna" version="5.8.0.v20210503-0343"/> <unit id="com.sun.jna.source" version="5.8.0.v20210503-0343"/> <unit id="com.sun.jna.platform" version="5.8.0.v20210406-1004"/> @@ -39,8 +39,8 @@ <unit id="net.bytebuddy.byte-buddy-agent" version="1.9.0.v20181106-1534"/> <unit id="net.bytebuddy.byte-buddy-agent.source" version="1.9.0.v20181106-1534"/> <unit id="net.bytebuddy.byte-buddy.source" version="1.9.0.v20181107-1410"/> - <unit id="net.i2p.crypto.eddsa" version="0.3.0.v20210923-1401"/> - <unit id="net.i2p.crypto.eddsa.source" version="0.3.0.v20210923-1401"/> + <unit id="net.i2p.crypto.eddsa" version="0.3.0.v20220506-1020"/> + <unit id="net.i2p.crypto.eddsa.source" version="0.3.0.v20220506-1020"/> <unit id="org.apache.ant" version="1.10.12.v20211102-1452"/> <unit id="org.apache.ant.source" version="1.10.12.v20211102-1452"/> <unit id="org.apache.commons.codec" version="1.14.0.v20200818-1422"/> @@ -51,24 +51,22 @@ <unit id="org.apache.commons.logging.source" version="1.2.0.v20180409-1502"/> <unit id="org.apache.httpcomponents.httpclient" version="4.5.13.v20210128-2225"/> <unit id="org.apache.httpcomponents.httpclient.source" version="4.5.13.v20210128-2225"/> - <unit id="org.apache.httpcomponents.httpcore" version="4.4.14.v20210128-2225"/> - <unit id="org.apache.httpcomponents.httpcore.source" version="4.4.14.v20210128-2225"/> - <unit id="org.apache.log4j" version="1.2.15.v201012070815"/> - <unit id="org.apache.log4j.source" version="1.2.15.v201012070815"/> - <unit id="org.apache.sshd.osgi" version="2.7.0.v20210623-0618"/> - <unit id="org.apache.sshd.osgi.source" version="2.7.0.v20210623-0618"/> - <unit id="org.apache.sshd.sftp" version="2.7.0.v20210623-0618"/> - <unit id="org.apache.sshd.sftp.source" version="2.7.0.v20210623-0618"/> + <unit id="org.apache.httpcomponents.httpcore" version="4.4.15.v20220209-2345"/> + <unit id="org.apache.httpcomponents.httpcore.source" version="4.4.15.v20220209-2345"/> + <unit id="org.apache.sshd.osgi" version="2.8.0.v20211227-1750"/> + <unit id="org.apache.sshd.osgi.source" version="2.8.0.v20211227-1750"/> + <unit id="org.apache.sshd.sftp" version="2.8.0.v20211227-1750"/> + <unit id="org.apache.sshd.sftp.source" version="2.8.0.v20211227-1750"/> <unit id="org.assertj" version="3.20.2.v20210706-1104"/> <unit id="org.assertj.source" version="3.20.2.v20210706-1104"/> - <unit id="org.bouncycastle.bcpg" version="1.69.0.v20210713-1924"/> - <unit id="org.bouncycastle.bcpg.source" version="1.69.0.v20210713-1924"/> - <unit id="org.bouncycastle.bcpkix" version="1.69.0.v20210713-1924"/> - <unit id="org.bouncycastle.bcpkix.source" version="1.69.0.v20210713-1924"/> - <unit id="org.bouncycastle.bcprov" version="1.69.0.v20210923-1401"/> - <unit id="org.bouncycastle.bcprov.source" version="1.69.0.v20210923-1401"/> - <unit id="org.bouncycastle.bcutil" version="1.69.0.v20210713-1924"/> - <unit id="org.bouncycastle.bcutil.source" version="1.69.0.v20210713-1924"/> + <unit id="org.bouncycastle.bcpg" version="1.70.0.v20220507-1208"/> + <unit id="org.bouncycastle.bcpg.source" version="1.70.0.v20220507-1208"/> + <unit id="org.bouncycastle.bcpkix" version="1.70.0.v20220105-1522"/> + <unit id="org.bouncycastle.bcpkix.source" version="1.70.0.v20220105-1522"/> + <unit id="org.bouncycastle.bcprov" version="1.70.0.v20220507-1208"/> + <unit id="org.bouncycastle.bcprov.source" version="1.70.0.v20220507-1208"/> + <unit id="org.bouncycastle.bcutil" version="1.70.0.v20220105-1522"/> + <unit id="org.bouncycastle.bcutil.source" version="1.70.0.v20220105-1522"/> <unit id="org.hamcrest" version="2.2.0.v20210711-0821"/> <unit id="org.hamcrest.source" version="2.2.0.v20210711-0821"/> <unit id="org.hamcrest.core" version="1.3.0.v20180420-1519"/> @@ -85,11 +83,11 @@ <unit id="org.objenesis.source" version="2.6.0.v20180420-1519"/> <unit id="org.slf4j.api" version="1.7.30.v20200204-2150"/> <unit id="org.slf4j.api.source" version="1.7.30.v20200204-2150"/> - <unit id="org.slf4j.binding.log4j12" version="1.7.30.v20201108-2042"/> - <unit id="org.slf4j.binding.log4j12.source" version="1.7.30.v20201108-2042"/> + <unit id="org.slf4j.binding.simple" version="1.7.30.v20200204-2150"/> + <unit id="org.slf4j.binding.simple.source" version="1.7.30.v20200204-2150"/> <unit id="org.tukaani.xz" version="1.9.0.v20210624-1259"/> <unit id="org.tukaani.xz.source" version="1.9.0.v20210624-1259"/> - <repository location="https://download.eclipse.org/tools/orbit/downloads/drops/R20211122181901/repository"/> + <repository location="https://download.eclipse.org/tools/orbit/downloads/drops/R20220531185310/repository"/> </location> <location includeMode="slicer" includeAllPlatforms="false" includeSource="true" includeConfigurePhase="true" type="InstallableUnit"> <unit id="org.eclipse.osgi" version="0.0.0"/> diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.19.tpd b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.19.tpd index 419999652d..806851c6e2 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.19.tpd +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.19.tpd @@ -1,7 +1,7 @@ target "jgit-4.19-staging" with source configurePhase include "projects/jetty-10.0.x.tpd" -include "orbit/R20211122181901-2021-12.tpd" +include "orbit/R20220531185310-2022-06.tpd" location "https://download.eclipse.org/staging/2021-03/" { org.eclipse.osgi lazy diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.20.target b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.20.target index e2fed0675a..efcb591efa 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.20.target +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.20.target @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8" standalone="no"?> <?pde?> <!-- generated with https://github.com/eclipse-cbi/targetplatform-dsl --> -<target name="jgit-4.20" sequenceNumber="1638648728"> +<target name="jgit-4.20" sequenceNumber="1654550634"> <locations> <location includeMode="slicer" includeAllPlatforms="false" includeSource="true" includeConfigurePhase="true" type="InstallableUnit"> <unit id="jakarta.servlet-api" version="4.0.0"/> @@ -23,12 +23,12 @@ <repository id="jetty-10.0.x" location="https://download.eclipse.org/eclipse/jetty/10.0.6/"/> </location> <location includeMode="slicer" includeAllPlatforms="false" includeSource="true" includeConfigurePhase="true" type="InstallableUnit"> - <unit id="com.google.gson" version="2.8.8.v20211029-0838"/> - <unit id="com.google.gson.source" version="2.8.8.v20211029-0838"/> + <unit id="com.google.gson" version="2.8.9.v20220111-1409"/> + <unit id="com.google.gson.source" version="2.8.9.v20220111-1409"/> <unit id="com.jcraft.jsch" version="0.1.55.v20190404-1902"/> <unit id="com.jcraft.jsch.source" version="0.1.55.v20190404-1902"/> - <unit id="com.jcraft.jzlib" version="1.1.1.v201205102305"/> - <unit id="com.jcraft.jzlib.source" version="1.1.1.v201205102305"/> + <unit id="com.jcraft.jzlib" version="1.1.3.v20220502-1820"/> + <unit id="com.jcraft.jzlib.source" version="1.1.3.v20220502-1820"/> <unit id="com.sun.jna" version="5.8.0.v20210503-0343"/> <unit id="com.sun.jna.source" version="5.8.0.v20210503-0343"/> <unit id="com.sun.jna.platform" version="5.8.0.v20210406-1004"/> @@ -39,8 +39,8 @@ <unit id="net.bytebuddy.byte-buddy-agent" version="1.9.0.v20181106-1534"/> <unit id="net.bytebuddy.byte-buddy-agent.source" version="1.9.0.v20181106-1534"/> <unit id="net.bytebuddy.byte-buddy.source" version="1.9.0.v20181107-1410"/> - <unit id="net.i2p.crypto.eddsa" version="0.3.0.v20210923-1401"/> - <unit id="net.i2p.crypto.eddsa.source" version="0.3.0.v20210923-1401"/> + <unit id="net.i2p.crypto.eddsa" version="0.3.0.v20220506-1020"/> + <unit id="net.i2p.crypto.eddsa.source" version="0.3.0.v20220506-1020"/> <unit id="org.apache.ant" version="1.10.12.v20211102-1452"/> <unit id="org.apache.ant.source" version="1.10.12.v20211102-1452"/> <unit id="org.apache.commons.codec" version="1.14.0.v20200818-1422"/> @@ -51,24 +51,22 @@ <unit id="org.apache.commons.logging.source" version="1.2.0.v20180409-1502"/> <unit id="org.apache.httpcomponents.httpclient" version="4.5.13.v20210128-2225"/> <unit id="org.apache.httpcomponents.httpclient.source" version="4.5.13.v20210128-2225"/> - <unit id="org.apache.httpcomponents.httpcore" version="4.4.14.v20210128-2225"/> - <unit id="org.apache.httpcomponents.httpcore.source" version="4.4.14.v20210128-2225"/> - <unit id="org.apache.log4j" version="1.2.15.v201012070815"/> - <unit id="org.apache.log4j.source" version="1.2.15.v201012070815"/> - <unit id="org.apache.sshd.osgi" version="2.7.0.v20210623-0618"/> - <unit id="org.apache.sshd.osgi.source" version="2.7.0.v20210623-0618"/> - <unit id="org.apache.sshd.sftp" version="2.7.0.v20210623-0618"/> - <unit id="org.apache.sshd.sftp.source" version="2.7.0.v20210623-0618"/> + <unit id="org.apache.httpcomponents.httpcore" version="4.4.15.v20220209-2345"/> + <unit id="org.apache.httpcomponents.httpcore.source" version="4.4.15.v20220209-2345"/> + <unit id="org.apache.sshd.osgi" version="2.8.0.v20211227-1750"/> + <unit id="org.apache.sshd.osgi.source" version="2.8.0.v20211227-1750"/> + <unit id="org.apache.sshd.sftp" version="2.8.0.v20211227-1750"/> + <unit id="org.apache.sshd.sftp.source" version="2.8.0.v20211227-1750"/> <unit id="org.assertj" version="3.20.2.v20210706-1104"/> <unit id="org.assertj.source" version="3.20.2.v20210706-1104"/> - <unit id="org.bouncycastle.bcpg" version="1.69.0.v20210713-1924"/> - <unit id="org.bouncycastle.bcpg.source" version="1.69.0.v20210713-1924"/> - <unit id="org.bouncycastle.bcpkix" version="1.69.0.v20210713-1924"/> - <unit id="org.bouncycastle.bcpkix.source" version="1.69.0.v20210713-1924"/> - <unit id="org.bouncycastle.bcprov" version="1.69.0.v20210923-1401"/> - <unit id="org.bouncycastle.bcprov.source" version="1.69.0.v20210923-1401"/> - <unit id="org.bouncycastle.bcutil" version="1.69.0.v20210713-1924"/> - <unit id="org.bouncycastle.bcutil.source" version="1.69.0.v20210713-1924"/> + <unit id="org.bouncycastle.bcpg" version="1.70.0.v20220507-1208"/> + <unit id="org.bouncycastle.bcpg.source" version="1.70.0.v20220507-1208"/> + <unit id="org.bouncycastle.bcpkix" version="1.70.0.v20220105-1522"/> + <unit id="org.bouncycastle.bcpkix.source" version="1.70.0.v20220105-1522"/> + <unit id="org.bouncycastle.bcprov" version="1.70.0.v20220507-1208"/> + <unit id="org.bouncycastle.bcprov.source" version="1.70.0.v20220507-1208"/> + <unit id="org.bouncycastle.bcutil" version="1.70.0.v20220105-1522"/> + <unit id="org.bouncycastle.bcutil.source" version="1.70.0.v20220105-1522"/> <unit id="org.hamcrest" version="2.2.0.v20210711-0821"/> <unit id="org.hamcrest.source" version="2.2.0.v20210711-0821"/> <unit id="org.hamcrest.core" version="1.3.0.v20180420-1519"/> @@ -85,11 +83,11 @@ <unit id="org.objenesis.source" version="2.6.0.v20180420-1519"/> <unit id="org.slf4j.api" version="1.7.30.v20200204-2150"/> <unit id="org.slf4j.api.source" version="1.7.30.v20200204-2150"/> - <unit id="org.slf4j.binding.log4j12" version="1.7.30.v20201108-2042"/> - <unit id="org.slf4j.binding.log4j12.source" version="1.7.30.v20201108-2042"/> + <unit id="org.slf4j.binding.simple" version="1.7.30.v20200204-2150"/> + <unit id="org.slf4j.binding.simple.source" version="1.7.30.v20200204-2150"/> <unit id="org.tukaani.xz" version="1.9.0.v20210624-1259"/> <unit id="org.tukaani.xz.source" version="1.9.0.v20210624-1259"/> - <repository location="https://download.eclipse.org/tools/orbit/downloads/drops/R20211122181901/repository"/> + <repository location="https://download.eclipse.org/tools/orbit/downloads/drops/R20220531185310/repository"/> </location> <location includeMode="slicer" includeAllPlatforms="false" includeSource="true" includeConfigurePhase="true" type="InstallableUnit"> <unit id="org.eclipse.osgi" version="0.0.0"/> diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.20.tpd b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.20.tpd index 37123e5fa5..a3ea58300e 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.20.tpd +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.20.tpd @@ -1,7 +1,7 @@ target "jgit-4.20" with source configurePhase include "projects/jetty-10.0.x.tpd" -include "orbit/R20211122181901-2021-12.tpd" +include "orbit/R20220531185310-2022-06.tpd" location "https://download.eclipse.org/releases/2021-06/" { org.eclipse.osgi lazy diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.21.target b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.21.target index 4bd55466ec..85ed31f441 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.21.target +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.21.target @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8" standalone="no"?> <?pde?> <!-- generated with https://github.com/eclipse-cbi/targetplatform-dsl --> -<target name="jgit-4.21" sequenceNumber="1638648728"> +<target name="jgit-4.21" sequenceNumber="1654550635"> <locations> <location includeMode="slicer" includeAllPlatforms="false" includeSource="true" includeConfigurePhase="true" type="InstallableUnit"> <unit id="jakarta.servlet-api" version="4.0.0"/> @@ -23,12 +23,12 @@ <repository id="jetty-10.0.x" location="https://download.eclipse.org/eclipse/jetty/10.0.6/"/> </location> <location includeMode="slicer" includeAllPlatforms="false" includeSource="true" includeConfigurePhase="true" type="InstallableUnit"> - <unit id="com.google.gson" version="2.8.8.v20211029-0838"/> - <unit id="com.google.gson.source" version="2.8.8.v20211029-0838"/> + <unit id="com.google.gson" version="2.8.9.v20220111-1409"/> + <unit id="com.google.gson.source" version="2.8.9.v20220111-1409"/> <unit id="com.jcraft.jsch" version="0.1.55.v20190404-1902"/> <unit id="com.jcraft.jsch.source" version="0.1.55.v20190404-1902"/> - <unit id="com.jcraft.jzlib" version="1.1.1.v201205102305"/> - <unit id="com.jcraft.jzlib.source" version="1.1.1.v201205102305"/> + <unit id="com.jcraft.jzlib" version="1.1.3.v20220502-1820"/> + <unit id="com.jcraft.jzlib.source" version="1.1.3.v20220502-1820"/> <unit id="com.sun.jna" version="5.8.0.v20210503-0343"/> <unit id="com.sun.jna.source" version="5.8.0.v20210503-0343"/> <unit id="com.sun.jna.platform" version="5.8.0.v20210406-1004"/> @@ -39,8 +39,8 @@ <unit id="net.bytebuddy.byte-buddy-agent" version="1.9.0.v20181106-1534"/> <unit id="net.bytebuddy.byte-buddy-agent.source" version="1.9.0.v20181106-1534"/> <unit id="net.bytebuddy.byte-buddy.source" version="1.9.0.v20181107-1410"/> - <unit id="net.i2p.crypto.eddsa" version="0.3.0.v20210923-1401"/> - <unit id="net.i2p.crypto.eddsa.source" version="0.3.0.v20210923-1401"/> + <unit id="net.i2p.crypto.eddsa" version="0.3.0.v20220506-1020"/> + <unit id="net.i2p.crypto.eddsa.source" version="0.3.0.v20220506-1020"/> <unit id="org.apache.ant" version="1.10.12.v20211102-1452"/> <unit id="org.apache.ant.source" version="1.10.12.v20211102-1452"/> <unit id="org.apache.commons.codec" version="1.14.0.v20200818-1422"/> @@ -51,24 +51,22 @@ <unit id="org.apache.commons.logging.source" version="1.2.0.v20180409-1502"/> <unit id="org.apache.httpcomponents.httpclient" version="4.5.13.v20210128-2225"/> <unit id="org.apache.httpcomponents.httpclient.source" version="4.5.13.v20210128-2225"/> - <unit id="org.apache.httpcomponents.httpcore" version="4.4.14.v20210128-2225"/> - <unit id="org.apache.httpcomponents.httpcore.source" version="4.4.14.v20210128-2225"/> - <unit id="org.apache.log4j" version="1.2.15.v201012070815"/> - <unit id="org.apache.log4j.source" version="1.2.15.v201012070815"/> - <unit id="org.apache.sshd.osgi" version="2.7.0.v20210623-0618"/> - <unit id="org.apache.sshd.osgi.source" version="2.7.0.v20210623-0618"/> - <unit id="org.apache.sshd.sftp" version="2.7.0.v20210623-0618"/> - <unit id="org.apache.sshd.sftp.source" version="2.7.0.v20210623-0618"/> + <unit id="org.apache.httpcomponents.httpcore" version="4.4.15.v20220209-2345"/> + <unit id="org.apache.httpcomponents.httpcore.source" version="4.4.15.v20220209-2345"/> + <unit id="org.apache.sshd.osgi" version="2.8.0.v20211227-1750"/> + <unit id="org.apache.sshd.osgi.source" version="2.8.0.v20211227-1750"/> + <unit id="org.apache.sshd.sftp" version="2.8.0.v20211227-1750"/> + <unit id="org.apache.sshd.sftp.source" version="2.8.0.v20211227-1750"/> <unit id="org.assertj" version="3.20.2.v20210706-1104"/> <unit id="org.assertj.source" version="3.20.2.v20210706-1104"/> - <unit id="org.bouncycastle.bcpg" version="1.69.0.v20210713-1924"/> - <unit id="org.bouncycastle.bcpg.source" version="1.69.0.v20210713-1924"/> - <unit id="org.bouncycastle.bcpkix" version="1.69.0.v20210713-1924"/> - <unit id="org.bouncycastle.bcpkix.source" version="1.69.0.v20210713-1924"/> - <unit id="org.bouncycastle.bcprov" version="1.69.0.v20210923-1401"/> - <unit id="org.bouncycastle.bcprov.source" version="1.69.0.v20210923-1401"/> - <unit id="org.bouncycastle.bcutil" version="1.69.0.v20210713-1924"/> - <unit id="org.bouncycastle.bcutil.source" version="1.69.0.v20210713-1924"/> + <unit id="org.bouncycastle.bcpg" version="1.70.0.v20220507-1208"/> + <unit id="org.bouncycastle.bcpg.source" version="1.70.0.v20220507-1208"/> + <unit id="org.bouncycastle.bcpkix" version="1.70.0.v20220105-1522"/> + <unit id="org.bouncycastle.bcpkix.source" version="1.70.0.v20220105-1522"/> + <unit id="org.bouncycastle.bcprov" version="1.70.0.v20220507-1208"/> + <unit id="org.bouncycastle.bcprov.source" version="1.70.0.v20220507-1208"/> + <unit id="org.bouncycastle.bcutil" version="1.70.0.v20220105-1522"/> + <unit id="org.bouncycastle.bcutil.source" version="1.70.0.v20220105-1522"/> <unit id="org.hamcrest" version="2.2.0.v20210711-0821"/> <unit id="org.hamcrest.source" version="2.2.0.v20210711-0821"/> <unit id="org.hamcrest.core" version="1.3.0.v20180420-1519"/> @@ -85,11 +83,11 @@ <unit id="org.objenesis.source" version="2.6.0.v20180420-1519"/> <unit id="org.slf4j.api" version="1.7.30.v20200204-2150"/> <unit id="org.slf4j.api.source" version="1.7.30.v20200204-2150"/> - <unit id="org.slf4j.binding.log4j12" version="1.7.30.v20201108-2042"/> - <unit id="org.slf4j.binding.log4j12.source" version="1.7.30.v20201108-2042"/> + <unit id="org.slf4j.binding.simple" version="1.7.30.v20200204-2150"/> + <unit id="org.slf4j.binding.simple.source" version="1.7.30.v20200204-2150"/> <unit id="org.tukaani.xz" version="1.9.0.v20210624-1259"/> <unit id="org.tukaani.xz.source" version="1.9.0.v20210624-1259"/> - <repository location="https://download.eclipse.org/tools/orbit/downloads/drops/R20211122181901/repository"/> + <repository location="https://download.eclipse.org/tools/orbit/downloads/drops/R20220531185310/repository"/> </location> <location includeMode="slicer" includeAllPlatforms="false" includeSource="true" includeConfigurePhase="true" type="InstallableUnit"> <unit id="org.eclipse.osgi" version="0.0.0"/> diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.21.tpd b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.21.tpd index 2949e50a2d..0808601826 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.21.tpd +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.21.tpd @@ -1,7 +1,7 @@ target "jgit-4.21" with source configurePhase include "projects/jetty-10.0.x.tpd" -include "orbit/R20211122181901-2021-12.tpd" +include "orbit/R20220531185310-2022-06.tpd" location "https://download.eclipse.org/releases/2021-09/" { org.eclipse.osgi lazy diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.22.target b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.22.target index 98f44a8dc2..e7b5a31992 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.22.target +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.22.target @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8" standalone="no"?> <?pde?> <!-- generated with https://github.com/eclipse-cbi/targetplatform-dsl --> -<target name="jgit-4.22" sequenceNumber="1638648736"> +<target name="jgit-4.22" sequenceNumber="1654550634"> <locations> <location includeMode="slicer" includeAllPlatforms="false" includeSource="true" includeConfigurePhase="true" type="InstallableUnit"> <unit id="jakarta.servlet-api" version="4.0.0"/> @@ -23,12 +23,12 @@ <repository id="jetty-10.0.x" location="https://download.eclipse.org/eclipse/jetty/10.0.6/"/> </location> <location includeMode="slicer" includeAllPlatforms="false" includeSource="true" includeConfigurePhase="true" type="InstallableUnit"> - <unit id="com.google.gson" version="2.8.8.v20211029-0838"/> - <unit id="com.google.gson.source" version="2.8.8.v20211029-0838"/> + <unit id="com.google.gson" version="2.8.9.v20220111-1409"/> + <unit id="com.google.gson.source" version="2.8.9.v20220111-1409"/> <unit id="com.jcraft.jsch" version="0.1.55.v20190404-1902"/> <unit id="com.jcraft.jsch.source" version="0.1.55.v20190404-1902"/> - <unit id="com.jcraft.jzlib" version="1.1.1.v201205102305"/> - <unit id="com.jcraft.jzlib.source" version="1.1.1.v201205102305"/> + <unit id="com.jcraft.jzlib" version="1.1.3.v20220502-1820"/> + <unit id="com.jcraft.jzlib.source" version="1.1.3.v20220502-1820"/> <unit id="com.sun.jna" version="5.8.0.v20210503-0343"/> <unit id="com.sun.jna.source" version="5.8.0.v20210503-0343"/> <unit id="com.sun.jna.platform" version="5.8.0.v20210406-1004"/> @@ -39,8 +39,8 @@ <unit id="net.bytebuddy.byte-buddy-agent" version="1.9.0.v20181106-1534"/> <unit id="net.bytebuddy.byte-buddy-agent.source" version="1.9.0.v20181106-1534"/> <unit id="net.bytebuddy.byte-buddy.source" version="1.9.0.v20181107-1410"/> - <unit id="net.i2p.crypto.eddsa" version="0.3.0.v20210923-1401"/> - <unit id="net.i2p.crypto.eddsa.source" version="0.3.0.v20210923-1401"/> + <unit id="net.i2p.crypto.eddsa" version="0.3.0.v20220506-1020"/> + <unit id="net.i2p.crypto.eddsa.source" version="0.3.0.v20220506-1020"/> <unit id="org.apache.ant" version="1.10.12.v20211102-1452"/> <unit id="org.apache.ant.source" version="1.10.12.v20211102-1452"/> <unit id="org.apache.commons.codec" version="1.14.0.v20200818-1422"/> @@ -51,24 +51,22 @@ <unit id="org.apache.commons.logging.source" version="1.2.0.v20180409-1502"/> <unit id="org.apache.httpcomponents.httpclient" version="4.5.13.v20210128-2225"/> <unit id="org.apache.httpcomponents.httpclient.source" version="4.5.13.v20210128-2225"/> - <unit id="org.apache.httpcomponents.httpcore" version="4.4.14.v20210128-2225"/> - <unit id="org.apache.httpcomponents.httpcore.source" version="4.4.14.v20210128-2225"/> - <unit id="org.apache.log4j" version="1.2.15.v201012070815"/> - <unit id="org.apache.log4j.source" version="1.2.15.v201012070815"/> - <unit id="org.apache.sshd.osgi" version="2.7.0.v20210623-0618"/> - <unit id="org.apache.sshd.osgi.source" version="2.7.0.v20210623-0618"/> - <unit id="org.apache.sshd.sftp" version="2.7.0.v20210623-0618"/> - <unit id="org.apache.sshd.sftp.source" version="2.7.0.v20210623-0618"/> + <unit id="org.apache.httpcomponents.httpcore" version="4.4.15.v20220209-2345"/> + <unit id="org.apache.httpcomponents.httpcore.source" version="4.4.15.v20220209-2345"/> + <unit id="org.apache.sshd.osgi" version="2.8.0.v20211227-1750"/> + <unit id="org.apache.sshd.osgi.source" version="2.8.0.v20211227-1750"/> + <unit id="org.apache.sshd.sftp" version="2.8.0.v20211227-1750"/> + <unit id="org.apache.sshd.sftp.source" version="2.8.0.v20211227-1750"/> <unit id="org.assertj" version="3.20.2.v20210706-1104"/> <unit id="org.assertj.source" version="3.20.2.v20210706-1104"/> - <unit id="org.bouncycastle.bcpg" version="1.69.0.v20210713-1924"/> - <unit id="org.bouncycastle.bcpg.source" version="1.69.0.v20210713-1924"/> - <unit id="org.bouncycastle.bcpkix" version="1.69.0.v20210713-1924"/> - <unit id="org.bouncycastle.bcpkix.source" version="1.69.0.v20210713-1924"/> - <unit id="org.bouncycastle.bcprov" version="1.69.0.v20210923-1401"/> - <unit id="org.bouncycastle.bcprov.source" version="1.69.0.v20210923-1401"/> - <unit id="org.bouncycastle.bcutil" version="1.69.0.v20210713-1924"/> - <unit id="org.bouncycastle.bcutil.source" version="1.69.0.v20210713-1924"/> + <unit id="org.bouncycastle.bcpg" version="1.70.0.v20220507-1208"/> + <unit id="org.bouncycastle.bcpg.source" version="1.70.0.v20220507-1208"/> + <unit id="org.bouncycastle.bcpkix" version="1.70.0.v20220105-1522"/> + <unit id="org.bouncycastle.bcpkix.source" version="1.70.0.v20220105-1522"/> + <unit id="org.bouncycastle.bcprov" version="1.70.0.v20220507-1208"/> + <unit id="org.bouncycastle.bcprov.source" version="1.70.0.v20220507-1208"/> + <unit id="org.bouncycastle.bcutil" version="1.70.0.v20220105-1522"/> + <unit id="org.bouncycastle.bcutil.source" version="1.70.0.v20220105-1522"/> <unit id="org.hamcrest" version="2.2.0.v20210711-0821"/> <unit id="org.hamcrest.source" version="2.2.0.v20210711-0821"/> <unit id="org.hamcrest.core" version="1.3.0.v20180420-1519"/> @@ -85,11 +83,11 @@ <unit id="org.objenesis.source" version="2.6.0.v20180420-1519"/> <unit id="org.slf4j.api" version="1.7.30.v20200204-2150"/> <unit id="org.slf4j.api.source" version="1.7.30.v20200204-2150"/> - <unit id="org.slf4j.binding.log4j12" version="1.7.30.v20201108-2042"/> - <unit id="org.slf4j.binding.log4j12.source" version="1.7.30.v20201108-2042"/> + <unit id="org.slf4j.binding.simple" version="1.7.30.v20200204-2150"/> + <unit id="org.slf4j.binding.simple.source" version="1.7.30.v20200204-2150"/> <unit id="org.tukaani.xz" version="1.9.0.v20210624-1259"/> <unit id="org.tukaani.xz.source" version="1.9.0.v20210624-1259"/> - <repository location="https://download.eclipse.org/tools/orbit/downloads/drops/R20211122181901/repository"/> + <repository location="https://download.eclipse.org/tools/orbit/downloads/drops/R20220531185310/repository"/> </location> <location includeMode="slicer" includeAllPlatforms="false" includeSource="true" includeConfigurePhase="true" type="InstallableUnit"> <unit id="org.eclipse.osgi" version="0.0.0"/> diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.22.tpd b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.22.tpd index db3db28773..5697574d3f 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.22.tpd +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.22.tpd @@ -1,7 +1,7 @@ target "jgit-4.22" with source configurePhase include "projects/jetty-10.0.x.tpd" -include "orbit/R20211122181901-2021-12.tpd" +include "orbit/R20220531185310-2022-06.tpd" location "https://download.eclipse.org/releases/2021-12/" { org.eclipse.osgi lazy diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.23.target b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.23.target new file mode 100644 index 0000000000..3c18e4b75c --- /dev/null +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.23.target @@ -0,0 +1,97 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<?pde?> +<!-- generated with https://github.com/eclipse-cbi/targetplatform-dsl --> +<target name="jgit-4.23" sequenceNumber="1654550634"> + <locations> + <location includeMode="slicer" includeAllPlatforms="false" includeSource="true" includeConfigurePhase="true" type="InstallableUnit"> + <unit id="jakarta.servlet-api" version="4.0.0"/> + <unit id="jakarta.servlet-api.source" version="4.0.0"/> + <unit id="org.eclipse.jetty.http" version="10.0.6"/> + <unit id="org.eclipse.jetty.http.source" version="10.0.6"/> + <unit id="org.eclipse.jetty.io" version="10.0.6"/> + <unit id="org.eclipse.jetty.io.source" version="10.0.6"/> + <unit id="org.eclipse.jetty.security" version="10.0.6"/> + <unit id="org.eclipse.jetty.security.source" version="10.0.6"/> + <unit id="org.eclipse.jetty.server" version="10.0.6"/> + <unit id="org.eclipse.jetty.server.source" version="10.0.6"/> + <unit id="org.eclipse.jetty.servlet" version="10.0.6"/> + <unit id="org.eclipse.jetty.servlet.source" version="10.0.6"/> + <unit id="org.eclipse.jetty.util" version="10.0.6"/> + <unit id="org.eclipse.jetty.util.source" version="10.0.6"/> + <unit id="org.eclipse.jetty.util.ajax" version="10.0.6"/> + <unit id="org.eclipse.jetty.util.ajax.source" version="10.0.6"/> + <repository id="jetty-10.0.x" location="https://download.eclipse.org/eclipse/jetty/10.0.6/"/> + </location> + <location includeMode="slicer" includeAllPlatforms="false" includeSource="true" includeConfigurePhase="true" type="InstallableUnit"> + <unit id="com.google.gson" version="2.8.9.v20220111-1409"/> + <unit id="com.google.gson.source" version="2.8.9.v20220111-1409"/> + <unit id="com.jcraft.jsch" version="0.1.55.v20190404-1902"/> + <unit id="com.jcraft.jsch.source" version="0.1.55.v20190404-1902"/> + <unit id="com.jcraft.jzlib" version="1.1.3.v20220502-1820"/> + <unit id="com.jcraft.jzlib.source" version="1.1.3.v20220502-1820"/> + <unit id="com.sun.jna" version="5.8.0.v20210503-0343"/> + <unit id="com.sun.jna.source" version="5.8.0.v20210503-0343"/> + <unit id="com.sun.jna.platform" version="5.8.0.v20210406-1004"/> + <unit id="com.sun.jna.platform.source" version="5.8.0.v20210406-1004"/> + <unit id="javaewah" version="1.1.13.v20211029-0839"/> + <unit id="javaewah.source" version="1.1.13.v20211029-0839"/> + <unit id="net.bytebuddy.byte-buddy" version="1.9.0.v20181107-1410"/> + <unit id="net.bytebuddy.byte-buddy-agent" version="1.9.0.v20181106-1534"/> + <unit id="net.bytebuddy.byte-buddy-agent.source" version="1.9.0.v20181106-1534"/> + <unit id="net.bytebuddy.byte-buddy.source" version="1.9.0.v20181107-1410"/> + <unit id="net.i2p.crypto.eddsa" version="0.3.0.v20220506-1020"/> + <unit id="net.i2p.crypto.eddsa.source" version="0.3.0.v20220506-1020"/> + <unit id="org.apache.ant" version="1.10.12.v20211102-1452"/> + <unit id="org.apache.ant.source" version="1.10.12.v20211102-1452"/> + <unit id="org.apache.commons.codec" version="1.14.0.v20200818-1422"/> + <unit id="org.apache.commons.codec.source" version="1.14.0.v20200818-1422"/> + <unit id="org.apache.commons.compress" version="1.21.0.v20211103-2100"/> + <unit id="org.apache.commons.compress.source" version="1.21.0.v20211103-2100"/> + <unit id="org.apache.commons.logging" version="1.2.0.v20180409-1502"/> + <unit id="org.apache.commons.logging.source" version="1.2.0.v20180409-1502"/> + <unit id="org.apache.httpcomponents.httpclient" version="4.5.13.v20210128-2225"/> + <unit id="org.apache.httpcomponents.httpclient.source" version="4.5.13.v20210128-2225"/> + <unit id="org.apache.httpcomponents.httpcore" version="4.4.15.v20220209-2345"/> + <unit id="org.apache.httpcomponents.httpcore.source" version="4.4.15.v20220209-2345"/> + <unit id="org.apache.sshd.osgi" version="2.8.0.v20211227-1750"/> + <unit id="org.apache.sshd.osgi.source" version="2.8.0.v20211227-1750"/> + <unit id="org.apache.sshd.sftp" version="2.8.0.v20211227-1750"/> + <unit id="org.apache.sshd.sftp.source" version="2.8.0.v20211227-1750"/> + <unit id="org.assertj" version="3.20.2.v20210706-1104"/> + <unit id="org.assertj.source" version="3.20.2.v20210706-1104"/> + <unit id="org.bouncycastle.bcpg" version="1.70.0.v20220507-1208"/> + <unit id="org.bouncycastle.bcpg.source" version="1.70.0.v20220507-1208"/> + <unit id="org.bouncycastle.bcpkix" version="1.70.0.v20220105-1522"/> + <unit id="org.bouncycastle.bcpkix.source" version="1.70.0.v20220105-1522"/> + <unit id="org.bouncycastle.bcprov" version="1.70.0.v20220507-1208"/> + <unit id="org.bouncycastle.bcprov.source" version="1.70.0.v20220507-1208"/> + <unit id="org.bouncycastle.bcutil" version="1.70.0.v20220105-1522"/> + <unit id="org.bouncycastle.bcutil.source" version="1.70.0.v20220105-1522"/> + <unit id="org.hamcrest" version="2.2.0.v20210711-0821"/> + <unit id="org.hamcrest.source" version="2.2.0.v20210711-0821"/> + <unit id="org.hamcrest.core" version="1.3.0.v20180420-1519"/> + <unit id="org.hamcrest.core.source" version="1.3.0.v20180420-1519"/> + <unit id="org.hamcrest.library" version="1.3.0.v20180524-2246"/> + <unit id="org.hamcrest.library.source" version="1.3.0.v20180524-2246"/> + <unit id="org.junit" version="4.13.2.v20211018-1956"/> + <unit id="org.junit.source" version="4.13.2.v20211018-1956"/> + <unit id="org.kohsuke.args4j" version="2.33.0.v20160323-2218"/> + <unit id="org.kohsuke.args4j.source" version="2.33.0.v20160323-2218"/> + <unit id="org.mockito" version="2.23.0.v20200310-1642"/> + <unit id="org.mockito.source" version="2.23.0.v20200310-1642"/> + <unit id="org.objenesis" version="2.6.0.v20180420-1519"/> + <unit id="org.objenesis.source" version="2.6.0.v20180420-1519"/> + <unit id="org.slf4j.api" version="1.7.30.v20200204-2150"/> + <unit id="org.slf4j.api.source" version="1.7.30.v20200204-2150"/> + <unit id="org.slf4j.binding.simple" version="1.7.30.v20200204-2150"/> + <unit id="org.slf4j.binding.simple.source" version="1.7.30.v20200204-2150"/> + <unit id="org.tukaani.xz" version="1.9.0.v20210624-1259"/> + <unit id="org.tukaani.xz.source" version="1.9.0.v20210624-1259"/> + <repository location="https://download.eclipse.org/tools/orbit/downloads/drops/R20220531185310/repository"/> + </location> + <location includeMode="slicer" includeAllPlatforms="false" includeSource="true" includeConfigurePhase="true" type="InstallableUnit"> + <unit id="org.eclipse.osgi" version="0.0.0"/> + <repository location="https://download.eclipse.org/releases/2022-03/"/> + </location> + </locations> +</target> diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.23.tpd b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.23.tpd new file mode 100644 index 0000000000..7fd421a882 --- /dev/null +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.23.tpd @@ -0,0 +1,8 @@ +target "jgit-4.23" with source configurePhase + +include "projects/jetty-10.0.x.tpd" +include "orbit/R20220531185310-2022-06.tpd" + +location "https://download.eclipse.org/releases/2022-03/" { + org.eclipse.osgi lazy +} diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.24.target b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.24.target new file mode 100644 index 0000000000..bd45e85e78 --- /dev/null +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.24.target @@ -0,0 +1,97 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<?pde?> +<!-- generated with https://github.com/eclipse-cbi/targetplatform-dsl --> +<target name="jgit-4.24" sequenceNumber="1655375254"> + <locations> + <location includeMode="slicer" includeAllPlatforms="false" includeSource="true" includeConfigurePhase="true" type="InstallableUnit"> + <unit id="jakarta.servlet-api" version="4.0.0"/> + <unit id="jakarta.servlet-api.source" version="4.0.0"/> + <unit id="org.eclipse.jetty.http" version="10.0.6"/> + <unit id="org.eclipse.jetty.http.source" version="10.0.6"/> + <unit id="org.eclipse.jetty.io" version="10.0.6"/> + <unit id="org.eclipse.jetty.io.source" version="10.0.6"/> + <unit id="org.eclipse.jetty.security" version="10.0.6"/> + <unit id="org.eclipse.jetty.security.source" version="10.0.6"/> + <unit id="org.eclipse.jetty.server" version="10.0.6"/> + <unit id="org.eclipse.jetty.server.source" version="10.0.6"/> + <unit id="org.eclipse.jetty.servlet" version="10.0.6"/> + <unit id="org.eclipse.jetty.servlet.source" version="10.0.6"/> + <unit id="org.eclipse.jetty.util" version="10.0.6"/> + <unit id="org.eclipse.jetty.util.source" version="10.0.6"/> + <unit id="org.eclipse.jetty.util.ajax" version="10.0.6"/> + <unit id="org.eclipse.jetty.util.ajax.source" version="10.0.6"/> + <repository id="jetty-10.0.x" location="https://download.eclipse.org/eclipse/jetty/10.0.6/"/> + </location> + <location includeMode="slicer" includeAllPlatforms="false" includeSource="true" includeConfigurePhase="true" type="InstallableUnit"> + <unit id="com.google.gson" version="2.8.9.v20220111-1409"/> + <unit id="com.google.gson.source" version="2.8.9.v20220111-1409"/> + <unit id="com.jcraft.jsch" version="0.1.55.v20190404-1902"/> + <unit id="com.jcraft.jsch.source" version="0.1.55.v20190404-1902"/> + <unit id="com.jcraft.jzlib" version="1.1.3.v20220502-1820"/> + <unit id="com.jcraft.jzlib.source" version="1.1.3.v20220502-1820"/> + <unit id="com.sun.jna" version="5.8.0.v20210503-0343"/> + <unit id="com.sun.jna.source" version="5.8.0.v20210503-0343"/> + <unit id="com.sun.jna.platform" version="5.8.0.v20210406-1004"/> + <unit id="com.sun.jna.platform.source" version="5.8.0.v20210406-1004"/> + <unit id="javaewah" version="1.1.13.v20211029-0839"/> + <unit id="javaewah.source" version="1.1.13.v20211029-0839"/> + <unit id="net.bytebuddy.byte-buddy" version="1.9.0.v20181107-1410"/> + <unit id="net.bytebuddy.byte-buddy-agent" version="1.9.0.v20181106-1534"/> + <unit id="net.bytebuddy.byte-buddy-agent.source" version="1.9.0.v20181106-1534"/> + <unit id="net.bytebuddy.byte-buddy.source" version="1.9.0.v20181107-1410"/> + <unit id="net.i2p.crypto.eddsa" version="0.3.0.v20220506-1020"/> + <unit id="net.i2p.crypto.eddsa.source" version="0.3.0.v20220506-1020"/> + <unit id="org.apache.ant" version="1.10.12.v20211102-1452"/> + <unit id="org.apache.ant.source" version="1.10.12.v20211102-1452"/> + <unit id="org.apache.commons.codec" version="1.14.0.v20200818-1422"/> + <unit id="org.apache.commons.codec.source" version="1.14.0.v20200818-1422"/> + <unit id="org.apache.commons.compress" version="1.21.0.v20211103-2100"/> + <unit id="org.apache.commons.compress.source" version="1.21.0.v20211103-2100"/> + <unit id="org.apache.commons.logging" version="1.2.0.v20180409-1502"/> + <unit id="org.apache.commons.logging.source" version="1.2.0.v20180409-1502"/> + <unit id="org.apache.httpcomponents.httpclient" version="4.5.13.v20210128-2225"/> + <unit id="org.apache.httpcomponents.httpclient.source" version="4.5.13.v20210128-2225"/> + <unit id="org.apache.httpcomponents.httpcore" version="4.4.15.v20220209-2345"/> + <unit id="org.apache.httpcomponents.httpcore.source" version="4.4.15.v20220209-2345"/> + <unit id="org.apache.sshd.osgi" version="2.8.0.v20211227-1750"/> + <unit id="org.apache.sshd.osgi.source" version="2.8.0.v20211227-1750"/> + <unit id="org.apache.sshd.sftp" version="2.8.0.v20211227-1750"/> + <unit id="org.apache.sshd.sftp.source" version="2.8.0.v20211227-1750"/> + <unit id="org.assertj" version="3.20.2.v20210706-1104"/> + <unit id="org.assertj.source" version="3.20.2.v20210706-1104"/> + <unit id="org.bouncycastle.bcpg" version="1.70.0.v20220507-1208"/> + <unit id="org.bouncycastle.bcpg.source" version="1.70.0.v20220507-1208"/> + <unit id="org.bouncycastle.bcpkix" version="1.70.0.v20220105-1522"/> + <unit id="org.bouncycastle.bcpkix.source" version="1.70.0.v20220105-1522"/> + <unit id="org.bouncycastle.bcprov" version="1.70.0.v20220507-1208"/> + <unit id="org.bouncycastle.bcprov.source" version="1.70.0.v20220507-1208"/> + <unit id="org.bouncycastle.bcutil" version="1.70.0.v20220105-1522"/> + <unit id="org.bouncycastle.bcutil.source" version="1.70.0.v20220105-1522"/> + <unit id="org.hamcrest" version="2.2.0.v20210711-0821"/> + <unit id="org.hamcrest.source" version="2.2.0.v20210711-0821"/> + <unit id="org.hamcrest.core" version="1.3.0.v20180420-1519"/> + <unit id="org.hamcrest.core.source" version="1.3.0.v20180420-1519"/> + <unit id="org.hamcrest.library" version="1.3.0.v20180524-2246"/> + <unit id="org.hamcrest.library.source" version="1.3.0.v20180524-2246"/> + <unit id="org.junit" version="4.13.2.v20211018-1956"/> + <unit id="org.junit.source" version="4.13.2.v20211018-1956"/> + <unit id="org.kohsuke.args4j" version="2.33.0.v20160323-2218"/> + <unit id="org.kohsuke.args4j.source" version="2.33.0.v20160323-2218"/> + <unit id="org.mockito" version="2.23.0.v20200310-1642"/> + <unit id="org.mockito.source" version="2.23.0.v20200310-1642"/> + <unit id="org.objenesis" version="2.6.0.v20180420-1519"/> + <unit id="org.objenesis.source" version="2.6.0.v20180420-1519"/> + <unit id="org.slf4j.api" version="1.7.30.v20200204-2150"/> + <unit id="org.slf4j.api.source" version="1.7.30.v20200204-2150"/> + <unit id="org.slf4j.binding.simple" version="1.7.30.v20200204-2150"/> + <unit id="org.slf4j.binding.simple.source" version="1.7.30.v20200204-2150"/> + <unit id="org.tukaani.xz" version="1.9.0.v20210624-1259"/> + <unit id="org.tukaani.xz.source" version="1.9.0.v20210624-1259"/> + <repository location="https://download.eclipse.org/tools/orbit/downloads/drops/R20220531185310/repository"/> + </location> + <location includeMode="slicer" includeAllPlatforms="false" includeSource="true" includeConfigurePhase="true" type="InstallableUnit"> + <unit id="org.eclipse.osgi" version="0.0.0"/> + <repository location="https://download.eclipse.org/releases/2022-06/"/> + </location> + </locations> +</target> diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.24.tpd b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.24.tpd new file mode 100644 index 0000000000..f258adc2d4 --- /dev/null +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.24.tpd @@ -0,0 +1,8 @@ +target "jgit-4.24" with source configurePhase + +include "projects/jetty-10.0.x.tpd" +include "orbit/R20220531185310-2022-06.tpd" + +location "https://download.eclipse.org/releases/2022-06/" { + org.eclipse.osgi lazy +} diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.25.target b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.25.target new file mode 100644 index 0000000000..0ec9d1024f --- /dev/null +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.25.target @@ -0,0 +1,97 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<?pde?> +<!-- generated with https://github.com/eclipse-cbi/targetplatform-dsl --> +<target name="jgit-4.25" sequenceNumber="1655454378"> + <locations> + <location includeMode="slicer" includeAllPlatforms="false" includeSource="true" includeConfigurePhase="true" type="InstallableUnit"> + <unit id="jakarta.servlet-api" version="4.0.0"/> + <unit id="jakarta.servlet-api.source" version="4.0.0"/> + <unit id="org.eclipse.jetty.http" version="10.0.6"/> + <unit id="org.eclipse.jetty.http.source" version="10.0.6"/> + <unit id="org.eclipse.jetty.io" version="10.0.6"/> + <unit id="org.eclipse.jetty.io.source" version="10.0.6"/> + <unit id="org.eclipse.jetty.security" version="10.0.6"/> + <unit id="org.eclipse.jetty.security.source" version="10.0.6"/> + <unit id="org.eclipse.jetty.server" version="10.0.6"/> + <unit id="org.eclipse.jetty.server.source" version="10.0.6"/> + <unit id="org.eclipse.jetty.servlet" version="10.0.6"/> + <unit id="org.eclipse.jetty.servlet.source" version="10.0.6"/> + <unit id="org.eclipse.jetty.util" version="10.0.6"/> + <unit id="org.eclipse.jetty.util.source" version="10.0.6"/> + <unit id="org.eclipse.jetty.util.ajax" version="10.0.6"/> + <unit id="org.eclipse.jetty.util.ajax.source" version="10.0.6"/> + <repository id="jetty-10.0.x" location="https://download.eclipse.org/eclipse/jetty/10.0.6/"/> + </location> + <location includeMode="slicer" includeAllPlatforms="false" includeSource="true" includeConfigurePhase="true" type="InstallableUnit"> + <unit id="com.google.gson" version="2.8.9.v20220111-1409"/> + <unit id="com.google.gson.source" version="2.8.9.v20220111-1409"/> + <unit id="com.jcraft.jsch" version="0.1.55.v20190404-1902"/> + <unit id="com.jcraft.jsch.source" version="0.1.55.v20190404-1902"/> + <unit id="com.jcraft.jzlib" version="1.1.3.v20220502-1820"/> + <unit id="com.jcraft.jzlib.source" version="1.1.3.v20220502-1820"/> + <unit id="com.sun.jna" version="5.8.0.v20210503-0343"/> + <unit id="com.sun.jna.source" version="5.8.0.v20210503-0343"/> + <unit id="com.sun.jna.platform" version="5.8.0.v20210406-1004"/> + <unit id="com.sun.jna.platform.source" version="5.8.0.v20210406-1004"/> + <unit id="javaewah" version="1.1.13.v20211029-0839"/> + <unit id="javaewah.source" version="1.1.13.v20211029-0839"/> + <unit id="net.bytebuddy.byte-buddy" version="1.9.0.v20181107-1410"/> + <unit id="net.bytebuddy.byte-buddy-agent" version="1.9.0.v20181106-1534"/> + <unit id="net.bytebuddy.byte-buddy-agent.source" version="1.9.0.v20181106-1534"/> + <unit id="net.bytebuddy.byte-buddy.source" version="1.9.0.v20181107-1410"/> + <unit id="net.i2p.crypto.eddsa" version="0.3.0.v20220506-1020"/> + <unit id="net.i2p.crypto.eddsa.source" version="0.3.0.v20220506-1020"/> + <unit id="org.apache.ant" version="1.10.12.v20211102-1452"/> + <unit id="org.apache.ant.source" version="1.10.12.v20211102-1452"/> + <unit id="org.apache.commons.codec" version="1.14.0.v20200818-1422"/> + <unit id="org.apache.commons.codec.source" version="1.14.0.v20200818-1422"/> + <unit id="org.apache.commons.compress" version="1.21.0.v20211103-2100"/> + <unit id="org.apache.commons.compress.source" version="1.21.0.v20211103-2100"/> + <unit id="org.apache.commons.logging" version="1.2.0.v20180409-1502"/> + <unit id="org.apache.commons.logging.source" version="1.2.0.v20180409-1502"/> + <unit id="org.apache.httpcomponents.httpclient" version="4.5.13.v20210128-2225"/> + <unit id="org.apache.httpcomponents.httpclient.source" version="4.5.13.v20210128-2225"/> + <unit id="org.apache.httpcomponents.httpcore" version="4.4.15.v20220209-2345"/> + <unit id="org.apache.httpcomponents.httpcore.source" version="4.4.15.v20220209-2345"/> + <unit id="org.apache.sshd.osgi" version="2.8.0.v20211227-1750"/> + <unit id="org.apache.sshd.osgi.source" version="2.8.0.v20211227-1750"/> + <unit id="org.apache.sshd.sftp" version="2.8.0.v20211227-1750"/> + <unit id="org.apache.sshd.sftp.source" version="2.8.0.v20211227-1750"/> + <unit id="org.assertj" version="3.20.2.v20210706-1104"/> + <unit id="org.assertj.source" version="3.20.2.v20210706-1104"/> + <unit id="org.bouncycastle.bcpg" version="1.70.0.v20220507-1208"/> + <unit id="org.bouncycastle.bcpg.source" version="1.70.0.v20220507-1208"/> + <unit id="org.bouncycastle.bcpkix" version="1.70.0.v20220105-1522"/> + <unit id="org.bouncycastle.bcpkix.source" version="1.70.0.v20220105-1522"/> + <unit id="org.bouncycastle.bcprov" version="1.70.0.v20220507-1208"/> + <unit id="org.bouncycastle.bcprov.source" version="1.70.0.v20220507-1208"/> + <unit id="org.bouncycastle.bcutil" version="1.70.0.v20220105-1522"/> + <unit id="org.bouncycastle.bcutil.source" version="1.70.0.v20220105-1522"/> + <unit id="org.hamcrest" version="2.2.0.v20210711-0821"/> + <unit id="org.hamcrest.source" version="2.2.0.v20210711-0821"/> + <unit id="org.hamcrest.core" version="1.3.0.v20180420-1519"/> + <unit id="org.hamcrest.core.source" version="1.3.0.v20180420-1519"/> + <unit id="org.hamcrest.library" version="1.3.0.v20180524-2246"/> + <unit id="org.hamcrest.library.source" version="1.3.0.v20180524-2246"/> + <unit id="org.junit" version="4.13.2.v20211018-1956"/> + <unit id="org.junit.source" version="4.13.2.v20211018-1956"/> + <unit id="org.kohsuke.args4j" version="2.33.0.v20160323-2218"/> + <unit id="org.kohsuke.args4j.source" version="2.33.0.v20160323-2218"/> + <unit id="org.mockito" version="2.23.0.v20200310-1642"/> + <unit id="org.mockito.source" version="2.23.0.v20200310-1642"/> + <unit id="org.objenesis" version="2.6.0.v20180420-1519"/> + <unit id="org.objenesis.source" version="2.6.0.v20180420-1519"/> + <unit id="org.slf4j.api" version="1.7.30.v20200204-2150"/> + <unit id="org.slf4j.api.source" version="1.7.30.v20200204-2150"/> + <unit id="org.slf4j.binding.simple" version="1.7.30.v20200204-2150"/> + <unit id="org.slf4j.binding.simple.source" version="1.7.30.v20200204-2150"/> + <unit id="org.tukaani.xz" version="1.9.0.v20210624-1259"/> + <unit id="org.tukaani.xz.source" version="1.9.0.v20210624-1259"/> + <repository location="https://download.eclipse.org/tools/orbit/downloads/drops/R20220531185310/repository"/> + </location> + <location includeMode="slicer" includeAllPlatforms="false" includeSource="true" includeConfigurePhase="true" type="InstallableUnit"> + <unit id="org.eclipse.osgi" version="0.0.0"/> + <repository location="https://download.eclipse.org/staging/2022-09/"/> + </location> + </locations> +</target> diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.25.tpd b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.25.tpd new file mode 100644 index 0000000000..e6a577571d --- /dev/null +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.25.tpd @@ -0,0 +1,8 @@ +target "jgit-4.25" with source configurePhase + +include "projects/jetty-10.0.x.tpd" +include "orbit/R20220531185310-2022-06.tpd" + +location "https://download.eclipse.org/staging/2022-09/" { + org.eclipse.osgi lazy +} diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/orbit/R20211213173813-2021-12.tpd b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/orbit/R20211213173813-2021-12.tpd new file mode 100644 index 0000000000..0c7c846738 --- /dev/null +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/orbit/R20211213173813-2021-12.tpd @@ -0,0 +1,69 @@ +target "R20211213173813-2021-12" with source configurePhase +// see https://download.eclipse.org/tools/orbit/downloads/ + +location "https://download.eclipse.org/tools/orbit/downloads/drops/R20211213173813/repository" { + com.google.gson [2.8.8.v20211029-0838,2.8.8.v20211029-0838] + com.google.gson.source [2.8.8.v20211029-0838,2.8.8.v20211029-0838] + com.jcraft.jsch [0.1.55.v20190404-1902,0.1.55.v20190404-1902] + com.jcraft.jsch.source [0.1.55.v20190404-1902,0.1.55.v20190404-1902] + com.jcraft.jzlib [1.1.1.v201205102305,1.1.1.v201205102305] + com.jcraft.jzlib.source [1.1.1.v201205102305,1.1.1.v201205102305] + com.sun.jna [5.8.0.v20210503-0343,5.8.0.v20210503-0343] + com.sun.jna.source [5.8.0.v20210503-0343,5.8.0.v20210503-0343] + com.sun.jna.platform [5.8.0.v20210406-1004,5.8.0.v20210406-1004] + com.sun.jna.platform.source [5.8.0.v20210406-1004,5.8.0.v20210406-1004] + javaewah [1.1.13.v20211029-0839,1.1.13.v20211029-0839] + javaewah.source [1.1.13.v20211029-0839,1.1.13.v20211029-0839] + net.bytebuddy.byte-buddy [1.9.0.v20181107-1410,1.9.0.v20181107-1410] + net.bytebuddy.byte-buddy-agent [1.9.0.v20181106-1534,1.9.0.v20181106-1534] + net.bytebuddy.byte-buddy-agent.source [1.9.0.v20181106-1534,1.9.0.v20181106-1534] + net.bytebuddy.byte-buddy.source [1.9.0.v20181107-1410,1.9.0.v20181107-1410] + net.i2p.crypto.eddsa [0.3.0.v20210923-1401,0.3.0.v20210923-1401] + net.i2p.crypto.eddsa.source [0.3.0.v20210923-1401,0.3.0.v20210923-1401] + org.apache.ant [1.10.12.v20211102-1452,1.10.12.v20211102-1452] + org.apache.ant.source [1.10.12.v20211102-1452,1.10.12.v20211102-1452] + org.apache.commons.codec [1.14.0.v20200818-1422,1.14.0.v20200818-1422] + org.apache.commons.codec.source [1.14.0.v20200818-1422,1.14.0.v20200818-1422] + org.apache.commons.compress [1.21.0.v20211103-2100,1.21.0.v20211103-2100] + org.apache.commons.compress.source [1.21.0.v20211103-2100,1.21.0.v20211103-2100] + org.apache.commons.logging [1.2.0.v20180409-1502,1.2.0.v20180409-1502] + org.apache.commons.logging.source [1.2.0.v20180409-1502,1.2.0.v20180409-1502] + org.apache.httpcomponents.httpclient [4.5.13.v20210128-2225,4.5.13.v20210128-2225] + org.apache.httpcomponents.httpclient.source [4.5.13.v20210128-2225,4.5.13.v20210128-2225] + org.apache.httpcomponents.httpcore [4.4.14.v20210128-2225,4.4.14.v20210128-2225] + org.apache.httpcomponents.httpcore.source [4.4.14.v20210128-2225,4.4.14.v20210128-2225] + org.apache.sshd.osgi [2.7.0.v20210623-0618,2.7.0.v20210623-0618] + org.apache.sshd.osgi.source [2.7.0.v20210623-0618,2.7.0.v20210623-0618] + org.apache.sshd.sftp [2.7.0.v20210623-0618,2.7.0.v20210623-0618] + org.apache.sshd.sftp.source [2.7.0.v20210623-0618,2.7.0.v20210623-0618] + org.assertj [3.20.2.v20210706-1104,3.20.2.v20210706-1104] + org.assertj.source [3.20.2.v20210706-1104,3.20.2.v20210706-1104] + org.bouncycastle.bcpg [1.69.0.v20210713-1924,1.69.0.v20210713-1924] + org.bouncycastle.bcpg.source [1.69.0.v20210713-1924,1.69.0.v20210713-1924] + org.bouncycastle.bcpkix [1.69.0.v20210713-1924,1.69.0.v20210713-1924] + org.bouncycastle.bcpkix.source [1.69.0.v20210713-1924,1.69.0.v20210713-1924] + org.bouncycastle.bcprov [1.69.0.v20210923-1401,1.69.0.v20210923-1401] + org.bouncycastle.bcprov.source [1.69.0.v20210923-1401,1.69.0.v20210923-1401] + org.bouncycastle.bcutil [1.69.0.v20210713-1924,1.69.0.v20210713-1924] + org.bouncycastle.bcutil.source [1.69.0.v20210713-1924,1.69.0.v20210713-1924] + org.hamcrest [2.2.0.v20210711-0821,2.2.0.v20210711-0821] + org.hamcrest.source [2.2.0.v20210711-0821,2.2.0.v20210711-0821] + org.hamcrest.core [1.3.0.v20180420-1519,1.3.0.v20180420-1519] + org.hamcrest.core.source [1.3.0.v20180420-1519,1.3.0.v20180420-1519] + org.hamcrest.library [1.3.0.v20180524-2246,1.3.0.v20180524-2246] + org.hamcrest.library.source [1.3.0.v20180524-2246,1.3.0.v20180524-2246] + org.junit [4.13.2.v20211018-1956,4.13.2.v20211018-1956] + org.junit.source [4.13.2.v20211018-1956,4.13.2.v20211018-1956] + org.kohsuke.args4j [2.33.0.v20160323-2218,2.33.0.v20160323-2218] + org.kohsuke.args4j.source [2.33.0.v20160323-2218,2.33.0.v20160323-2218] + org.mockito [2.23.0.v20200310-1642,2.23.0.v20200310-1642] + org.mockito.source [2.23.0.v20200310-1642,2.23.0.v20200310-1642] + org.objenesis [2.6.0.v20180420-1519,2.6.0.v20180420-1519] + org.objenesis.source [2.6.0.v20180420-1519,2.6.0.v20180420-1519] + org.slf4j.api [1.7.30.v20200204-2150,1.7.30.v20200204-2150] + org.slf4j.api.source [1.7.30.v20200204-2150,1.7.30.v20200204-2150] + org.slf4j.binding.simple [1.7.30.v20200204-2150,1.7.30.v20200204-2150] + org.slf4j.binding.simple.source [1.7.30.v20200204-2150,1.7.30.v20200204-2150] + org.tukaani.xz [1.9.0.v20210624-1259,1.9.0.v20210624-1259] + org.tukaani.xz.source [1.9.0.v20210624-1259,1.9.0.v20210624-1259] +} diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/orbit/R20220302172233-2022-03.tpd b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/orbit/R20220302172233-2022-03.tpd new file mode 100644 index 0000000000..fafc689268 --- /dev/null +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/orbit/R20220302172233-2022-03.tpd @@ -0,0 +1,69 @@ +target "R20220302172233" with source configurePhase +// see https://download.eclipse.org/tools/orbit/downloads/ + +location "https://download.eclipse.org/tools/orbit/downloads/drops/R20220302172233/repository" { + com.google.gson [2.8.9.v20220111-1409,2.8.9.v20220111-1409] + com.google.gson.source [2.8.9.v20220111-1409,2.8.9.v20220111-1409] + com.jcraft.jsch [0.1.55.v20190404-1902,0.1.55.v20190404-1902] + com.jcraft.jsch.source [0.1.55.v20190404-1902,0.1.55.v20190404-1902] + com.jcraft.jzlib [1.1.1.v201205102305,1.1.1.v201205102305] + com.jcraft.jzlib.source [1.1.1.v201205102305,1.1.1.v201205102305] + com.sun.jna [5.8.0.v20210503-0343,5.8.0.v20210503-0343] + com.sun.jna.source [5.8.0.v20210503-0343,5.8.0.v20210503-0343] + com.sun.jna.platform [5.8.0.v20210406-1004,5.8.0.v20210406-1004] + com.sun.jna.platform.source [5.8.0.v20210406-1004,5.8.0.v20210406-1004] + javaewah [1.1.13.v20211029-0839,1.1.13.v20211029-0839] + javaewah.source [1.1.13.v20211029-0839,1.1.13.v20211029-0839] + net.bytebuddy.byte-buddy [1.9.0.v20181107-1410,1.9.0.v20181107-1410] + net.bytebuddy.byte-buddy-agent [1.9.0.v20181106-1534,1.9.0.v20181106-1534] + net.bytebuddy.byte-buddy-agent.source [1.9.0.v20181106-1534,1.9.0.v20181106-1534] + net.bytebuddy.byte-buddy.source [1.9.0.v20181107-1410,1.9.0.v20181107-1410] + net.i2p.crypto.eddsa [0.3.0.v20210923-1401,0.3.0.v20210923-1401] + net.i2p.crypto.eddsa.source [0.3.0.v20210923-1401,0.3.0.v20210923-1401] + org.apache.ant [1.10.12.v20211102-1452,1.10.12.v20211102-1452] + org.apache.ant.source [1.10.12.v20211102-1452,1.10.12.v20211102-1452] + org.apache.commons.codec [1.14.0.v20200818-1422,1.14.0.v20200818-1422] + org.apache.commons.codec.source [1.14.0.v20200818-1422,1.14.0.v20200818-1422] + org.apache.commons.compress [1.21.0.v20211103-2100,1.21.0.v20211103-2100] + org.apache.commons.compress.source [1.21.0.v20211103-2100,1.21.0.v20211103-2100] + org.apache.commons.logging [1.2.0.v20180409-1502,1.2.0.v20180409-1502] + org.apache.commons.logging.source [1.2.0.v20180409-1502,1.2.0.v20180409-1502] + org.apache.httpcomponents.httpclient [4.5.13.v20210128-2225,4.5.13.v20210128-2225] + org.apache.httpcomponents.httpclient.source [4.5.13.v20210128-2225,4.5.13.v20210128-2225] + org.apache.httpcomponents.httpcore [4.4.15.v20220209-2345,4.4.15.v20220209-2345] + org.apache.httpcomponents.httpcore.source [4.4.15.v20220209-2345,4.4.15.v20220209-2345] + org.apache.sshd.osgi [2.8.0.v20211227-1750,2.8.0.v20211227-1750] + org.apache.sshd.osgi.source [2.8.0.v20211227-1750,2.8.0.v20211227-1750] + org.apache.sshd.sftp [2.8.0.v20211227-1750,2.8.0.v20211227-1750] + org.apache.sshd.sftp.source [2.8.0.v20211227-1750,2.8.0.v20211227-1750] + org.assertj [3.20.2.v20210706-1104,3.20.2.v20210706-1104] + org.assertj.source [3.20.2.v20210706-1104,3.20.2.v20210706-1104] + org.bouncycastle.bcpg [1.70.0.v20220105-1522,1.70.0.v20220105-1522] + org.bouncycastle.bcpg.source [1.70.0.v20220105-1522,1.70.0.v20220105-1522] + org.bouncycastle.bcpkix [1.70.0.v20220105-1522,1.70.0.v20220105-1522] + org.bouncycastle.bcpkix.source [1.70.0.v20220105-1522,1.70.0.v20220105-1522] + org.bouncycastle.bcprov [1.70.0.v20220105-1522,1.70.0.v20220105-1522] + org.bouncycastle.bcprov.source [1.70.0.v20220105-1522,1.70.0.v20220105-1522] + org.bouncycastle.bcutil [1.70.0.v20220105-1522,1.70.0.v20220105-1522] + org.bouncycastle.bcutil.source [1.70.0.v20220105-1522,1.70.0.v20220105-1522] + org.hamcrest [2.2.0.v20210711-0821,2.2.0.v20210711-0821] + org.hamcrest.source [2.2.0.v20210711-0821,2.2.0.v20210711-0821] + org.hamcrest.core [1.3.0.v20180420-1519,1.3.0.v20180420-1519] + org.hamcrest.core.source [1.3.0.v20180420-1519,1.3.0.v20180420-1519] + org.hamcrest.library [1.3.0.v20180524-2246,1.3.0.v20180524-2246] + org.hamcrest.library.source [1.3.0.v20180524-2246,1.3.0.v20180524-2246] + org.junit [4.13.2.v20211018-1956,4.13.2.v20211018-1956] + org.junit.source [4.13.2.v20211018-1956,4.13.2.v20211018-1956] + org.kohsuke.args4j [2.33.0.v20160323-2218,2.33.0.v20160323-2218] + org.kohsuke.args4j.source [2.33.0.v20160323-2218,2.33.0.v20160323-2218] + org.mockito [2.23.0.v20200310-1642,2.23.0.v20200310-1642] + org.mockito.source [2.23.0.v20200310-1642,2.23.0.v20200310-1642] + org.objenesis [2.6.0.v20180420-1519,2.6.0.v20180420-1519] + org.objenesis.source [2.6.0.v20180420-1519,2.6.0.v20180420-1519] + org.slf4j.api [1.7.30.v20200204-2150,1.7.30.v20200204-2150] + org.slf4j.api.source [1.7.30.v20200204-2150,1.7.30.v20200204-2150] + org.slf4j.binding.simple [1.7.30.v20200204-2150,1.7.30.v20200204-2150] + org.slf4j.binding.simple.source [1.7.30.v20200204-2150,1.7.30.v20200204-2150] + org.tukaani.xz [1.9.0.v20210624-1259,1.9.0.v20210624-1259] + org.tukaani.xz.source [1.9.0.v20210624-1259,1.9.0.v20210624-1259] +} diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/orbit/R20220531185310-2022-06.tpd b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/orbit/R20220531185310-2022-06.tpd new file mode 100644 index 0000000000..3c74497c21 --- /dev/null +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/orbit/R20220531185310-2022-06.tpd @@ -0,0 +1,69 @@ +target "R20220531185310-2022-06" with source configurePhase +// see https://download.eclipse.org/tools/orbit/downloads/ + +location "https://download.eclipse.org/tools/orbit/downloads/drops/R20220531185310/repository" { + com.google.gson [2.8.9.v20220111-1409,2.8.9.v20220111-1409] + com.google.gson.source [2.8.9.v20220111-1409,2.8.9.v20220111-1409] + com.jcraft.jsch [0.1.55.v20190404-1902,0.1.55.v20190404-1902] + com.jcraft.jsch.source [0.1.55.v20190404-1902,0.1.55.v20190404-1902] + com.jcraft.jzlib [1.1.3.v20220502-1820,1.1.3.v20220502-1820] + com.jcraft.jzlib.source [1.1.3.v20220502-1820,1.1.3.v20220502-1820] + com.sun.jna [5.8.0.v20210503-0343,5.8.0.v20210503-0343] + com.sun.jna.source [5.8.0.v20210503-0343,5.8.0.v20210503-0343] + com.sun.jna.platform [5.8.0.v20210406-1004,5.8.0.v20210406-1004] + com.sun.jna.platform.source [5.8.0.v20210406-1004,5.8.0.v20210406-1004] + javaewah [1.1.13.v20211029-0839,1.1.13.v20211029-0839] + javaewah.source [1.1.13.v20211029-0839,1.1.13.v20211029-0839] + net.bytebuddy.byte-buddy [1.9.0.v20181107-1410,1.9.0.v20181107-1410] + net.bytebuddy.byte-buddy-agent [1.9.0.v20181106-1534,1.9.0.v20181106-1534] + net.bytebuddy.byte-buddy-agent.source [1.9.0.v20181106-1534,1.9.0.v20181106-1534] + net.bytebuddy.byte-buddy.source [1.9.0.v20181107-1410,1.9.0.v20181107-1410] + net.i2p.crypto.eddsa [0.3.0.v20220506-1020,0.3.0.v20220506-1020] + net.i2p.crypto.eddsa.source [0.3.0.v20220506-1020,0.3.0.v20220506-1020] + org.apache.ant [1.10.12.v20211102-1452,1.10.12.v20211102-1452] + org.apache.ant.source [1.10.12.v20211102-1452,1.10.12.v20211102-1452] + org.apache.commons.codec [1.14.0.v20200818-1422,1.14.0.v20200818-1422] + org.apache.commons.codec.source [1.14.0.v20200818-1422,1.14.0.v20200818-1422] + org.apache.commons.compress [1.21.0.v20211103-2100,1.21.0.v20211103-2100] + org.apache.commons.compress.source [1.21.0.v20211103-2100,1.21.0.v20211103-2100] + org.apache.commons.logging [1.2.0.v20180409-1502,1.2.0.v20180409-1502] + org.apache.commons.logging.source [1.2.0.v20180409-1502,1.2.0.v20180409-1502] + org.apache.httpcomponents.httpclient [4.5.13.v20210128-2225,4.5.13.v20210128-2225] + org.apache.httpcomponents.httpclient.source [4.5.13.v20210128-2225,4.5.13.v20210128-2225] + org.apache.httpcomponents.httpcore [4.4.15.v20220209-2345,4.4.15.v20220209-2345] + org.apache.httpcomponents.httpcore.source [4.4.15.v20220209-2345,4.4.15.v20220209-2345] + org.apache.sshd.osgi [2.8.0.v20211227-1750,2.8.0.v20211227-1750] + org.apache.sshd.osgi.source [2.8.0.v20211227-1750,2.8.0.v20211227-1750] + org.apache.sshd.sftp [2.8.0.v20211227-1750,2.8.0.v20211227-1750] + org.apache.sshd.sftp.source [2.8.0.v20211227-1750,2.8.0.v20211227-1750] + org.assertj [3.20.2.v20210706-1104,3.20.2.v20210706-1104] + org.assertj.source [3.20.2.v20210706-1104,3.20.2.v20210706-1104] + org.bouncycastle.bcpg [1.70.0.v20220507-1208,1.70.0.v20220507-1208] + org.bouncycastle.bcpg.source [1.70.0.v20220507-1208,1.70.0.v20220507-1208] + org.bouncycastle.bcpkix [1.70.0.v20220105-1522,1.70.0.v20220105-1522] + org.bouncycastle.bcpkix.source [1.70.0.v20220105-1522,1.70.0.v20220105-1522] + org.bouncycastle.bcprov [1.70.0.v20220507-1208,1.70.0.v20220507-1208] + org.bouncycastle.bcprov.source [1.70.0.v20220507-1208,1.70.0.v20220507-1208] + org.bouncycastle.bcutil [1.70.0.v20220105-1522,1.70.0.v20220105-1522] + org.bouncycastle.bcutil.source [1.70.0.v20220105-1522,1.70.0.v20220105-1522] + org.hamcrest [2.2.0.v20210711-0821,2.2.0.v20210711-0821] + org.hamcrest.source [2.2.0.v20210711-0821,2.2.0.v20210711-0821] + org.hamcrest.core [1.3.0.v20180420-1519,1.3.0.v20180420-1519] + org.hamcrest.core.source [1.3.0.v20180420-1519,1.3.0.v20180420-1519] + org.hamcrest.library [1.3.0.v20180524-2246,1.3.0.v20180524-2246] + org.hamcrest.library.source [1.3.0.v20180524-2246,1.3.0.v20180524-2246] + org.junit [4.13.2.v20211018-1956,4.13.2.v20211018-1956] + org.junit.source [4.13.2.v20211018-1956,4.13.2.v20211018-1956] + org.kohsuke.args4j [2.33.0.v20160323-2218,2.33.0.v20160323-2218] + org.kohsuke.args4j.source [2.33.0.v20160323-2218,2.33.0.v20160323-2218] + org.mockito [2.23.0.v20200310-1642,2.23.0.v20200310-1642] + org.mockito.source [2.23.0.v20200310-1642,2.23.0.v20200310-1642] + org.objenesis [2.6.0.v20180420-1519,2.6.0.v20180420-1519] + org.objenesis.source [2.6.0.v20180420-1519,2.6.0.v20180420-1519] + org.slf4j.api [1.7.30.v20200204-2150,1.7.30.v20200204-2150] + org.slf4j.api.source [1.7.30.v20200204-2150,1.7.30.v20200204-2150] + org.slf4j.binding.simple [1.7.30.v20200204-2150,1.7.30.v20200204-2150] + org.slf4j.binding.simple.source [1.7.30.v20200204-2150,1.7.30.v20200204-2150] + org.tukaani.xz [1.9.0.v20210624-1259,1.9.0.v20210624-1259] + org.tukaani.xz.source [1.9.0.v20210624-1259,1.9.0.v20210624-1259] +} diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/pom.xml b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/pom.xml index 6744f6b047..71d2e93414 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/pom.xml +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/pom.xml @@ -22,31 +22,4 @@ <artifactId>org.eclipse.jgit.target</artifactId> <packaging>pom</packaging> <name>JGit Target Platform</name> - - <build> - <plugins> - <plugin> - <groupId>org.codehaus.mojo</groupId> - <artifactId>build-helper-maven-plugin</artifactId> - <executions> - <execution> - <id>attach-artifacts</id> - <phase>package</phase> - <goals> - <goal>attach-artifact</goal> - </goals> - <configuration> - <artifacts> - <artifact> - <file>${target-platform}.target</file> - <type>target</type> - <classifier>${target-platform}</classifier> - </artifact> - </artifacts> - </configuration> - </execution> - </executions> - </plugin> - </plugins> - </build> </project>
\ No newline at end of file diff --git a/org.eclipse.jgit.packaging/pom.xml b/org.eclipse.jgit.packaging/pom.xml index e2b7b79478..60206619f7 100644 --- a/org.eclipse.jgit.packaging/pom.xml +++ b/org.eclipse.jgit.packaging/pom.xml @@ -23,7 +23,7 @@ <properties> <java.version>11</java.version> - <tycho-version>2.5.0</tycho-version> + <tycho-version>2.6.0</tycho-version> <tycho-extras-version>${tycho-version}</tycho-extras-version> <target-platform>jgit-4.17</target-platform> </properties> @@ -231,12 +231,7 @@ <resolver>p2</resolver> <pomDependencies>consider</pomDependencies> <target> - <artifact> - <groupId>org.eclipse.jgit</groupId> - <artifactId>org.eclipse.jgit.target</artifactId> - <version>${project.version}</version> - <classifier>${target-platform}</classifier> - </artifact> + <file>${project.basedir}/../org.eclipse.jgit.target/${target-platform}.target</file> </target> <environments> <environment> @@ -264,6 +259,11 @@ <ws>cocoa</ws> <arch>x86_64</arch> </environment> + <environment> + <os>macosx</os> + <ws>cocoa</ws> + <arch>aarch64</arch> + </environment> </environments> </configuration> </plugin> diff --git a/org.eclipse.jgit.pgm.test/META-INF/MANIFEST.MF b/org.eclipse.jgit.pgm.test/META-INF/MANIFEST.MF index 9f9ee463b7..23f7c34a52 100644 --- a/org.eclipse.jgit.pgm.test/META-INF/MANIFEST.MF +++ b/org.eclipse.jgit.pgm.test/META-INF/MANIFEST.MF @@ -12,7 +12,8 @@ Import-Package: org.eclipse.jgit.api;version="[7.0.0,7.1.0)", org.eclipse.jgit.api.errors;version="[7.0.0,7.1.0)", org.eclipse.jgit.diff;version="[7.0.0,7.1.0)", org.eclipse.jgit.dircache;version="[7.0.0,7.1.0)", - org.eclipse.jgit.internal.storage.file;version="7.0.0", + org.eclipse.jgit.internal.diffmergetool;version="[7.0.0,7.1.0)", + org.eclipse.jgit.internal.storage.file;version="[7.0.0,7.1.0)", org.eclipse.jgit.junit;version="[7.0.0,7.1.0)", org.eclipse.jgit.lib;version="[7.0.0,7.1.0)", org.eclipse.jgit.lib.internal;version="[7.0.0,7.1.0)", @@ -26,7 +27,7 @@ Import-Package: org.eclipse.jgit.api;version="[7.0.0,7.1.0)", org.eclipse.jgit.treewalk;version="[7.0.0,7.1.0)", org.eclipse.jgit.util;version="[7.0.0,7.1.0)", org.eclipse.jgit.util.io;version="[7.0.0,7.1.0)", - org.hamcrest.core;bundle-version="[2.2.0,3.0.0)", + org.hamcrest.core;bundle-version="[1.1.0,3.0.0)", org.junit;version="[4.13,5.0.0)", org.junit.rules;version="[4.13,5.0.0)", org.kohsuke.args4j;version="[2.33.0,3.0.0)" diff --git a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/DescribeTest.java b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/DescribeTest.java index 4bad73b5b5..c78544309b 100644 --- a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/DescribeTest.java +++ b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/DescribeTest.java @@ -89,6 +89,31 @@ public class DescribeTest extends CLIRepositoryTestCase { } @Test + public void testDescribeCommitMatchAbbrev() throws Exception { + initialCommitAndTag(); + secondCommit(); + assertArrayEquals(new String[] { "v1.0-1-g56f6cebdf3f5", "" }, + execute("git describe --abbrev 12 --match v1.*")); + } + + @Test + public void testDescribeCommitMatchAbbrevMin() throws Exception { + initialCommitAndTag(); + secondCommit(); + assertArrayEquals(new String[] { "v1.0-1-g56f6", "" }, + execute("git describe --abbrev -5 --match v1.*")); + } + + @Test + public void testDescribeCommitMatchAbbrevMax() throws Exception { + initialCommitAndTag(); + secondCommit(); + assertArrayEquals(new String[] { + "v1.0-1-g56f6cebdf3f5ceeecd803365abf0996fb1fa006d", "" }, + execute("git describe --abbrev 50 --match v1.*")); + } + + @Test public void testDescribeCommitMatch2() throws Exception { initialCommitAndTag(); secondCommit(); diff --git a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/DiffToolTest.java b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/DiffToolTest.java index e7bf48417d..f0908cebc4 100644 --- a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/DiffToolTest.java +++ b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/DiffToolTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021, Simeon Andreev <simeon.danailov.andreev@gmail.com> and others. + * Copyright (C) 2021-2022, Simeon Andreev <simeon.danailov.andreev@gmail.com> and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Distribution License v. 1.0 which is available at @@ -9,72 +9,147 @@ */ package org.eclipse.jgit.pgm; -import static org.junit.Assert.assertEquals; +import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_DIFFTOOL_SECTION; +import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_DIFF_SECTION; +import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_CMD; +import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_PROMPT; +import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_TOOL; +import static org.junit.Assert.fail; +import java.io.File; +import java.io.InputStream; +import java.nio.file.Path; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Map; +import java.util.regex.Pattern; -import org.eclipse.jgit.api.Git; -import org.eclipse.jgit.diff.DiffEntry; -import org.eclipse.jgit.internal.diffmergetool.CommandLineDiffTool; -import org.eclipse.jgit.lib.CLIRepositoryTestCase; -import org.eclipse.jgit.pgm.opt.CmdLineParser; -import org.eclipse.jgit.pgm.opt.SubcommandHandler; -import org.eclipse.jgit.revwalk.RevCommit; -import org.eclipse.jgit.treewalk.FileTreeIterator; -import org.eclipse.jgit.treewalk.TreeWalk; +import org.eclipse.jgit.internal.diffmergetool.DiffTools; +import org.eclipse.jgit.internal.diffmergetool.ExternalDiffTool; +import org.eclipse.jgit.lib.StoredConfig; import org.junit.Before; import org.junit.Test; -import org.kohsuke.args4j.Argument; /** * Testing the {@code difftool} command. */ -public class DiffToolTest extends CLIRepositoryTestCase { - public static class GitCliJGitWrapperParser { - @Argument(index = 0, metaVar = "metaVar_command", required = true, handler = SubcommandHandler.class) - TextBuiltin subcommand; +public class DiffToolTest extends ToolTestCase { - @Argument(index = 1, metaVar = "metaVar_arg") - List<String> arguments = new ArrayList<>(); - } + private static final String DIFF_TOOL = CONFIG_DIFFTOOL_SECTION; - private String[] runAndCaptureUsingInitRaw(String... args) - throws Exception { - CLIGitCommand.Result result = new CLIGitCommand.Result(); + @Override + @Before + public void setUp() throws Exception { + super.setUp(); + configureEchoTool(TOOL_NAME); + } - GitCliJGitWrapperParser bean = new GitCliJGitWrapperParser(); - CmdLineParser clp = new CmdLineParser(bean); - clp.parseArgument(args); + @Test(expected = Die.class) + public void testUndefinedTool() throws Exception { + String toolName = "undefined"; + String[] conflictingFilenames = createUnstagedChanges(); - TextBuiltin cmd = bean.subcommand; - cmd.initRaw(db, null, null, result.out, result.err); - cmd.execute(bean.arguments.toArray(new String[bean.arguments.size()])); - if (cmd.getOutputWriter() != null) { - cmd.getOutputWriter().flush(); + List<String> expectedErrors = new ArrayList<>(); + for (String changedFilename : conflictingFilenames) { + expectedErrors.add("External diff tool is not defined: " + toolName); + expectedErrors.add("compare of " + changedFilename + " failed"); } - if (cmd.getErrorWriter() != null) { - cmd.getErrorWriter().flush(); - } - return result.outLines().toArray(new String[0]); + + runAndCaptureUsingInitRaw(expectedErrors, DIFF_TOOL, "--no-prompt", + "--tool", toolName); + fail("Expected exception to be thrown due to undefined external tool"); } - private Git git; + @Test(expected = Die.class) + public void testUserToolWithCommandNotFoundError() throws Exception { + String toolName = "customTool"; - @Override - @Before - public void setUp() throws Exception { - super.setUp(); - git = new Git(db); - git.commit().setMessage("initial commit").call(); + int errorReturnCode = 127; // command not found + String command = "exit " + errorReturnCode; + + StoredConfig config = db.getConfig(); + config.setString(CONFIG_DIFFTOOL_SECTION, toolName, CONFIG_KEY_CMD, + command); + + createMergeConflict(); + runAndCaptureUsingInitRaw(DIFF_TOOL, "--no-prompt", "--tool", toolName); + + fail("Expected exception to be thrown due to external tool exiting with error code: " + + errorReturnCode); + } + + @Test(expected = Die.class) + public void testEmptyToolName() throws Exception { + assumeLinuxPlatform(); + + String emptyToolName = ""; + + StoredConfig config = db.getConfig(); + // the default diff tool is configured without a subsection + String subsection = null; + config.setString(CONFIG_DIFF_SECTION, subsection, CONFIG_KEY_TOOL, + emptyToolName); + + createUnstagedChanges(); + + String araxisErrorLine = "compare: unrecognized option `-wait' @ error/compare.c/CompareImageCommand/1123."; + String[] expectedErrorOutput = { araxisErrorLine, araxisErrorLine, }; + runAndCaptureUsingInitRaw(Arrays.asList(expectedErrorOutput), DIFF_TOOL, + "--no-prompt"); + fail("Expected exception to be thrown due to external tool exiting with an error"); + } + + @Test + public void testToolWithPrompt() throws Exception { + String[] inputLines = { + "y", // accept launching diff tool + "y", // accept launching diff tool + }; + + String[] conflictingFilenames = createUnstagedChanges(); + String[] expectedOutput = getExpectedCompareOutput(conflictingFilenames); + + String option = "--tool"; + + InputStream inputStream = createInputStream(inputLines); + assertArrayOfLinesEquals("Incorrect output for option: " + option, + expectedOutput, runAndCaptureUsingInitRaw(inputStream, + DIFF_TOOL, "--prompt", option, TOOL_NAME)); + } + + @Test + public void testToolAbortLaunch() throws Exception { + String[] inputLines = { + "y", // accept launching diff tool + "n", // don't launch diff tool + }; + + String[] conflictingFilenames = createUnstagedChanges(); + int abortIndex = 1; + String[] expectedOutput = getExpectedAbortOutput(conflictingFilenames, abortIndex); + + String option = "--tool"; + + InputStream inputStream = createInputStream(inputLines); + assertArrayOfLinesEquals("Incorrect output for option: " + option, + expectedOutput, + runAndCaptureUsingInitRaw(inputStream, DIFF_TOOL, "--prompt", option, + TOOL_NAME)); + } + + @Test(expected = Die.class) + public void testNotDefinedTool() throws Exception { + createUnstagedChanges(); + + runAndCaptureUsingInitRaw(DIFF_TOOL, "--tool", "undefined"); + fail("Expected exception when trying to run undefined tool"); } @Test public void testTool() throws Exception { - RevCommit commit = createUnstagedChanges(); - List<DiffEntry> changes = getRepositoryChanges(commit); - String[] expectedOutput = getExpectedDiffToolOutput(changes); + String[] conflictFilenames = createUnstagedChanges(); + String[] expectedOutput = getExpectedToolOutputNoPrompt(conflictFilenames); String[] options = { "--tool", @@ -84,69 +159,88 @@ public class DiffToolTest extends CLIRepositoryTestCase { for (String option : options) { assertArrayOfLinesEquals("Incorrect output for option: " + option, expectedOutput, - runAndCaptureUsingInitRaw("difftool", option, - "some_tool")); + runAndCaptureUsingInitRaw(DIFF_TOOL, option, + TOOL_NAME)); } } @Test public void testToolTrustExitCode() throws Exception { - RevCommit commit = createUnstagedChanges(); - List<DiffEntry> changes = getRepositoryChanges(commit); - String[] expectedOutput = getExpectedDiffToolOutput(changes); + String[] conflictingFilenames = createUnstagedChanges(); + String[] expectedOutput = getExpectedToolOutputNoPrompt(conflictingFilenames); String[] options = { "--tool", "-t", }; for (String option : options) { assertArrayOfLinesEquals("Incorrect output for option: " + option, - expectedOutput, runAndCaptureUsingInitRaw("difftool", - "--trust-exit-code", option, "some_tool")); + expectedOutput, runAndCaptureUsingInitRaw(DIFF_TOOL, + "--trust-exit-code", option, TOOL_NAME)); } } @Test public void testToolNoGuiNoPromptNoTrustExitcode() throws Exception { - RevCommit commit = createUnstagedChanges(); - List<DiffEntry> changes = getRepositoryChanges(commit); - String[] expectedOutput = getExpectedDiffToolOutput(changes); + String[] conflictingFilenames = createUnstagedChanges(); + String[] expectedOutput = getExpectedToolOutputNoPrompt(conflictingFilenames); String[] options = { "--tool", "-t", }; for (String option : options) { assertArrayOfLinesEquals("Incorrect output for option: " + option, - expectedOutput, runAndCaptureUsingInitRaw("difftool", + expectedOutput, runAndCaptureUsingInitRaw(DIFF_TOOL, "--no-gui", "--no-prompt", "--no-trust-exit-code", - option, "some_tool")); + option, TOOL_NAME)); } } @Test public void testToolCached() throws Exception { - RevCommit commit = createStagedChanges(); - List<DiffEntry> changes = getRepositoryChanges(commit); - String[] expectedOutput = getExpectedDiffToolOutput(changes); + String[] conflictingFilenames = createStagedChanges(); + Pattern[] expectedOutput = getExpectedCachedToolOutputNoPrompt(conflictingFilenames); String[] options = { "--cached", "--staged", }; for (String option : options) { - assertArrayOfLinesEquals("Incorrect output for option: " + option, - expectedOutput, runAndCaptureUsingInitRaw("difftool", - option, "--tool", "some_tool")); + assertArrayOfMatchingLines("Incorrect output for option: " + option, + expectedOutput, runAndCaptureUsingInitRaw(DIFF_TOOL, + option, "--tool", TOOL_NAME)); } } @Test public void testToolHelp() throws Exception { - CommandLineDiffTool[] defaultTools = CommandLineDiffTool.values(); List<String> expectedOutput = new ArrayList<>(); - expectedOutput.add("git difftool --tool=<tool> may be set to one of the following:"); - for (CommandLineDiffTool defaultTool : defaultTools) { - String toolName = defaultTool.name(); + + DiffTools diffTools = new DiffTools(db); + Map<String, ExternalDiffTool> predefinedTools = diffTools + .getPredefinedTools(true); + List<ExternalDiffTool> availableTools = new ArrayList<>(); + List<ExternalDiffTool> notAvailableTools = new ArrayList<>(); + for (ExternalDiffTool tool : predefinedTools.values()) { + if (tool.isAvailable()) { + availableTools.add(tool); + } else { + notAvailableTools.add(tool); + } + } + + expectedOutput.add( + "'git difftool --tool=<tool>' may be set to one of the following:"); + for (ExternalDiffTool tool : availableTools) { + String toolName = tool.getName(); + expectedOutput.add(toolName); + } + String customToolHelpLine = TOOL_NAME + "." + CONFIG_KEY_CMD + " " + + getEchoCommand(); + expectedOutput.add("user-defined:"); + expectedOutput.add(customToolHelpLine); + expectedOutput.add( + "The following tools are valid, but not currently available:"); + for (ExternalDiffTool tool : notAvailableTools) { + String toolName = tool.getName(); expectedOutput.add(toolName); } String[] userDefinedToolsHelp = { - "user-defined:", - "The following tools are valid, but not currently available:", "Some of the tools listed above only work in a windowed", "environment. If run in a terminal-only session, they will fail.", }; @@ -154,52 +248,99 @@ public class DiffToolTest extends CLIRepositoryTestCase { String option = "--tool-help"; assertArrayOfLinesEquals("Incorrect output for option: " + option, - expectedOutput.toArray(new String[0]), runAndCaptureUsingInitRaw("difftool", option)); - } - - private RevCommit createUnstagedChanges() throws Exception { - writeTrashFile("a", "Hello world a"); - writeTrashFile("b", "Hello world b"); - git.add().addFilepattern(".").call(); - RevCommit commit = git.commit().setMessage("files a & b").call(); - writeTrashFile("a", "New Hello world a"); - writeTrashFile("b", "New Hello world b"); - return commit; - } - - private RevCommit createStagedChanges() throws Exception { - RevCommit commit = createUnstagedChanges(); - git.add().addFilepattern(".").call(); - return commit; - } - - private List<DiffEntry> getRepositoryChanges(RevCommit commit) - throws Exception { - TreeWalk tw = new TreeWalk(db); - tw.addTree(commit.getTree()); - FileTreeIterator modifiedTree = new FileTreeIterator(db); - tw.addTree(modifiedTree); - List<DiffEntry> changes = DiffEntry.scan(tw); - return changes; - } - - private String[] getExpectedDiffToolOutput(List<DiffEntry> changes) { - String[] expectedToolOutput = new String[changes.size()]; - for (int i = 0; i < changes.size(); ++i) { - DiffEntry change = changes.get(i); - String newPath = change.getNewPath(); - String oldPath = change.getOldPath(); - String newIdName = change.getNewId().name(); - String oldIdName = change.getOldId().name(); - String expectedLine = "M\t" + newPath + " (" + newIdName + ")" - + "\t" + oldPath + " (" + oldIdName + ")"; - expectedToolOutput[i] = expectedLine; + expectedOutput.toArray(new String[0]), + runAndCaptureUsingInitRaw(DIFF_TOOL, option)); + } + + private void configureEchoTool(String toolName) { + StoredConfig config = db.getConfig(); + // the default diff tool is configured without a subsection + String subsection = null; + config.setString(CONFIG_DIFF_SECTION, subsection, CONFIG_KEY_TOOL, + toolName); + + String command = getEchoCommand(); + + config.setString(CONFIG_DIFFTOOL_SECTION, toolName, CONFIG_KEY_CMD, + command); + /* + * prevent prompts as we are running in tests and there is no user to + * interact with on the command line + */ + config.setString(CONFIG_DIFFTOOL_SECTION, toolName, CONFIG_KEY_PROMPT, + String.valueOf(false)); + } + + private String[] getExpectedToolOutputNoPrompt(String[] conflictingFilenames) { + String[] expectedToolOutput = new String[conflictingFilenames.length]; + for (int i = 0; i < conflictingFilenames.length; ++i) { + String newPath = conflictingFilenames[i]; + Path fullPath = getFullPath(newPath); + expectedToolOutput[i] = fullPath.toString(); } return expectedToolOutput; } - private static void assertArrayOfLinesEquals(String failMessage, - String[] expected, String[] actual) { - assertEquals(failMessage, toString(expected), toString(actual)); + private Pattern[] getExpectedCachedToolOutputNoPrompt(String[] conflictingFilenames) { + String tmpDir = System.getProperty("java.io.tmpdir"); + if (tmpDir.endsWith(File.separator)) { + tmpDir = tmpDir.substring(0, tmpDir.length() - 1); + } + Pattern emptyPattern = Pattern.compile(""); + List<Pattern> expectedToolOutput = new ArrayList<>(); + for (int i = 0; i < conflictingFilenames.length; ++i) { + String changedFilename = conflictingFilenames[i]; + Path fullPath = getFullPath(changedFilename); + String filename = fullPath.getFileName().toString(); + String regexp = tmpDir + File.separatorChar + filename + + "_REMOTE_.*"; + Pattern pattern = Pattern.compile(regexp); + expectedToolOutput.add(pattern); + expectedToolOutput.add(emptyPattern); + } + expectedToolOutput.add(emptyPattern); + return expectedToolOutput.toArray(new Pattern[0]); + } + + private String[] getExpectedCompareOutput(String[] conflictingFilenames) { + List<String> expected = new ArrayList<>(); + int n = conflictingFilenames.length; + for (int i = 0; i < n; ++i) { + String changedFilename = conflictingFilenames[i]; + expected.add( + "Viewing (" + (i + 1) + "/" + n + "): '" + changedFilename + + "'"); + expected.add("Launch '" + TOOL_NAME + "' [Y/n]?"); + Path fullPath = getFullPath(changedFilename); + expected.add(fullPath.toString()); + } + return expected.toArray(new String[0]); + } + + private String[] getExpectedAbortOutput(String[] conflictingFilenames, + int abortIndex) { + List<String> expected = new ArrayList<>(); + int n = conflictingFilenames.length; + for (int i = 0; i < n; ++i) { + String changedFilename = conflictingFilenames[i]; + expected.add( + "Viewing (" + (i + 1) + "/" + n + "): '" + changedFilename + + "'"); + expected.add("Launch '" + TOOL_NAME + "' [Y/n]?"); + if (i == abortIndex) { + break; + } + Path fullPath = getFullPath(changedFilename); + expected.add(fullPath.toString()); + } + return expected.toArray(new String[0]); + } + + private static String getEchoCommand() { + /* + * use 'REMOTE' placeholder, as it will be replaced by a file path + * within the repository. + */ + return "(echo \"$REMOTE\")"; } } diff --git a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/FetchTest.java b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/FetchTest.java index 564bd5fa94..1c6b7839d3 100644 --- a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/FetchTest.java +++ b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/FetchTest.java @@ -33,6 +33,7 @@ public class FetchTest extends CLIRepositoryTestCase { git.commit().setMessage("initial commit").call(); Repository remoteRepository = createWorkRepository(); + addRepoToClose(remoteRepository); remoteGit = new Git(remoteRepository); // setup the first repository to fetch from the second repository diff --git a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/MergeToolTest.java b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/MergeToolTest.java new file mode 100644 index 0000000000..54c4f26099 --- /dev/null +++ b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/MergeToolTest.java @@ -0,0 +1,397 @@ +/* + * Copyright (C) 2022, Simeon Andreev <simeon.danailov.andreev@gmail.com> and others. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Distribution License v. 1.0 which is available at + * https://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: BSD-3-Clause + */ +package org.eclipse.jgit.pgm; + +import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_CMD; +import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_PROMPT; +import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_TOOL; +import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_MERGETOOL_SECTION; +import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_MERGE_SECTION; +import static org.junit.Assert.fail; + +import java.io.InputStream; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +import org.eclipse.jgit.internal.diffmergetool.ExternalMergeTool; +import org.eclipse.jgit.internal.diffmergetool.MergeTools; +import org.eclipse.jgit.lib.StoredConfig; +import org.junit.Before; +import org.junit.Test; + +/** + * Testing the {@code mergetool} command. + */ +public class MergeToolTest extends ToolTestCase { + + private static final String MERGE_TOOL = CONFIG_MERGETOOL_SECTION; + + @Override + @Before + public void setUp() throws Exception { + super.setUp(); + configureEchoTool(TOOL_NAME); + } + + @Test + public void testUndefinedTool() throws Exception { + String toolName = "undefined"; + String[] conflictingFilenames = createMergeConflict(); + + List<String> expectedErrors = new ArrayList<>(); + for (String conflictingFilename : conflictingFilenames) { + expectedErrors.add("External merge tool is not defined: " + toolName); + expectedErrors.add("merge of " + conflictingFilename + " failed"); + } + + runAndCaptureUsingInitRaw(expectedErrors, MERGE_TOOL, + "--no-prompt", "--tool", toolName); + } + + @Test(expected = Die.class) + public void testUserToolWithCommandNotFoundError() throws Exception { + String toolName = "customTool"; + + int errorReturnCode = 127; // command not found + String command = "exit " + errorReturnCode; + + StoredConfig config = db.getConfig(); + config.setString(CONFIG_MERGETOOL_SECTION, toolName, CONFIG_KEY_CMD, + command); + + createMergeConflict(); + runAndCaptureUsingInitRaw(MERGE_TOOL, "--no-prompt", "--tool", + toolName); + + fail("Expected exception to be thrown due to external tool exiting with error code: " + + errorReturnCode); + } + + @Test + public void testEmptyToolName() throws Exception { + assumeLinuxPlatform(); + + String emptyToolName = ""; + + StoredConfig config = db.getConfig(); + // the default merge tool is configured without a subsection + String subsection = null; + config.setString(CONFIG_MERGE_SECTION, subsection, CONFIG_KEY_TOOL, + emptyToolName); + + createMergeConflict(); + + String araxisErrorLine = "compare: unrecognized option `-wait' @ error/compare.c/CompareImageCommand/1123."; + String[] expectedErrorOutput = { araxisErrorLine, araxisErrorLine, }; + runAndCaptureUsingInitRaw(Arrays.asList(expectedErrorOutput), + MERGE_TOOL, "--no-prompt"); + } + + @Test + public void testAbortMerge() throws Exception { + String[] inputLines = { + "y", // start tool for merge resolution + "n", // don't accept merge tool result + "n", // don't continue resolution + }; + String[] conflictingFilenames = createMergeConflict(); + int abortIndex = 1; + String[] expectedOutput = getExpectedAbortMergeOutput( + conflictingFilenames, + abortIndex); + + String option = "--tool"; + + InputStream inputStream = createInputStream(inputLines); + assertArrayOfLinesEquals("Incorrect output for option: " + option, + expectedOutput, runAndCaptureUsingInitRaw(inputStream, + MERGE_TOOL, "--prompt", option, TOOL_NAME)); + } + + @Test + public void testAbortLaunch() throws Exception { + String[] inputLines = { + "n", // abort merge tool launch + }; + String[] conflictingFilenames = createMergeConflict(); + String[] expectedOutput = getExpectedAbortLaunchOutput( + conflictingFilenames); + + String option = "--tool"; + + InputStream inputStream = createInputStream(inputLines); + assertArrayOfLinesEquals("Incorrect output for option: " + option, + expectedOutput, runAndCaptureUsingInitRaw(inputStream, + MERGE_TOOL, "--prompt", option, TOOL_NAME)); + } + + @Test + public void testMergeConflict() throws Exception { + String[] inputLines = { + "y", // start tool for merge resolution + "y", // accept merge result as successful + "y", // start tool for merge resolution + "y", // accept merge result as successful + }; + String[] conflictingFilenames = createMergeConflict(); + String[] expectedOutput = getExpectedMergeConflictOutput( + conflictingFilenames); + + String option = "--tool"; + + InputStream inputStream = createInputStream(inputLines); + assertArrayOfLinesEquals("Incorrect output for option: " + option, + expectedOutput, runAndCaptureUsingInitRaw(inputStream, + MERGE_TOOL, "--prompt", option, TOOL_NAME)); + } + + @Test + public void testDeletedConflict() throws Exception { + String[] inputLines = { + "d", // choose delete option to resolve conflict + "m", // choose merge option to resolve conflict + }; + String[] conflictingFilenames = createDeletedConflict(); + String[] expectedOutput = getExpectedDeletedConflictOutput( + conflictingFilenames); + + String option = "--tool"; + + InputStream inputStream = createInputStream(inputLines); + assertArrayOfLinesEquals("Incorrect output for option: " + option, + expectedOutput, runAndCaptureUsingInitRaw(inputStream, + MERGE_TOOL, "--prompt", option, TOOL_NAME)); + } + + @Test + public void testNoConflict() throws Exception { + createStagedChanges(); + String[] expectedOutput = { "No files need merging" }; + + String[] options = { "--tool", "-t", }; + + for (String option : options) { + assertArrayOfLinesEquals("Incorrect output for option: " + option, + expectedOutput, + runAndCaptureUsingInitRaw(MERGE_TOOL, option, TOOL_NAME)); + } + } + + @Test + public void testMergeConflictNoPrompt() throws Exception { + String[] conflictingFilenames = createMergeConflict(); + String[] expectedOutput = getExpectedMergeConflictOutputNoPrompt( + conflictingFilenames); + + String option = "--tool"; + + assertArrayOfLinesEquals("Incorrect output for option: " + option, + expectedOutput, + runAndCaptureUsingInitRaw(MERGE_TOOL, option, TOOL_NAME)); + } + + @Test + public void testMergeConflictNoGuiNoPrompt() throws Exception { + String[] conflictingFilenames = createMergeConflict(); + String[] expectedOutput = getExpectedMergeConflictOutputNoPrompt( + conflictingFilenames); + + String option = "--tool"; + + assertArrayOfLinesEquals("Incorrect output for option: " + option, + expectedOutput, runAndCaptureUsingInitRaw(MERGE_TOOL, + "--no-gui", "--no-prompt", option, TOOL_NAME)); + } + + @Test + public void testToolHelp() throws Exception { + List<String> expectedOutput = new ArrayList<>(); + + MergeTools diffTools = new MergeTools(db); + Map<String, ExternalMergeTool> predefinedTools = diffTools + .getPredefinedTools(true); + List<ExternalMergeTool> availableTools = new ArrayList<>(); + List<ExternalMergeTool> notAvailableTools = new ArrayList<>(); + for (ExternalMergeTool tool : predefinedTools.values()) { + if (tool.isAvailable()) { + availableTools.add(tool); + } else { + notAvailableTools.add(tool); + } + } + + expectedOutput.add( + "'git mergetool --tool=<tool>' may be set to one of the following:"); + for (ExternalMergeTool tool : availableTools) { + String toolName = tool.getName(); + expectedOutput.add(toolName); + } + String customToolHelpLine = TOOL_NAME + "." + CONFIG_KEY_CMD + " " + + getEchoCommand(); + expectedOutput.add("user-defined:"); + expectedOutput.add(customToolHelpLine); + expectedOutput.add( + "The following tools are valid, but not currently available:"); + for (ExternalMergeTool tool : notAvailableTools) { + String toolName = tool.getName(); + expectedOutput.add(toolName); + } + String[] userDefinedToolsHelp = { + "Some of the tools listed above only work in a windowed", + "environment. If run in a terminal-only session, they will fail.", }; + expectedOutput.addAll(Arrays.asList(userDefinedToolsHelp)); + + String option = "--tool-help"; + assertArrayOfLinesEquals("Incorrect output for option: " + option, + expectedOutput.toArray(new String[0]), + runAndCaptureUsingInitRaw(MERGE_TOOL, option)); + } + + private void configureEchoTool(String toolName) { + StoredConfig config = db.getConfig(); + // the default merge tool is configured without a subsection + String subsection = null; + config.setString(CONFIG_MERGE_SECTION, subsection, CONFIG_KEY_TOOL, + toolName); + + String command = getEchoCommand(); + + config.setString(CONFIG_MERGETOOL_SECTION, toolName, CONFIG_KEY_CMD, + command); + /* + * prevent prompts as we are running in tests and there is no user to + * interact with on the command line + */ + config.setString(CONFIG_MERGETOOL_SECTION, toolName, CONFIG_KEY_PROMPT, + String.valueOf(false)); + } + + private String[] getExpectedMergeConflictOutputNoPrompt( + String[] conflictFilenames) { + List<String> expected = new ArrayList<>(); + expected.add("Merging:"); + for (String conflictFilename : conflictFilenames) { + expected.add(conflictFilename); + } + for (String conflictFilename : conflictFilenames) { + expected.add("Normal merge conflict for '" + conflictFilename + + "':"); + expected.add("{local}: modified file"); + expected.add("{remote}: modified file"); + Path filePath = getFullPath(conflictFilename); + expected.add(filePath.toString()); + expected.add(conflictFilename + " seems unchanged."); + } + return expected.toArray(new String[0]); + } + + private static String[] getExpectedAbortLaunchOutput( + String[] conflictFilenames) { + List<String> expected = new ArrayList<>(); + expected.add("Merging:"); + for (String conflictFilename : conflictFilenames) { + expected.add(conflictFilename); + } + if (conflictFilenames.length > 1) { + String conflictFilename = conflictFilenames[0]; + expected.add( + "Normal merge conflict for '" + conflictFilename + "':"); + expected.add("{local}: modified file"); + expected.add("{remote}: modified file"); + expected.add("Hit return to start merge resolution tool (" + + TOOL_NAME + "):"); + } + return expected.toArray(new String[0]); + } + + private String[] getExpectedAbortMergeOutput( + String[] conflictFilenames, int abortIndex) { + List<String> expected = new ArrayList<>(); + expected.add("Merging:"); + for (String conflictFilename : conflictFilenames) { + expected.add(conflictFilename); + } + for (int i = 0; i < conflictFilenames.length; ++i) { + if (i == abortIndex) { + break; + } + + String conflictFilename = conflictFilenames[i]; + expected.add( + "Normal merge conflict for '" + conflictFilename + "':"); + expected.add("{local}: modified file"); + expected.add("{remote}: modified file"); + Path fullPath = getFullPath(conflictFilename); + expected.add("Hit return to start merge resolution tool (" + + TOOL_NAME + "): " + fullPath); + expected.add(conflictFilename + " seems unchanged."); + expected.add("Was the merge successful [y/n]?"); + if (i < conflictFilenames.length - 1) { + expected.add( + "\tContinue merging other unresolved paths [y/n]?"); + } + } + return expected.toArray(new String[0]); + } + + private String[] getExpectedMergeConflictOutput( + String[] conflictFilenames) { + List<String> expected = new ArrayList<>(); + expected.add("Merging:"); + for (String conflictFilename : conflictFilenames) { + expected.add(conflictFilename); + } + for (int i = 0; i < conflictFilenames.length; ++i) { + String conflictFilename = conflictFilenames[i]; + expected.add("Normal merge conflict for '" + conflictFilename + + "':"); + expected.add("{local}: modified file"); + expected.add("{remote}: modified file"); + Path filePath = getFullPath(conflictFilename); + expected.add("Hit return to start merge resolution tool (" + + TOOL_NAME + "): " + filePath); + expected.add(conflictFilename + " seems unchanged."); + expected.add("Was the merge successful [y/n]?"); + if (i < conflictFilenames.length - 1) { + // expected.add( + // "\tContinue merging other unresolved paths [y/n]?"); + } + } + return expected.toArray(new String[0]); + } + + private static String[] getExpectedDeletedConflictOutput( + String[] conflictFilenames) { + List<String> expected = new ArrayList<>(); + expected.add("Merging:"); + for (String mergeConflictFilename : conflictFilenames) { + expected.add(mergeConflictFilename); + } + for (int i = 0; i < conflictFilenames.length; ++i) { + String conflictFilename = conflictFilenames[i]; + expected.add(conflictFilename + " seems unchanged."); + expected.add("{local}: deleted"); + expected.add("{remote}: modified file"); + expected.add("Use (m)odified or (d)eleted file, or (a)bort?"); + } + return expected.toArray(new String[0]); + } + + private static String getEchoCommand() { + /* + * use 'MERGED' placeholder, as both 'LOCAL' and 'REMOTE' will be + * replaced with full paths to a temporary file during some of the tests + */ + return "(echo \"$MERGED\")"; + } +} diff --git a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ToolTestCase.java b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ToolTestCase.java new file mode 100644 index 0000000000..5f6b38c25d --- /dev/null +++ b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ToolTestCase.java @@ -0,0 +1,250 @@ +/* + * Copyright (C) 2022, Simeon Andreev <simeon.danailov.andreev@gmail.com> and others. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Distribution License v. 1.0 which is available at + * https://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: BSD-3-Clause + */ +package org.eclipse.jgit.pgm; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.stream.Collectors; + +import org.eclipse.jgit.api.Git; +import org.eclipse.jgit.diff.DiffEntry; +import org.eclipse.jgit.lib.CLIRepositoryTestCase; +import org.eclipse.jgit.pgm.opt.CmdLineParser; +import org.eclipse.jgit.pgm.opt.SubcommandHandler; +import org.eclipse.jgit.revwalk.RevCommit; +import org.eclipse.jgit.treewalk.FileTreeIterator; +import org.eclipse.jgit.treewalk.TreeWalk; +import org.eclipse.jgit.util.SystemReader; +import org.junit.Assume; +import org.junit.Before; +import org.kohsuke.args4j.Argument; +import org.kohsuke.args4j.CmdLineException; + +/** + * Base test case for the {@code difftool} and {@code mergetool} commands. + */ +public abstract class ToolTestCase extends CLIRepositoryTestCase { + + public static class GitCliJGitWrapperParser { + @Argument(index = 0, metaVar = "metaVar_command", required = true, handler = SubcommandHandler.class) + TextBuiltin subcommand; + + @Argument(index = 1, metaVar = "metaVar_arg") + List<String> arguments = new ArrayList<>(); + } + + protected static final String TOOL_NAME = "some_tool"; + + private static final String TEST_BRANCH_NAME = "test_branch"; + + private Git git; + + @Override + @Before + public void setUp() throws Exception { + super.setUp(); + git = new Git(db); + git.commit().setMessage("initial commit").call(); + git.branchCreate().setName(TEST_BRANCH_NAME).call(); + } + + protected String[] runAndCaptureUsingInitRaw(String... args) + throws Exception { + InputStream inputStream = null; // no input stream + return runAndCaptureUsingInitRaw(inputStream, args); + } + + protected String[] runAndCaptureUsingInitRaw( + List<String> expectedErrorOutput, String... args) throws Exception { + InputStream inputStream = null; // no input stream + return runAndCaptureUsingInitRaw(inputStream, expectedErrorOutput, + args); + } + + protected String[] runAndCaptureUsingInitRaw(InputStream inputStream, + String... args) throws Exception { + List<String> expectedErrorOutput = Collections.emptyList(); + return runAndCaptureUsingInitRaw(inputStream, expectedErrorOutput, + args); + } + + protected String[] runAndCaptureUsingInitRaw(InputStream inputStream, + List<String> expectedErrorOutput, String... args) + throws CmdLineException, Exception, IOException { + CLIGitCommand.Result result = new CLIGitCommand.Result(); + + GitCliJGitWrapperParser bean = new GitCliJGitWrapperParser(); + CmdLineParser clp = new CmdLineParser(bean); + clp.parseArgument(args); + + TextBuiltin cmd = bean.subcommand; + cmd.initRaw(db, null, inputStream, result.out, result.err); + cmd.execute(bean.arguments.toArray(new String[bean.arguments.size()])); + if (cmd.getOutputWriter() != null) { + cmd.getOutputWriter().flush(); + } + if (cmd.getErrorWriter() != null) { + cmd.getErrorWriter().flush(); + } + + List<String> errLines = result.errLines().stream() + .filter(l -> !l.isBlank()) // we care only about error messages + .collect(Collectors.toList()); + assertEquals("Expected no standard error output from tool", + expectedErrorOutput.toString(), errLines.toString()); + + return result.outLines().toArray(new String[0]); + } + + protected String[] createMergeConflict() throws Exception { + // create files on initial branch + git.checkout().setName(TEST_BRANCH_NAME).call(); + writeTrashFile("dir1/a", "Hello world a"); + writeTrashFile("dir2/b", "Hello world b"); + git.add().addFilepattern(".").call(); + git.commit().setMessage("files a & b added").call(); + // create another branch and change files + git.branchCreate().setName("branch_1").call(); + git.checkout().setName("branch_1").call(); + writeTrashFile("dir1/a", "Hello world a 1"); + writeTrashFile("dir2/b", "Hello world b 1"); + git.add().addFilepattern(".").call(); + RevCommit commit1 = git.commit() + .setMessage("files a & b modified commit 1").call(); + // checkout initial branch + git.checkout().setName(TEST_BRANCH_NAME).call(); + // create another branch and change files + git.branchCreate().setName("branch_2").call(); + git.checkout().setName("branch_2").call(); + writeTrashFile("dir1/a", "Hello world a 2"); + writeTrashFile("dir2/b", "Hello world b 2"); + git.add().addFilepattern(".").call(); + git.commit().setMessage("files a & b modified commit 2").call(); + // cherry-pick conflicting changes + git.cherryPick().include(commit1).call(); + String[] conflictingFilenames = { "dir1/a", "dir2/b" }; + return conflictingFilenames; + } + + protected String[] createDeletedConflict() throws Exception { + // create files on initial branch + git.checkout().setName(TEST_BRANCH_NAME).call(); + writeTrashFile("dir1/a", "Hello world a"); + writeTrashFile("dir2/b", "Hello world b"); + git.add().addFilepattern(".").call(); + git.commit().setMessage("files a & b added").call(); + // create another branch and change files + git.branchCreate().setName("branch_1").call(); + git.checkout().setName("branch_1").call(); + writeTrashFile("dir1/a", "Hello world a 1"); + writeTrashFile("dir2/b", "Hello world b 1"); + git.add().addFilepattern(".").call(); + RevCommit commit1 = git.commit() + .setMessage("files a & b modified commit 1").call(); + // checkout initial branch + git.checkout().setName(TEST_BRANCH_NAME).call(); + // create another branch and change files + git.branchCreate().setName("branch_2").call(); + git.checkout().setName("branch_2").call(); + git.rm().addFilepattern("dir1/a").call(); + git.rm().addFilepattern("dir2/b").call(); + git.commit().setMessage("files a & b deleted commit 2").call(); + // cherry-pick conflicting changes + git.cherryPick().include(commit1).call(); + String[] conflictingFilenames = { "dir1/a", "dir2/b" }; + return conflictingFilenames; + } + + protected String[] createUnstagedChanges() throws Exception { + writeTrashFile("dir1/a", "Hello world a"); + writeTrashFile("dir2/b", "Hello world b"); + git.add().addFilepattern(".").call(); + git.commit().setMessage("files a & b").call(); + writeTrashFile("dir1/a", "New Hello world a"); + writeTrashFile("dir2/b", "New Hello world b"); + String[] conflictingFilenames = { "dir1/a", "dir2/b" }; + return conflictingFilenames; + } + + protected String[] createStagedChanges() throws Exception { + String[] conflictingFilenames = createUnstagedChanges(); + git.add().addFilepattern(".").call(); + return conflictingFilenames; + } + + protected List<DiffEntry> getRepositoryChanges(RevCommit commit) + throws Exception { + TreeWalk tw = new TreeWalk(db); + tw.addTree(commit.getTree()); + FileTreeIterator modifiedTree = new FileTreeIterator(db); + tw.addTree(modifiedTree); + List<DiffEntry> changes = DiffEntry.scan(tw); + return changes; + } + + protected Path getFullPath(String repositoryFilename) { + Path dotGitPath = db.getDirectory().toPath(); + Path repositoryRoot = dotGitPath.getParent(); + Path repositoryFilePath = repositoryRoot.resolve(repositoryFilename); + return repositoryFilePath; + } + + protected static InputStream createInputStream(String[] inputLines) { + return createInputStream(Arrays.asList(inputLines)); + } + + protected static InputStream createInputStream(List<String> inputLines) { + String input = String.join(System.lineSeparator(), inputLines); + InputStream inputStream = new ByteArrayInputStream(input.getBytes()); + return inputStream; + } + + protected static void assertArrayOfLinesEquals(String failMessage, + String[] expected, String[] actual) { + assertEquals(failMessage, toString(expected), toString(actual)); + } + + protected static void assertArrayOfMatchingLines(String failMessage, + Pattern[] expected, String[] actual) { + assertEquals(failMessage + System.lineSeparator() + + "Expected and actual lines count don't match. Expected: " + + Arrays.asList(expected) + ", actual: " + + Arrays.asList(actual), expected.length, actual.length); + int n = expected.length; + for (int i = 0; i < n; ++i) { + Pattern expectedPattern = expected[i]; + String actualLine = actual[i]; + Matcher matcher = expectedPattern.matcher(actualLine); + boolean matches = matcher.matches(); + assertTrue(failMessage + System.lineSeparator() + "Line " + i + " '" + + actualLine + "' doesn't match expected pattern: " + + expectedPattern + System.lineSeparator() + "Expected: " + + Arrays.asList(expected) + ", actual: " + + Arrays.asList(actual), + matches); + } + } + + protected static void assumeLinuxPlatform() { + Assume.assumeTrue("This test can run only in Linux tests", + SystemReader.getInstance().isLinux()); + } +} diff --git a/org.eclipse.jgit.pgm/META-INF/services/org.eclipse.jgit.pgm.TextBuiltin b/org.eclipse.jgit.pgm/META-INF/services/org.eclipse.jgit.pgm.TextBuiltin index 8c44764c63..ea1d1e3faa 100644 --- a/org.eclipse.jgit.pgm/META-INF/services/org.eclipse.jgit.pgm.TextBuiltin +++ b/org.eclipse.jgit.pgm/META-INF/services/org.eclipse.jgit.pgm.TextBuiltin @@ -25,6 +25,7 @@ org.eclipse.jgit.pgm.LsRemote org.eclipse.jgit.pgm.LsTree org.eclipse.jgit.pgm.Merge org.eclipse.jgit.pgm.MergeBase +org.eclipse.jgit.pgm.MergeTool org.eclipse.jgit.pgm.Push org.eclipse.jgit.pgm.ReceivePack org.eclipse.jgit.pgm.Reflog diff --git a/org.eclipse.jgit.pgm/build.properties b/org.eclipse.jgit.pgm/build.properties index 4b38114d09..302dded85a 100644 --- a/org.eclipse.jgit.pgm/build.properties +++ b/org.eclipse.jgit.pgm/build.properties @@ -6,4 +6,4 @@ bin.includes = META-INF/,\ .,\ plugin.properties,\ about.html,\ - resources/log4j.properties + resources/simplelogger.properties diff --git a/org.eclipse.jgit.pgm/pom.xml b/org.eclipse.jgit.pgm/pom.xml index 5cac06f3d6..e541e1a9ba 100644 --- a/org.eclipse.jgit.pgm/pom.xml +++ b/org.eclipse.jgit.pgm/pom.xml @@ -103,12 +103,7 @@ <dependency> <groupId>org.slf4j</groupId> - <artifactId>slf4j-log4j12</artifactId> - </dependency> - - <dependency> - <groupId>log4j</groupId> - <artifactId>log4j</artifactId> + <artifactId>slf4j-simple</artifactId> </dependency> <dependency> diff --git a/org.eclipse.jgit.pgm/resources/log4j.properties b/org.eclipse.jgit.pgm/resources/log4j.properties deleted file mode 100644 index 1496c5a2cf..0000000000 --- a/org.eclipse.jgit.pgm/resources/log4j.properties +++ /dev/null @@ -1,6 +0,0 @@ -log4j.rootLogger=WARN, stderr - -log4j.appender.stderr=org.apache.log4j.ConsoleAppender -log4j.appender.stderr.Target=System.err -log4j.appender.stderr.layout=org.apache.log4j.PatternLayout -log4j.appender.stderr.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
\ No newline at end of file diff --git a/org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/internal/CLIText.properties b/org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/internal/CLIText.properties index d51daafde3..b14531a1bd 100644 --- a/org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/internal/CLIText.properties +++ b/org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/internal/CLIText.properties @@ -58,9 +58,11 @@ couldNotCreateBranch=Could not create branch {0}: {1} dateInfo=Date: {0} deletedBranch=Deleted branch {0} deletedRemoteBranch=Deleted remote branch {0} -diffToolHelpSetToFollowing='git difftool --tool=<tool>' may be set to one of the following:\n{0}\n\tuser-defined:\n{1}\nThe following tools are valid, but not currently available:\n{2}\nSome of the tools listed above only work in a windowed\nenvironment. If run in a terminal-only session, they will fail. -diffToolLaunch=Viewing ({0}/{1}): '{2}'\nLaunch '{3}' [Y/n]? -diffToolDied=external diff died, stopping at {0} +diffToolHelpSetToFollowing=''git difftool --tool=<tool>'' may be set to one of the following:\n{0}\n\tuser-defined:\n{1}\nThe following tools are valid, but not currently available:\n{2}\nSome of the tools listed above only work in a windowed\nenvironment. If run in a terminal-only session, they will fail. +diffToolLaunch=Viewing ({0}/{1}): ''{2}''\nLaunch ''{3}'' [Y/n]? +diffToolDied=external diff died, stopping at path ''{0}'' due to exception: {1} +diffToolPromptToolName=This message is displayed because 'diff.tool' is not configured.\nSee 'git difftool --tool-help' or 'git help config' for more details.\n'git difftool' will now attempt to use one of the following tools:\n{0}\n +diffToolUnknownToolName=Unknown diff tool '{0}' doesNotExist={0} does not exist dontOverwriteLocalChanges=error: Your local changes to the following file would be overwritten by merge: everythingUpToDate=Everything up-to-date @@ -91,6 +93,24 @@ listeningOn=Listening on {0} logNoSignatureVerifier="No signature verifier available" mergeConflict=CONFLICT(content): Merge conflict in {0} mergeCheckoutConflict=error: Your local changes to the following files would be overwritten by merge: +mergeToolHelpSetToFollowing=''git mergetool --tool=<tool>'' may be set to one of the following:\n{0}\n\tuser-defined:\n{1}\nThe following tools are valid, but not currently available:\n{2}\nSome of the tools listed above only work in a windowed\nenvironment. If run in a terminal-only session, they will fail. +mergeToolLaunch=Hit return to start merge resolution tool ({0}): +mergeToolDied=local or remote cannot be found in cache, stopping at {0} +mergeToolNoFiles=No files need merging +mergeToolMerging=Merging:\n{0} +mergeToolUnknownConflict=\nUnknown merge conflict for ''{0}'': +mergeToolNormalConflict=\nNormal merge conflict for ''{0}'':\n '{'local'}': modified file\n '{'remote'}': modified file +mergeToolMergeFailed=merge of {0} failed +mergeToolExecutionError=excution error +mergeToolFileUnchanged=\n{0} seems unchanged. +mergeToolDeletedConflict=\nDeleted merge conflict for ''{0}'': +mergeToolDeletedConflictByUs= {local}: deleted\n {remote}: modified file +mergeToolDeletedConflictByThem= {local}: modified file\n {remote}: deleted +mergeToolContinueUnresolvedPaths=\nContinue merging other unresolved paths [y/n]? +mergeToolWasMergeSuccessfull=Was the merge successful [y/n]? +mergeToolDeletedMergeDecision=Use (m)odified or (d)eleted file, or (a)bort? +mergeToolPromptToolName=This message is displayed because 'merge.tool' is not configured.\nSee 'git mergetool --tool-help' or 'git help config' for more details.\n'git mergetool' will now attempt to use one of the following tools:\n{0}\n +mergeToolUnknownToolName=Unknown merge tool '{0}' mergeFailed=Automatic merge failed; fix conflicts and then commit the result mergeCheckoutFailed=Please, commit your changes or stash them before you can merge. mergeMadeBy=Merge made by the ''{0}'' strategy. @@ -229,6 +249,7 @@ unmergedPaths=Unmerged paths: unsupportedOperation=Unsupported operation: {0} untrackedFiles=Untracked files: updating=Updating {0}..{1} +usage_Abbrev=Instead of using the default number of hexadecimal digits (which will vary according to the number of objects in the repository with a default of 7) of the abbreviated object name, use <n> digits, or as many digits as needed to form a unique object name. An <n> of 0 will suppress long format, only showing the closest tag. usage_Aggressive=This option will cause gc to more aggressively optimize the repository at the expense of taking much more time usage_AlwaysFallback=Show uniquely abbreviated commit object as fallback usage_bareClone=Make a bare Git repository. That is, instead of creating [DIRECTORY] and placing the administrative files in [DIRECTORY]/.git, make the [DIRECTORY] itself the $GIT_DIR. @@ -254,6 +275,7 @@ usage_DisplayTheVersionOfJgit=Display the version of jgit usage_Gc=Cleanup unnecessary files and optimize the local repository usage_Glog=View commit history as a graph usage_DiffGuiTool=When git-difftool is invoked with the -g or --gui option the default diff tool will be read from the configured diff.guitool variable instead of diff.tool. +usage_MergeGuiTool=When git-mergetool is invoked with the -g or --gui option the default merge tool will be read from the configured merge.guitool variable instead of merge.tool. usage_noGui=The --no-gui option can be used to override -g or --gui setting. usage_IndexPack=Build pack index file for an existing packed archive usage_LFSDirectory=Directory to store large objects @@ -302,6 +324,7 @@ usage_Status=Show the working tree status usage_StopTrackingAFile=Stop tracking a file usage_TextHashFunctions=Scan repository to compute maximum number of collisions for hash functions usage_ToolForDiff=Use the diff tool specified by <tool>. Run git difftool --tool-help for the list of valid <tool> settings.\nIf a diff tool is not specified, git difftool will use the configuration variable diff.tool. +usage_ToolForMerge=Use the merge resolution program specified by <tool>. Run git mergetool --tool-help for the list of valid <tool> settings.\nIf a merge resolution program is not specified, git mergetool will use the configuration variable merge.tool. usage_UpdateRemoteRepositoryFromLocalRefs=Update remote repository from local refs usage_UseAll=Use all refs found in refs/ usage_UseTags=Use any tag including lightweight tags @@ -349,6 +372,7 @@ usage_date=date format, one of default, rfc, local, iso, short, raw (as defined usage_detectRenames=detect renamed files usage_diffAlgorithm=the diff algorithm to use. Currently supported are: 'myers', 'histogram' usage_DiffTool=git difftool is a Git command that allows you to compare and edit files between revisions using common diff tools.\ngit difftool is a frontend to git diff and accepts the same options and arguments. +usage_MergeTool=git-mergetool - Run merge conflict resolution tools to resolve merge conflicts.\nUse git mergetool to run one of several merge utilities to resolve merge conflicts. It is typically run after git merge. usage_directoriesToExport=directories to export usage_disableTheServiceInAllRepositories=disable the service in all repositories usage_displayAListOfAllRegisteredJgitCommands=Display a list of all registered jgit commands diff --git a/org.eclipse.jgit.pgm/resources/simplelogger.properties b/org.eclipse.jgit.pgm/resources/simplelogger.properties new file mode 100644 index 0000000000..98c19ce01d --- /dev/null +++ b/org.eclipse.jgit.pgm/resources/simplelogger.properties @@ -0,0 +1,6 @@ +org.slf4j.simpleLogger.defaultLogLevel=warn +org.slf4j.simpleLogger.logFile=System.err +org.slf4j.simpleLogger.showDateTime=true +org.slf4j.simpleLogger.dateTimeFormat=yyyy-MM-dd HH:mm:ss +org.slf4j.simpleLogger.showThreadName=true +org.slf4j.simpleLogger.showLogName=true diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Blame.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Blame.java index 2b49cf73d4..1a3a2f6f4b 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Blame.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Blame.java @@ -15,6 +15,7 @@ package org.eclipse.jgit.pgm; import static java.lang.Integer.valueOf; import static java.lang.Long.valueOf; +import static org.eclipse.jgit.lib.Constants.OBJECT_ID_ABBREV_STRING_LENGTH; import static org.eclipse.jgit.lib.Constants.OBJECT_ID_STRING_LENGTH; import java.io.IOException; @@ -116,7 +117,8 @@ class Blame extends TextBuiltin { boolean autoAbbrev = abbrev == 0; if (abbrev == 0) { - abbrev = db.getConfig().getInt("core", "abbrev", 7); //$NON-NLS-1$ //$NON-NLS-2$ + abbrev = db.getConfig().getInt("core", "abbrev", //$NON-NLS-1$ //$NON-NLS-2$ + OBJECT_ID_ABBREV_STRING_LENGTH); } if (!showBlankBoundary) { root = db.getConfig().getBoolean("blame", "blankboundary", false); //$NON-NLS-1$ //$NON-NLS-2$ diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Describe.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Describe.java index 8aa119a358..116db037d4 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Describe.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Describe.java @@ -44,6 +44,9 @@ class Describe extends TextBuiltin { @Option(name = "--match", usage = "usage_Match", metaVar = "metaVar_pattern") private List<String> patterns = new ArrayList<>(); + @Option(name = "--abbrev", usage = "usage_Abbrev") + private Integer abbrev; + /** {@inheritDoc} */ @Override protected void run() { @@ -57,6 +60,9 @@ class Describe extends TextBuiltin { cmd.setTags(useTags); cmd.setAlways(always); cmd.setMatch(patterns.toArray(new String[0])); + if (abbrev != null) { + cmd.setAbbrev(abbrev.intValue()); + } String result = null; try { result = cmd.call(); diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/DiffTool.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/DiffTool.java index d26842c641..87c71795ec 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/DiffTool.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/DiffTool.java @@ -1,5 +1,6 @@ /* - * Copyright (C) 2018-2021, Andre Bossert <andre.bossert@siemens.com> + * Copyright (C) 2018-2022, Andre Bossert <andre.bossert@siemens.com> + * Copyright (C) 2019, Tim Neumann <tim.neumann@advantest.com> * * This program and the accompanying materials are made available under the * terms of the Eclipse Distribution License v. 1.0 which is available at @@ -11,24 +12,40 @@ package org.eclipse.jgit.pgm; import static org.eclipse.jgit.lib.Constants.HEAD; +import static org.eclipse.jgit.treewalk.TreeWalk.OperationType.CHECKOUT_OP; import java.io.BufferedOutputStream; import java.io.BufferedReader; +import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; +import java.nio.charset.Charset; import java.text.MessageFormat; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.concurrent.TimeUnit; +import org.eclipse.jgit.diff.ContentSource; +import org.eclipse.jgit.diff.ContentSource.Pair; import org.eclipse.jgit.diff.DiffEntry; +import org.eclipse.jgit.diff.DiffEntry.Side; import org.eclipse.jgit.diff.DiffFormatter; +import org.eclipse.jgit.dircache.DirCacheCheckout; +import org.eclipse.jgit.dircache.DirCacheCheckout.CheckoutMetadata; import org.eclipse.jgit.dircache.DirCacheIterator; import org.eclipse.jgit.errors.AmbiguousObjectException; +import org.eclipse.jgit.errors.CorruptObjectException; import org.eclipse.jgit.errors.IncorrectObjectTypeException; +import org.eclipse.jgit.errors.NoWorkTreeException; import org.eclipse.jgit.errors.RevisionSyntaxException; import org.eclipse.jgit.internal.diffmergetool.DiffTools; import org.eclipse.jgit.internal.diffmergetool.ExternalDiffTool; +import org.eclipse.jgit.internal.diffmergetool.FileElement; +import org.eclipse.jgit.internal.diffmergetool.PromptContinueHandler; +import org.eclipse.jgit.internal.diffmergetool.ToolException; +import org.eclipse.jgit.lib.Constants; +import org.eclipse.jgit.lib.CoreConfig.EolStreamType; import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectReader; import org.eclipse.jgit.lib.Repository; @@ -36,11 +53,17 @@ import org.eclipse.jgit.lib.TextProgressMonitor; import org.eclipse.jgit.lib.internal.BooleanTriState; import org.eclipse.jgit.pgm.internal.CLIText; import org.eclipse.jgit.pgm.opt.PathTreeFilterHandler; +import org.eclipse.jgit.revwalk.RevWalk; import org.eclipse.jgit.treewalk.AbstractTreeIterator; import org.eclipse.jgit.treewalk.CanonicalTreeParser; import org.eclipse.jgit.treewalk.FileTreeIterator; +import org.eclipse.jgit.treewalk.TreeWalk; +import org.eclipse.jgit.treewalk.WorkingTreeIterator; +import org.eclipse.jgit.treewalk.WorkingTreeOptions; +import org.eclipse.jgit.treewalk.filter.PathFilterGroup; import org.eclipse.jgit.treewalk.filter.TreeFilter; -import org.eclipse.jgit.util.StringUtils; +import org.eclipse.jgit.util.FS.ExecutionResult; +import org.eclipse.jgit.util.SystemReader; import org.kohsuke.args4j.Argument; import org.kohsuke.args4j.Option; @@ -56,9 +79,13 @@ class DiffTool extends TextBuiltin { @Argument(index = 1, metaVar = "metaVar_treeish") private AbstractTreeIterator newTree; + private Optional<String> toolName = Optional.empty(); + @Option(name = "--tool", aliases = { "-t" }, metaVar = "metaVar_tool", usage = "usage_ToolForDiff") - private String toolName; + void setToolName(String name) { + toolName = Optional.of(name); + } @Option(name = "--cached", aliases = { "--staged" }, usage = "usage_cached") private boolean cached; @@ -78,16 +105,16 @@ class DiffTool extends TextBuiltin { @Option(name = "--tool-help", usage = "usage_toolHelp") private boolean toolHelp; - private BooleanTriState gui = BooleanTriState.UNSET; + private boolean gui = false; @Option(name = "--gui", aliases = { "-g" }, usage = "usage_DiffGuiTool") void setGui(@SuppressWarnings("unused") boolean on) { - gui = BooleanTriState.TRUE; + gui = true; } @Option(name = "--no-gui", usage = "usage_noGui") void noGui(@SuppressWarnings("unused") boolean on) { - gui = BooleanTriState.FALSE; + gui = false; } private BooleanTriState trustExitCode = BooleanTriState.UNSET; @@ -105,11 +132,15 @@ class DiffTool extends TextBuiltin { @Option(name = "--", metaVar = "metaVar_paths", handler = PathTreeFilterHandler.class) private TreeFilter pathFilter = TreeFilter.ALL; + private BufferedReader inputReader; + @Override protected void init(Repository repository, String gitDir) { super.init(repository, gitDir); diffFmt = new DiffFormatter(new BufferedOutputStream(outs)); diffTools = new DiffTools(repository); + inputReader = new BufferedReader(new InputStreamReader(ins, + SystemReader.getInstance().getDefaultCharset())); } @Override @@ -118,23 +149,12 @@ class DiffTool extends TextBuiltin { if (toolHelp) { showToolHelp(); } else { - boolean showPrompt = diffTools.isInteractive(); - if (prompt != BooleanTriState.UNSET) { - showPrompt = prompt == BooleanTriState.TRUE; - } - String toolNamePrompt = toolName; - if (showPrompt) { - if (StringUtils.isEmptyOrNull(toolNamePrompt)) { - toolNamePrompt = diffTools.getDefaultToolName(gui); - } - } // get the changed files List<DiffEntry> files = getFiles(); if (files.size() > 0) { - compare(files, showPrompt, toolNamePrompt); + compare(files); } } - outw.flush(); } catch (RevisionSyntaxException | IOException e) { throw die(e.getMessage(), e); } finally { @@ -142,76 +162,131 @@ class DiffTool extends TextBuiltin { } } - private void compare(List<DiffEntry> files, boolean showPrompt, - String toolNamePrompt) throws IOException { - for (int fileIndex = 0; fileIndex < files.size(); fileIndex++) { - DiffEntry ent = files.get(fileIndex); - String mergedFilePath = ent.getNewPath(); - if (mergedFilePath.equals(DiffEntry.DEV_NULL)) { - mergedFilePath = ent.getOldPath(); - } - // check if user wants to launch compare - boolean launchCompare = true; - if (showPrompt) { - launchCompare = isLaunchCompare(fileIndex + 1, files.size(), - mergedFilePath, toolNamePrompt); + private void informUserNoTool(List<String> tools) { + try { + StringBuilder toolNames = new StringBuilder(); + for (String name : tools) { + toolNames.append(name + " "); //$NON-NLS-1$ } - if (launchCompare) { - switch (ent.getChangeType()) { - case MODIFY: - outw.println("M\t" + ent.getNewPath() //$NON-NLS-1$ - + " (" + ent.getNewId().name() + ")" //$NON-NLS-1$ //$NON-NLS-2$ - + "\t" + ent.getOldPath() //$NON-NLS-1$ - + " (" + ent.getOldId().name() + ")"); //$NON-NLS-1$ //$NON-NLS-2$ - int ret = diffTools.compare(ent.getNewPath(), - ent.getOldPath(), ent.getNewId().name(), - ent.getOldId().name(), toolName, prompt, gui, - trustExitCode); - if (ret != 0) { - throw die(MessageFormat.format( - CLIText.get().diffToolDied, mergedFilePath)); + outw.println(MessageFormat.format( + CLIText.get().diffToolPromptToolName, toolNames)); + outw.flush(); + } catch (IOException e) { + throw new IllegalStateException("Cannot output text", e); //$NON-NLS-1$ + } + } + + private class CountingPromptContinueHandler + implements PromptContinueHandler { + private final int fileIndex; + + private final int fileCount; + + private final String fileName; + + public CountingPromptContinueHandler(int fileIndex, int fileCount, + String fileName) { + this.fileIndex = fileIndex; + this.fileCount = fileCount; + this.fileName = fileName; + } + + @SuppressWarnings("boxing") + @Override + public boolean prompt(String toolToLaunchName) { + try { + boolean launchCompare = true; + outw.println(MessageFormat.format(CLIText.get().diffToolLaunch, + fileIndex, fileCount, fileName, toolToLaunchName) + + " "); //$NON-NLS-1$ + outw.flush(); + BufferedReader br = inputReader; + String line = null; + if ((line = br.readLine()) != null) { + if (!line.equalsIgnoreCase("Y")) { //$NON-NLS-1$ + launchCompare = false; } - break; - default: - break; } - } else { - break; + return launchCompare; + } catch (IOException e) { + throw new IllegalStateException("Cannot output text", e); //$NON-NLS-1$ } } } - @SuppressWarnings("boxing") - private boolean isLaunchCompare(int fileIndex, int fileCount, - String fileName, String toolNamePrompt) throws IOException { - boolean launchCompare = true; - outw.println(MessageFormat.format(CLIText.get().diffToolLaunch, - fileIndex, fileCount, fileName, toolNamePrompt)); - outw.flush(); - BufferedReader br = new BufferedReader(new InputStreamReader(ins)); - String line = null; - if ((line = br.readLine()) != null) { - if (!line.equalsIgnoreCase("Y")) { //$NON-NLS-1$ - launchCompare = false; + private void compare(List<DiffEntry> files) throws IOException { + ContentSource.Pair sourcePair = new ContentSource.Pair(source(oldTree), + source(newTree)); + try { + for (int fileIndex = 0; fileIndex < files.size(); fileIndex++) { + DiffEntry ent = files.get(fileIndex); + + String filePath = ent.getNewPath(); + if (filePath.equals(DiffEntry.DEV_NULL)) { + filePath = ent.getOldPath(); + } + + try { + FileElement local = createFileElement( + FileElement.Type.LOCAL, sourcePair, Side.OLD, ent); + FileElement remote = createFileElement( + FileElement.Type.REMOTE, sourcePair, Side.NEW, ent); + + PromptContinueHandler promptContinueHandler = new CountingPromptContinueHandler( + fileIndex + 1, files.size(), filePath); + + Optional<ExecutionResult> optionalResult = diffTools + .compare(local, remote, toolName, prompt, gui, + trustExitCode, promptContinueHandler, + this::informUserNoTool); + + if (optionalResult.isPresent()) { + ExecutionResult result = optionalResult.get(); + // TODO: check how to return the exit-code of the tool + // to jgit / java runtime ? + // int rc =... + Charset defaultCharset = SystemReader.getInstance() + .getDefaultCharset(); + outw.println( + new String(result.getStdout().toByteArray(), + defaultCharset)); + outw.flush(); + errw.println( + new String(result.getStderr().toByteArray(), + defaultCharset)); + errw.flush(); + } + } catch (ToolException e) { + outw.println(e.getResultStdout()); + outw.flush(); + errw.println(e.getMessage()); + errw.flush(); + throw die(MessageFormat.format( + CLIText.get().diffToolDied, filePath, e), e); + } } + } finally { + sourcePair.close(); } - return launchCompare; } private void showToolHelp() throws IOException { + Map<String, ExternalDiffTool> predefTools = diffTools + .getPredefinedTools(true); StringBuilder availableToolNames = new StringBuilder(); - for (String name : diffTools.getAvailableTools().keySet()) { - availableToolNames.append(String.format("\t\t%s\n", name)); //$NON-NLS-1$ - } StringBuilder notAvailableToolNames = new StringBuilder(); - for (String name : diffTools.getNotAvailableTools().keySet()) { - notAvailableToolNames.append(String.format("\t\t%s\n", name)); //$NON-NLS-1$ + for (String name : predefTools.keySet()) { + if (predefTools.get(name).isAvailable()) { + availableToolNames.append(MessageFormat.format("\t\t{0}\n", name)); //$NON-NLS-1$ + } else { + notAvailableToolNames.append(MessageFormat.format("\t\t{0}\n", name)); //$NON-NLS-1$ + } } StringBuilder userToolNames = new StringBuilder(); Map<String, ExternalDiffTool> userTools = diffTools .getUserDefinedTools(); for (String name : userTools.keySet()) { - userToolNames.append(String.format("\t\t%s.cmd %s\n", //$NON-NLS-1$ + userToolNames.append(MessageFormat.format("\t\t{0}.cmd {1}\n", //$NON-NLS-1$ name, userTools.get(name).getCommand())); } outw.println(MessageFormat.format( @@ -252,4 +327,54 @@ class DiffTool extends TextBuiltin { return files; } + private FileElement createFileElement(FileElement.Type elementType, + Pair pair, Side side, DiffEntry entry) throws NoWorkTreeException, + CorruptObjectException, IOException, ToolException { + String entryPath = side == Side.NEW ? entry.getNewPath() + : entry.getOldPath(); + FileElement fileElement = new FileElement(entryPath, elementType, + db.getWorkTree()); + if (!pair.isWorkingTreeSource(side) && !fileElement.isNullPath()) { + try (RevWalk revWalk = new RevWalk(db); + TreeWalk treeWalk = new TreeWalk(db, + revWalk.getObjectReader())) { + treeWalk.setFilter( + PathFilterGroup.createFromStrings(entryPath)); + if (side == Side.NEW) { + newTree.reset(); + treeWalk.addTree(newTree); + } else { + oldTree.reset(); + treeWalk.addTree(oldTree); + } + if (treeWalk.next()) { + final EolStreamType eolStreamType = treeWalk + .getEolStreamType(CHECKOUT_OP); + final String filterCommand = treeWalk.getFilterCommand( + Constants.ATTR_FILTER_TYPE_SMUDGE); + WorkingTreeOptions opt = db.getConfig() + .get(WorkingTreeOptions.KEY); + CheckoutMetadata checkoutMetadata = new CheckoutMetadata( + eolStreamType, filterCommand); + DirCacheCheckout.getContent(db, entryPath, + checkoutMetadata, pair.open(side, entry), opt, + new FileOutputStream( + fileElement.createTempFile(null))); + } else { + throw new ToolException("Cannot find path '" + entryPath //$NON-NLS-1$ + + "' in staging area!", //$NON-NLS-1$ + null); + } + } + } + return fileElement; + } + + private ContentSource source(AbstractTreeIterator iterator) { + if (iterator instanceof WorkingTreeIterator) { + return ContentSource.create((WorkingTreeIterator) iterator); + } + return ContentSource.create(db.newObjectReader()); + } + } diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Merge.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Merge.java index ca4877fb34..27a3d90fad 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Merge.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Merge.java @@ -10,6 +10,8 @@ package org.eclipse.jgit.pgm; +import static org.eclipse.jgit.lib.Constants.OBJECT_ID_ABBREV_STRING_LENGTH; + import java.io.IOException; import java.text.MessageFormat; import java.util.Map; @@ -144,8 +146,10 @@ class Merge extends TextBuiltin { case FAST_FORWARD: ObjectId oldHeadId = oldHead.getObjectId(); if (oldHeadId != null) { - String oldId = oldHeadId.abbreviate(7).name(); - String newId = result.getNewHead().abbreviate(7).name(); + String oldId = oldHeadId + .abbreviate(OBJECT_ID_ABBREV_STRING_LENGTH).name(); + String newId = result.getNewHead() + .abbreviate(OBJECT_ID_ABBREV_STRING_LENGTH).name(); outw.println(MessageFormat.format(CLIText.get().updating, oldId, newId)); } diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/MergeTool.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/MergeTool.java new file mode 100644 index 0000000000..a382fab757 --- /dev/null +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/MergeTool.java @@ -0,0 +1,483 @@ +/* + * Copyright (C) 2018-2022, Andre Bossert <andre.bossert@siemens.com> + * Copyright (C) 2019, Tim Neumann <tim.neumann@advantest.com> + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Distribution License v. 1.0 which is available at + * https://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +package org.eclipse.jgit.pgm; + +import static org.eclipse.jgit.treewalk.TreeWalk.OperationType.CHECKOUT_OP; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.nio.charset.Charset; +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.TreeMap; + +import org.eclipse.jgit.api.Git; +import org.eclipse.jgit.api.Status; +import org.eclipse.jgit.api.StatusCommand; +import org.eclipse.jgit.api.errors.GitAPIException; +import org.eclipse.jgit.diff.ContentSource; +import org.eclipse.jgit.dircache.DirCache; +import org.eclipse.jgit.dircache.DirCacheCheckout; +import org.eclipse.jgit.dircache.DirCacheCheckout.CheckoutMetadata; +import org.eclipse.jgit.dircache.DirCacheEntry; +import org.eclipse.jgit.dircache.DirCacheIterator; +import org.eclipse.jgit.errors.NoWorkTreeException; +import org.eclipse.jgit.errors.RevisionSyntaxException; +import org.eclipse.jgit.internal.diffmergetool.ExternalMergeTool; +import org.eclipse.jgit.internal.diffmergetool.FileElement; +import org.eclipse.jgit.internal.diffmergetool.FileElement.Type; +import org.eclipse.jgit.internal.diffmergetool.MergeTools; +import org.eclipse.jgit.internal.diffmergetool.ToolException; +import org.eclipse.jgit.lib.Constants; +import org.eclipse.jgit.lib.CoreConfig.EolStreamType; +import org.eclipse.jgit.lib.IndexDiff.StageState; +import org.eclipse.jgit.lib.ObjectId; +import org.eclipse.jgit.lib.Repository; +import org.eclipse.jgit.lib.internal.BooleanTriState; +import org.eclipse.jgit.pgm.internal.CLIText; +import org.eclipse.jgit.revwalk.RevWalk; +import org.eclipse.jgit.treewalk.TreeWalk; +import org.eclipse.jgit.treewalk.WorkingTreeOptions; +import org.eclipse.jgit.treewalk.filter.PathFilterGroup; +import org.eclipse.jgit.util.FS.ExecutionResult; +import org.eclipse.jgit.util.SystemReader; +import org.kohsuke.args4j.Argument; +import org.kohsuke.args4j.Option; +import org.kohsuke.args4j.spi.RestOfArgumentsHandler; + +@Command(name = "mergetool", common = true, usage = "usage_MergeTool") +class MergeTool extends TextBuiltin { + private MergeTools mergeTools; + + private Optional<String> toolName = Optional.empty(); + + @Option(name = "--tool", aliases = { + "-t" }, metaVar = "metaVar_tool", usage = "usage_ToolForMerge") + void setToolName(String name) { + toolName = Optional.of(name); + } + + private BooleanTriState prompt = BooleanTriState.UNSET; + + @Option(name = "--prompt", usage = "usage_prompt") + void setPrompt(@SuppressWarnings("unused") boolean on) { + prompt = BooleanTriState.TRUE; + } + + @Option(name = "--no-prompt", aliases = { "-y" }, usage = "usage_noPrompt") + void noPrompt(@SuppressWarnings("unused") boolean on) { + prompt = BooleanTriState.FALSE; + } + + @Option(name = "--tool-help", usage = "usage_toolHelp") + private boolean toolHelp; + + private boolean gui = false; + + @Option(name = "--gui", aliases = { "-g" }, usage = "usage_MergeGuiTool") + void setGui(@SuppressWarnings("unused") boolean on) { + gui = true; + } + + @Option(name = "--no-gui", usage = "usage_noGui") + void noGui(@SuppressWarnings("unused") boolean on) { + gui = false; + } + + @Argument(required = false, index = 0, metaVar = "metaVar_paths") + @Option(name = "--", metaVar = "metaVar_paths", handler = RestOfArgumentsHandler.class) + protected List<String> filterPaths; + + private BufferedReader inputReader; + + @Override + protected void init(Repository repository, String gitDir) { + super.init(repository, gitDir); + mergeTools = new MergeTools(repository); + inputReader = new BufferedReader( + new InputStreamReader(ins, + SystemReader.getInstance().getDefaultCharset())); + } + + enum MergeResult { + SUCCESSFUL, FAILED, ABORTED + } + + @Override + protected void run() { + try { + if (toolHelp) { + showToolHelp(); + } else { + // get the changed files + Map<String, StageState> files = getFiles(); + if (files.size() > 0) { + merge(files); + } else { + outw.println(CLIText.get().mergeToolNoFiles); + } + } + outw.flush(); + } catch (Exception e) { + throw die(e.getMessage(), e); + } + } + + private void informUserNoTool(List<String> tools) { + try { + StringBuilder toolNames = new StringBuilder(); + for (String name : tools) { + toolNames.append(name + " "); //$NON-NLS-1$ + } + outw.println(MessageFormat + .format(CLIText.get().mergeToolPromptToolName, toolNames)); + outw.flush(); + } catch (IOException e) { + throw new IllegalStateException("Cannot output text", e); //$NON-NLS-1$ + } + } + + private void merge(Map<String, StageState> files) throws Exception { + // sort file names + List<String> mergedFilePaths = new ArrayList<>(files.keySet()); + Collections.sort(mergedFilePaths); + // show the files + StringBuilder mergedFiles = new StringBuilder(); + for (String mergedFilePath : mergedFilePaths) { + mergedFiles.append(MessageFormat.format("{0}\n", mergedFilePath)); //$NON-NLS-1$ + } + outw.println(MessageFormat.format(CLIText.get().mergeToolMerging, + mergedFiles)); + outw.flush(); + boolean showPrompt = mergeTools.isInteractive(); + if (prompt != BooleanTriState.UNSET) { + showPrompt = prompt == BooleanTriState.TRUE; + } + // merge the files + MergeResult mergeResult = MergeResult.SUCCESSFUL; + for (String mergedFilePath : mergedFilePaths) { + // if last merge failed... + if (mergeResult == MergeResult.FAILED) { + // check if user wants to continue + if (showPrompt && !isContinueUnresolvedPaths()) { + mergeResult = MergeResult.ABORTED; + } + } + // aborted ? + if (mergeResult == MergeResult.ABORTED) { + break; + } + // get file stage state and merge + StageState fileState = files.get(mergedFilePath); + if (fileState == StageState.BOTH_MODIFIED) { + mergeResult = mergeModified(mergedFilePath, showPrompt); + } else if ((fileState == StageState.DELETED_BY_US) + || (fileState == StageState.DELETED_BY_THEM)) { + mergeResult = mergeDeleted(mergedFilePath, + fileState == StageState.DELETED_BY_US); + } else { + outw.println(MessageFormat.format( + CLIText.get().mergeToolUnknownConflict, + mergedFilePath)); + mergeResult = MergeResult.ABORTED; + } + } + } + + private MergeResult mergeModified(String mergedFilePath, boolean showPrompt) + throws Exception { + outw.println(MessageFormat.format(CLIText.get().mergeToolNormalConflict, + mergedFilePath)); + outw.flush(); + boolean isMergeSuccessful = true; + ContentSource baseSource = ContentSource.create(db.newObjectReader()); + ContentSource localSource = ContentSource.create(db.newObjectReader()); + ContentSource remoteSource = ContentSource.create(db.newObjectReader()); + // temporary directory if mergetool.writeToTemp == true + File tempDir = mergeTools.createTempDirectory(); + // the parent directory for temp files (can be same as tempDir or just + // the worktree dir) + File tempFilesParent = tempDir != null ? tempDir : db.getWorkTree(); + try { + FileElement base = null; + FileElement local = null; + FileElement remote = null; + FileElement merged = new FileElement(mergedFilePath, Type.MERGED, + db.getWorkTree()); + DirCache cache = db.readDirCache(); + try (RevWalk revWalk = new RevWalk(db); + TreeWalk treeWalk = new TreeWalk(db, + revWalk.getObjectReader())) { + treeWalk.setFilter( + PathFilterGroup.createFromStrings(mergedFilePath)); + DirCacheIterator cacheIter = new DirCacheIterator(cache); + treeWalk.addTree(cacheIter); + while (treeWalk.next()) { + if (treeWalk.isSubtree()) { + treeWalk.enterSubtree(); + continue; + } + final EolStreamType eolStreamType = treeWalk + .getEolStreamType(CHECKOUT_OP); + final String filterCommand = treeWalk.getFilterCommand( + Constants.ATTR_FILTER_TYPE_SMUDGE); + WorkingTreeOptions opt = db.getConfig() + .get(WorkingTreeOptions.KEY); + CheckoutMetadata checkoutMetadata = new CheckoutMetadata( + eolStreamType, filterCommand); + DirCacheEntry entry = treeWalk + .getTree(DirCacheIterator.class).getDirCacheEntry(); + if (entry == null) { + continue; + } + ObjectId id = entry.getObjectId(); + switch (entry.getStage()) { + case DirCacheEntry.STAGE_1: + base = new FileElement(mergedFilePath, Type.BASE); + DirCacheCheckout.getContent(db, mergedFilePath, + checkoutMetadata, + baseSource.open(mergedFilePath, id), opt, + new FileOutputStream( + base.createTempFile(tempFilesParent))); + break; + case DirCacheEntry.STAGE_2: + local = new FileElement(mergedFilePath, Type.LOCAL); + DirCacheCheckout.getContent(db, mergedFilePath, + checkoutMetadata, + localSource.open(mergedFilePath, id), opt, + new FileOutputStream( + local.createTempFile(tempFilesParent))); + break; + case DirCacheEntry.STAGE_3: + remote = new FileElement(mergedFilePath, Type.REMOTE); + DirCacheCheckout.getContent(db, mergedFilePath, + checkoutMetadata, + remoteSource.open(mergedFilePath, id), opt, + new FileOutputStream(remote + .createTempFile(tempFilesParent))); + break; + } + } + } + if ((local == null) || (remote == null)) { + throw die(MessageFormat.format(CLIText.get().mergeToolDied, + mergedFilePath)); + } + long modifiedBefore = merged.getFile().lastModified(); + try { + // TODO: check how to return the exit-code of the + // tool to jgit / java runtime ? + // int rc =... + Optional<ExecutionResult> optionalResult = mergeTools.merge( + local, remote, merged, base, tempDir, toolName, prompt, + gui, this::promptForLaunch, this::informUserNoTool); + if (optionalResult.isPresent()) { + ExecutionResult result = optionalResult.get(); + Charset defaultCharset = SystemReader.getInstance() + .getDefaultCharset(); + outw.println(new String(result.getStdout().toByteArray(), + defaultCharset)); + outw.flush(); + errw.println(new String(result.getStderr().toByteArray(), + defaultCharset)); + errw.flush(); + } else { + return MergeResult.ABORTED; + } + } catch (ToolException e) { + isMergeSuccessful = false; + outw.println(e.getResultStdout()); + outw.flush(); + errw.println(e.getMessage()); + errw.println(MessageFormat.format( + CLIText.get().mergeToolMergeFailed, mergedFilePath)); + errw.flush(); + if (e.isCommandExecutionError()) { + throw die(CLIText.get().mergeToolExecutionError, e); + } + } + // if merge was successful check file modified + if (isMergeSuccessful) { + long modifiedAfter = merged.getFile().lastModified(); + if (modifiedBefore == modifiedAfter) { + outw.println(MessageFormat.format( + CLIText.get().mergeToolFileUnchanged, + mergedFilePath)); + isMergeSuccessful = !showPrompt || isMergeSuccessful(); + } + } + // if automatically or manually successful + // -> add the file to the index + if (isMergeSuccessful) { + addFile(mergedFilePath); + } + } finally { + baseSource.close(); + localSource.close(); + remoteSource.close(); + } + return isMergeSuccessful ? MergeResult.SUCCESSFUL : MergeResult.FAILED; + } + + private MergeResult mergeDeleted(String mergedFilePath, boolean deletedByUs) + throws Exception { + outw.println(MessageFormat.format(CLIText.get().mergeToolFileUnchanged, + mergedFilePath)); + if (deletedByUs) { + outw.println(CLIText.get().mergeToolDeletedConflictByUs); + } else { + outw.println(CLIText.get().mergeToolDeletedConflictByThem); + } + int mergeDecision = getDeletedMergeDecision(); + if (mergeDecision == 1) { + // add modified file + addFile(mergedFilePath); + } else if (mergeDecision == -1) { + // remove deleted file + rmFile(mergedFilePath); + } else { + return MergeResult.ABORTED; + } + return MergeResult.SUCCESSFUL; + } + + private void addFile(String fileName) throws Exception { + try (Git git = new Git(db)) { + git.add().addFilepattern(fileName).call(); + } + } + + private void rmFile(String fileName) throws Exception { + try (Git git = new Git(db)) { + git.rm().addFilepattern(fileName).call(); + } + } + + private boolean hasUserAccepted(String message) throws IOException { + boolean yes = true; + outw.print(message + " "); //$NON-NLS-1$ + outw.flush(); + BufferedReader br = inputReader; + String line = null; + while ((line = br.readLine()) != null) { + if (line.equalsIgnoreCase("y")) { //$NON-NLS-1$ + yes = true; + break; + } else if (line.equalsIgnoreCase("n")) { //$NON-NLS-1$ + yes = false; + break; + } + outw.print(message); + outw.flush(); + } + return yes; + } + + private boolean isContinueUnresolvedPaths() throws IOException { + return hasUserAccepted(CLIText.get().mergeToolContinueUnresolvedPaths); + } + + private boolean isMergeSuccessful() throws IOException { + return hasUserAccepted(CLIText.get().mergeToolWasMergeSuccessfull); + } + + private boolean promptForLaunch(String toolNamePrompt) { + try { + boolean launch = true; + outw.print(MessageFormat.format(CLIText.get().mergeToolLaunch, + toolNamePrompt) + " "); //$NON-NLS-1$ + outw.flush(); + BufferedReader br = inputReader; + String line = null; + if ((line = br.readLine()) != null) { + if (!line.equalsIgnoreCase("y") && !line.equalsIgnoreCase("")) { //$NON-NLS-1$ //$NON-NLS-2$ + launch = false; + } + } + return launch; + } catch (IOException e) { + throw new IllegalStateException("Cannot output text", e); //$NON-NLS-1$ + } + } + + private int getDeletedMergeDecision() throws IOException { + int ret = 0; // abort + final String message = CLIText.get().mergeToolDeletedMergeDecision + + " "; //$NON-NLS-1$ + outw.print(message); + outw.flush(); + BufferedReader br = inputReader; + String line = null; + while ((line = br.readLine()) != null) { + if (line.equalsIgnoreCase("m")) { //$NON-NLS-1$ + ret = 1; // modified + break; + } else if (line.equalsIgnoreCase("d")) { //$NON-NLS-1$ + ret = -1; // deleted + break; + } else if (line.equalsIgnoreCase("a")) { //$NON-NLS-1$ + break; + } + outw.print(message); + outw.flush(); + } + return ret; + } + + private void showToolHelp() throws IOException { + Map<String, ExternalMergeTool> predefTools = mergeTools + .getPredefinedTools(true); + StringBuilder availableToolNames = new StringBuilder(); + StringBuilder notAvailableToolNames = new StringBuilder(); + for (String name : predefTools.keySet()) { + if (predefTools.get(name).isAvailable()) { + availableToolNames.append(MessageFormat.format("\t\t{0}\n", name)); //$NON-NLS-1$ + } else { + notAvailableToolNames.append(MessageFormat.format("\t\t{0}\n", name)); //$NON-NLS-1$ + } + } + StringBuilder userToolNames = new StringBuilder(); + Map<String, ExternalMergeTool> userTools = mergeTools + .getUserDefinedTools(); + for (String name : userTools.keySet()) { + userToolNames.append(MessageFormat.format("\t\t{0}.cmd {1}\n", //$NON-NLS-1$ + name, userTools.get(name).getCommand())); + } + outw.println(MessageFormat.format( + CLIText.get().mergeToolHelpSetToFollowing, availableToolNames, + userToolNames, notAvailableToolNames)); + } + + private Map<String, StageState> getFiles() throws RevisionSyntaxException, + NoWorkTreeException, GitAPIException { + Map<String, StageState> files = new TreeMap<>(); + try (Git git = new Git(db)) { + StatusCommand statusCommand = git.status(); + if (filterPaths != null && filterPaths.size() > 0) { + for (String path : filterPaths) { + statusCommand.addPath(path); + } + } + Status status = statusCommand.call(); + files = status.getConflictingStageState(); + } + return files; + } + +} diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Reflog.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Reflog.java index 030119ea34..c63532df60 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Reflog.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Reflog.java @@ -9,6 +9,8 @@ */ package org.eclipse.jgit.pgm; +import static org.eclipse.jgit.lib.Constants.OBJECT_ID_ABBREV_STRING_LENGTH; + import java.io.IOException; import java.util.Collection; @@ -45,7 +47,8 @@ class Reflog extends TextBuiltin { private String toString(ReflogEntry entry, int i) { final StringBuilder s = new StringBuilder(); - s.append(entry.getNewId().abbreviate(7).name()); + s.append(entry.getNewId().abbreviate(OBJECT_ID_ABBREV_STRING_LENGTH) + .name()); s.append(" "); //$NON-NLS-1$ s.append(ref == null ? Constants.HEAD : Repository.shortenRefName(ref)); s.append("@{" + i + "}:"); //$NON-NLS-1$ //$NON-NLS-2$ diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/internal/CLIText.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/internal/CLIText.java index 7fe5b0fa45..e06f150e51 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/internal/CLIText.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/internal/CLIText.java @@ -139,6 +139,8 @@ public class CLIText extends TranslationBundle { /***/ public String diffToolHelpSetToFollowing; /***/ public String diffToolLaunch; /***/ public String diffToolDied; + /***/ public String diffToolPromptToolName; + /***/ public String diffToolUnknownToolName; /***/ public String doesNotExist; /***/ public String dontOverwriteLocalChanges; /***/ public String everythingUpToDate; @@ -169,6 +171,24 @@ public class CLIText extends TranslationBundle { /***/ public String logNoSignatureVerifier; /***/ public String mergeCheckoutConflict; /***/ public String mergeConflict; + /***/ public String mergeToolHelpSetToFollowing; + /***/ public String mergeToolLaunch; + /***/ public String mergeToolDied; + /***/ public String mergeToolNoFiles; + /***/ public String mergeToolMerging; + /***/ public String mergeToolUnknownConflict; + /***/ public String mergeToolNormalConflict; + /***/ public String mergeToolMergeFailed; + /***/ public String mergeToolExecutionError; + /***/ public String mergeToolFileUnchanged; + /***/ public String mergeToolDeletedConflict; + /***/ public String mergeToolDeletedConflictByUs; + /***/ public String mergeToolDeletedConflictByThem; + /***/ public String mergeToolContinueUnresolvedPaths; + /***/ public String mergeToolWasMergeSuccessfull; + /***/ public String mergeToolDeletedMergeDecision; + /***/ public String mergeToolPromptToolName; + /***/ public String mergeToolUnknownToolName; /***/ public String mergeFailed; /***/ public String mergeCheckoutFailed; /***/ public String mergeMadeBy; diff --git a/org.eclipse.jgit.ssh.apache.agent/BUILD b/org.eclipse.jgit.ssh.apache.agent/BUILD index 0c8cf838d4..f2e4d55165 100644 --- a/org.eclipse.jgit.ssh.apache.agent/BUILD +++ b/org.eclipse.jgit.ssh.apache.agent/BUILD @@ -17,6 +17,6 @@ java_library( "//lib:slf4j-api", "//lib:sshd-osgi", "//org.eclipse.jgit:jgit", - "//org.eclipse.jgit.ssh.apache:ssh-apache" + "//org.eclipse.jgit.ssh.apache:ssh-apache", ], ) diff --git a/org.eclipse.jgit.ssh.apache.agent/README.md b/org.eclipse.jgit.ssh.apache.agent/README.md new file mode 100644 index 0000000000..6d62a2fd81 --- /dev/null +++ b/org.eclipse.jgit.ssh.apache.agent/README.md @@ -0,0 +1,82 @@ +# JGit SSH agent transport support for Apache MINA sshd + +This bundle provides optional support for communicating with an SSH agent +for SSH or SFTP authentication. It is an OSGi fragment for bundle +[org.eclipse.jgit.ssh.apache](../org.eclipse.jgit.ssh.apache/README.md), +and it provides transports for local communication with SSH agents. + +## Supported SSH agent transports + +### Linux, OS X, BSD + +On Linux, OS X, and BSD, the only transport mechanism supported is the usual +communication via a Unix domain socket. This is the only protocol the OpenSSH +SSH agent supports. A Unix domain socket appears as a special file in the file +system; this file name is typically available in the environment variable +`SSH_AUTH_SOCK`. + +The SSH config `IdentityAgent` can be set to this socket filename to specify +exactly which Unix domain socket to use, or it can be set to `SSH_AUTH_SOCK` +to use the value from that environment variable. If `IdentityAgent` is not set +at all, JGit uses `SSH_AUTH_SOCK` by default. If the variable is not set, no +SSH agent will be used. `IdentityAgent` can also be set to `none` to not use +any SSH agent. + +### Windows + +On Windows, two different transports are supported: + +* A transport over a Windows named pipe. This is used by Win32-OpenSSH, and is available for Pageant since version 0.75. +* A Pageant-specific legacy transport via shared memory; useful for Pageant and GPG's gpg-agent. + +Possible settings of `IdentityAgent` to select a particular transport are + +* `//./pipe/openssh-ssh-agent`: the Windows named pipe of Win32-OpenSSH. +* `//./pageant`: the shared-memory mechanism of Pageant. +* `none`: do not use any SSH agent. +* `//./pipe/<any_valid_pipe_name>`: use a specific Windows named pipe. + +The default transport on Windows if `IdentityAgent` is not set at all is the +Pageant shared-memory transport. Environment variable `SSH_AUTH_SOCK` needs +not be set for Pageant, and _must not_ be set for Win32-OpenSSH. + +It is also possible to use a named pipe as transport for Pageant (as of +version 0.75). Unfortunately, Pageant unnecessarily cryptographically +obfuscates the pipe name, so it is not possible for JGit to determine it +automatically. The pipe name is `pageant.<user name>.<sha256>`, for instance +`pageant.myself.c5687736ba755a70b000955cb191698aed7db221c2b0710199eb1f5298922ab5`. +A user can look up the name by starting Pageant and then running the +command `dir \\.\pipe\\` in a command shell. Once the name is known, setting +`IdentityAgent` to the pipe name as +`//./pipe/pageant.myself.c5687736ba755a70b000955cb191698aed7db221c2b0710199eb1f5298922ab5` +makes JGit use this Windows named pipe for communication with Pageant. + +(You can use forward slashes in the `~/.ssh/config` file. SSH config file +parsing has its own rules about backslashes in config files; which are +treated as escape characters in some contexts. With backslashes one would +have to write, e.g., `\\\\.\pipe\openssh-ssh-agent`.) + +With these two transport mechanisms, Pageant and Win32-OpenSSH are supported. +As for GPG: the gpg-agent can be configured to emulate ssh-agent (presumably +via a WinSockets2 "Unix domain socket" on Windows) or to emulate Pageant +(using the shared memory mechanism). Running gpg-agent with the +`enable-ssh-support` option is +[reported not to work on Windows](https://dev.gnupg.org/T3883), though. But +the PuTTY emulation in gpg-agent (option `enable-putty-support`) _should_ work, +so it should be possible to use gpg-agent instead of Pageant. + +Neither Pageant (as of version 0.76) nor Win32-OpenSSH (as of version 8.6) +support the `confirm` or lifetime constraints for `AddKeysToAgent`. gpg-agent +apparently does, even when communicating over the Pageant shared memory +mechanism. + +The ssh-agent from git bash on Windows is currently not supported. It would +need a connector handling Cygwin socket files and the Cygwin handshake over +a TCP stream socket bound to the loopback interface. The Cygwin socket file +_is_ exposed in the Windows file system at %TEMP%\ssh-XXXXXXXXXX\agent.<number>, +but it does not have a fixed name (the X's and the number are variable and +change each time ssh-agent is started). + +## Implementation + +The implementation of all transports uses JNA.
\ No newline at end of file diff --git a/org.eclipse.jgit.ssh.apache.agent/pom.xml b/org.eclipse.jgit.ssh.apache.agent/pom.xml index d48fd00f84..6b4ca30fd1 100644 --- a/org.eclipse.jgit.ssh.apache.agent/pom.xml +++ b/org.eclipse.jgit.ssh.apache.agent/pom.xml @@ -132,7 +132,6 @@ </configuration> </plugin> - <!-- New in 6.0; uncomment in 6.1 <plugin> <groupId>com.github.siom79.japicmp</groupId> <artifactId>japicmp-maven-plugin</artifactId> @@ -155,6 +154,9 @@ <includes> <include>org.eclipse.jgit.*</include> </includes> + <excludes> + <exclude>*.internal.*</exclude> + </excludes> <accessModifier>public</accessModifier> <breakBuildOnModifications>false</breakBuildOnModifications> <breakBuildOnBinaryIncompatibleModifications>false</breakBuildOnBinaryIncompatibleModifications> @@ -174,11 +176,9 @@ </execution> </executions> </plugin> - --> </plugins> </build> - <!-- New in 6.0, uncomment in 6.1 <reporting> <plugins> <plugin> @@ -210,6 +210,9 @@ <includes> <include>org.eclipse.jgit.*</include> </includes> + <excludes> + <exclude>*.internal.*</exclude> + </excludes> <accessModifier>public</accessModifier> <breakBuildOnModifications>false</breakBuildOnModifications> <breakBuildOnBinaryIncompatibleModifications>false</breakBuildOnBinaryIncompatibleModifications> @@ -223,5 +226,4 @@ </plugin> </plugins> </reporting> - --> </project> diff --git a/org.eclipse.jgit.ssh.apache.agent/resources/org/eclipse/jgit/internal/transport/sshd/agent/connector/Texts.properties b/org.eclipse.jgit.ssh.apache.agent/resources/org/eclipse/jgit/internal/transport/sshd/agent/connector/Texts.properties index 6fce083668..a3b4e91cad 100644 --- a/org.eclipse.jgit.ssh.apache.agent/resources/org/eclipse/jgit/internal/transport/sshd/agent/connector/Texts.properties +++ b/org.eclipse.jgit.ssh.apache.agent/resources/org/eclipse/jgit/internal/transport/sshd/agent/connector/Texts.properties @@ -2,9 +2,11 @@ errCloseMappedFile=Cannot close mapped file: {0} - {1} errLastError=System message for error {0} could not be retrieved, got {1} errReleaseSharedMemory=Cannot release shared memory: {0} - {1} errUnknown=unknown error +errUnknownIdentityAgent=IdentityAgent ''{0}'' unknown logErrorLoadLibrary=Cannot load socket library; SSH agent support is switched off msgCloseFailed=Cannot close SSH agent socket {0} msgConnectFailed=Could not connect to SSH agent via socket ''{0}'' +msgConnectPipeFailed=Could not connect to SSH agent via pipe ''{0}'' msgNoMappedFile=Could not create file mapping: {0} - {1} msgNoSharedMemory=Could not initialize shared memory: {0} - {1} msgPageantUnavailable=Could not connect to Pageant @@ -15,3 +17,4 @@ msgSharedMemoryFailed=Could not set up shared memory for communicating with Page msgShortRead=Short read from SSH agent, expected {0} bytes, got {1} bytes; last read() returned {2} pageant=Pageant unixDefaultAgent=ssh-agent +winOpenSsh=Win32 OpenSSH diff --git a/org.eclipse.jgit.ssh.apache.agent/src/org/eclipse/jgit/internal/transport/sshd/agent/connector/Factory.java b/org.eclipse.jgit.ssh.apache.agent/src/org/eclipse/jgit/internal/transport/sshd/agent/connector/Factory.java index d7409b0c3c..1cee1be13e 100644 --- a/org.eclipse.jgit.ssh.apache.agent/src/org/eclipse/jgit/internal/transport/sshd/agent/connector/Factory.java +++ b/org.eclipse.jgit.ssh.apache.agent/src/org/eclipse/jgit/internal/transport/sshd/agent/connector/Factory.java @@ -11,11 +11,15 @@ package org.eclipse.jgit.internal.transport.sshd.agent.connector; import java.io.File; import java.io.IOException; +import java.text.MessageFormat; import java.util.Collection; import java.util.Collections; +import java.util.List; +import java.util.Locale; import org.eclipse.jgit.transport.sshd.agent.Connector; import org.eclipse.jgit.transport.sshd.agent.ConnectorFactory; +import org.eclipse.jgit.util.StringUtils; import org.eclipse.jgit.util.SystemReader; /** @@ -29,7 +33,20 @@ public class Factory implements ConnectorFactory { public Connector create(String identityAgent, File homeDir) throws IOException { if (SystemReader.getInstance().isWindows()) { - return new PageantConnector(); + if (StringUtils.isEmptyOrNull(identityAgent)) { + // Default. + return new PageantConnector(); + } + String winPath = identityAgent.replace('/', '\\'); + if (PageantConnector.DESCRIPTOR.getIdentityAgent() + .equalsIgnoreCase(winPath)) { + return new PageantConnector(); + } + if (winPath.toLowerCase(Locale.ROOT).startsWith("\\\\.\\pipe\\")) { //$NON-NLS-1$ + return new WinPipeConnector(winPath); + } + throw new IOException(MessageFormat.format( + Texts.get().errUnknownIdentityAgent, identityAgent)); } return new UnixDomainSocketConnector(identityAgent); } @@ -55,7 +72,11 @@ public class Factory implements ConnectorFactory { */ @Override public Collection<ConnectorDescriptor> getSupportedConnectors() { - return Collections.singleton(getDefaultConnector()); + if (SystemReader.getInstance().isWindows()) { + return List.of(PageantConnector.DESCRIPTOR, + WinPipeConnector.DESCRIPTOR); + } + return Collections.singleton(UnixDomainSocketConnector.DESCRIPTOR); } @Override diff --git a/org.eclipse.jgit.ssh.apache.agent/src/org/eclipse/jgit/internal/transport/sshd/agent/connector/LibraryHolder.java b/org.eclipse.jgit.ssh.apache.agent/src/org/eclipse/jgit/internal/transport/sshd/agent/connector/LibraryHolder.java index b09b55f817..0a592d0500 100644 --- a/org.eclipse.jgit.ssh.apache.agent/src/org/eclipse/jgit/internal/transport/sshd/agent/connector/LibraryHolder.java +++ b/org.eclipse.jgit.ssh.apache.agent/src/org/eclipse/jgit/internal/transport/sshd/agent/connector/LibraryHolder.java @@ -53,6 +53,10 @@ class LibraryHolder { kernel = Kernel32.INSTANCE; } + String systemError() { + return systemError("[{0}] - {1}"); //$NON-NLS-1$ + } + String systemError(String pattern) { int lastError = kernel.GetLastError(); String msg; diff --git a/org.eclipse.jgit.ssh.apache.agent/src/org/eclipse/jgit/internal/transport/sshd/agent/connector/PageantConnector.java b/org.eclipse.jgit.ssh.apache.agent/src/org/eclipse/jgit/internal/transport/sshd/agent/connector/PageantConnector.java index b0e3bce724..19684ecb93 100644 --- a/org.eclipse.jgit.ssh.apache.agent/src/org/eclipse/jgit/internal/transport/sshd/agent/connector/PageantConnector.java +++ b/org.eclipse.jgit.ssh.apache.agent/src/org/eclipse/jgit/internal/transport/sshd/agent/connector/PageantConnector.java @@ -26,7 +26,10 @@ public class PageantConnector extends AbstractConnector { @Override public String getIdentityAgent() { - return "pageant"; //$NON-NLS-1$ + // This must be an absolute Windows path name to avoid that + // OpenSshConfigFile treats it as a relative path name. Use an UNC + // name on localhost, like for pipes. + return "\\\\.\\pageant"; //$NON-NLS-1$ } @Override diff --git a/org.eclipse.jgit.ssh.apache.agent/src/org/eclipse/jgit/internal/transport/sshd/agent/connector/Sockets.java b/org.eclipse.jgit.ssh.apache.agent/src/org/eclipse/jgit/internal/transport/sshd/agent/connector/Sockets.java index 3d95bdb51c..52cf5f22f2 100644 --- a/org.eclipse.jgit.ssh.apache.agent/src/org/eclipse/jgit/internal/transport/sshd/agent/connector/Sockets.java +++ b/org.eclipse.jgit.ssh.apache.agent/src/org/eclipse/jgit/internal/transport/sshd/agent/connector/Sockets.java @@ -24,11 +24,6 @@ public final class Sockets { } /** - * Default SSH agent socket environment variable name. - */ - public static final String ENV_SSH_AUTH_SOCK = "SSH_AUTH_SOCK"; //$NON-NLS-1$ - - /** * Domain for Unix domain sockets. */ public static final int AF_UNIX = 1; diff --git a/org.eclipse.jgit.ssh.apache.agent/src/org/eclipse/jgit/internal/transport/sshd/agent/connector/Texts.java b/org.eclipse.jgit.ssh.apache.agent/src/org/eclipse/jgit/internal/transport/sshd/agent/connector/Texts.java index fb45b30dd2..f387c76ad8 100644 --- a/org.eclipse.jgit.ssh.apache.agent/src/org/eclipse/jgit/internal/transport/sshd/agent/connector/Texts.java +++ b/org.eclipse.jgit.ssh.apache.agent/src/org/eclipse/jgit/internal/transport/sshd/agent/connector/Texts.java @@ -31,9 +31,11 @@ public final class Texts extends TranslationBundle { /***/ public String errLastError; /***/ public String errReleaseSharedMemory; /***/ public String errUnknown; + /***/ public String errUnknownIdentityAgent; /***/ public String logErrorLoadLibrary; /***/ public String msgCloseFailed; /***/ public String msgConnectFailed; + /***/ public String msgConnectPipeFailed; /***/ public String msgNoMappedFile; /***/ public String msgNoSharedMemory; /***/ public String msgPageantUnavailable; @@ -44,5 +46,6 @@ public final class Texts extends TranslationBundle { /***/ public String msgShortRead; /***/ public String pageant; /***/ public String unixDefaultAgent; + /***/ public String winOpenSsh; } diff --git a/org.eclipse.jgit.ssh.apache.agent/src/org/eclipse/jgit/internal/transport/sshd/agent/connector/UnixDomainSocketConnector.java b/org.eclipse.jgit.ssh.apache.agent/src/org/eclipse/jgit/internal/transport/sshd/agent/connector/UnixDomainSocketConnector.java index 3b75f3a7da..95ac34f940 100644 --- a/org.eclipse.jgit.ssh.apache.agent/src/org/eclipse/jgit/internal/transport/sshd/agent/connector/UnixDomainSocketConnector.java +++ b/org.eclipse.jgit.ssh.apache.agent/src/org/eclipse/jgit/internal/transport/sshd/agent/connector/UnixDomainSocketConnector.java @@ -11,10 +11,10 @@ package org.eclipse.jgit.internal.transport.sshd.agent.connector; import static org.eclipse.jgit.internal.transport.sshd.agent.connector.Sockets.AF_UNIX; import static org.eclipse.jgit.internal.transport.sshd.agent.connector.Sockets.DEFAULT_PROTOCOL; -import static org.eclipse.jgit.internal.transport.sshd.agent.connector.Sockets.ENV_SSH_AUTH_SOCK; import static org.eclipse.jgit.internal.transport.sshd.agent.connector.Sockets.SOCK_STREAM; import static org.eclipse.jgit.internal.transport.sshd.agent.connector.UnixSockets.FD_CLOEXEC; import static org.eclipse.jgit.internal.transport.sshd.agent.connector.UnixSockets.F_SETFD; +import static org.eclipse.jgit.transport.SshConstants.ENV_SSH_AUTH_SOCKET; import java.io.IOException; import java.nio.charset.StandardCharsets; @@ -46,7 +46,7 @@ public class UnixDomainSocketConnector extends AbstractConnector { @Override public String getIdentityAgent() { - return ENV_SSH_AUTH_SOCK; + return ENV_SSH_AUTH_SOCKET; } @Override @@ -91,8 +91,9 @@ public class UnixDomainSocketConnector extends AbstractConnector { public UnixDomainSocketConnector(String socketFile) { super(); String file = socketFile; - if (StringUtils.isEmptyOrNull(file)) { - file = SystemReader.getInstance().getenv(ENV_SSH_AUTH_SOCK); + if (StringUtils.isEmptyOrNull(file) + || ENV_SSH_AUTH_SOCKET.equals(file)) { + file = SystemReader.getInstance().getenv(ENV_SSH_AUTH_SOCKET); } this.socketFile = file; } diff --git a/org.eclipse.jgit.ssh.apache.agent/src/org/eclipse/jgit/internal/transport/sshd/agent/connector/WinPipeConnector.java b/org.eclipse.jgit.ssh.apache.agent/src/org/eclipse/jgit/internal/transport/sshd/agent/connector/WinPipeConnector.java new file mode 100644 index 0000000000..81c653722f --- /dev/null +++ b/org.eclipse.jgit.ssh.apache.agent/src/org/eclipse/jgit/internal/transport/sshd/agent/connector/WinPipeConnector.java @@ -0,0 +1,216 @@ +/* + * Copyright (C) 2021, Thomas Wolf <thomas.wolf@paranor.ch> and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Distribution License v. 1.0 which is available at + * https://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: BSD-3-Clause + */ +package org.eclipse.jgit.internal.transport.sshd.agent.connector; + +import java.io.IOException; +import java.text.MessageFormat; +import java.util.Arrays; +import java.util.concurrent.atomic.AtomicBoolean; + +import org.apache.sshd.common.SshException; +import org.eclipse.jgit.transport.sshd.agent.AbstractConnector; +import org.eclipse.jgit.transport.sshd.agent.ConnectorFactory.ConnectorDescriptor; +import org.eclipse.jgit.util.StringUtils; + +import com.sun.jna.LastErrorException; +import com.sun.jna.platform.win32.WinBase; +import com.sun.jna.platform.win32.WinError; +import com.sun.jna.platform.win32.WinNT; +import com.sun.jna.platform.win32.WinNT.HANDLE; +import com.sun.jna.ptr.IntByReference; + +/** + * A connector based on JNA using Windows' named pipes to communicate with an + * ssh agent. This is used by Microsoft's Win32-OpenSSH port. + */ +public class WinPipeConnector extends AbstractConnector { + + // Pipe names are, like other file names, case-insensitive on Windows. + private static final String CANONICAL_PIPE_NAME = "\\\\.\\pipe\\openssh-ssh-agent"; //$NON-NLS-1$ + + /** + * {@link ConnectorDescriptor} for the {@link PageantConnector}. + */ + public static final ConnectorDescriptor DESCRIPTOR = new ConnectorDescriptor() { + + @Override + public String getIdentityAgent() { + return CANONICAL_PIPE_NAME; + } + + @Override + public String getDisplayName() { + return Texts.get().winOpenSsh; + } + }; + + private static final int FILE_SHARE_NONE = 0; + + private static final int FILE_ATTRIBUTE_NONE = 0; + + private final String pipeName; + + private final AtomicBoolean connected = new AtomicBoolean(); + + // It's a byte pipe, so the normal Windows file mechanisms can be used. + // Would one of the standard Java File I/O abstractions work? + private volatile HANDLE fileHandle; + + /** + * Creates a {@link WinPipeConnector} for the given named pipe. + * + * @param pipeName + * to connect to + */ + public WinPipeConnector(String pipeName) { + this.pipeName = pipeName.replace('/', '\\'); + } + + @Override + public boolean connect() throws IOException { + if (StringUtils.isEmptyOrNull(pipeName)) { + return false; + } + HANDLE file = fileHandle; + synchronized (this) { + if (connected.get()) { + return true; + } + LibraryHolder libs = LibraryHolder.getLibrary(); + if (libs == null) { + return false; + } + file = libs.kernel.CreateFile(pipeName, + WinNT.GENERIC_READ | WinNT.GENERIC_WRITE, FILE_SHARE_NONE, + null, WinNT.OPEN_EXISTING, FILE_ATTRIBUTE_NONE, null); + if (file == null || WinBase.INVALID_HANDLE_VALUE.equals(file)) { + int errorCode = libs.kernel.GetLastError(); + if (errorCode == WinError.ERROR_FILE_NOT_FOUND + && CANONICAL_PIPE_NAME.equalsIgnoreCase(pipeName)) { + // OpenSSH agent not running. Don't throw. + return false; + } + LastErrorException cause = new LastErrorException( + libs.systemError()); + throw new IOException(MessageFormat + .format(Texts.get().msgConnectPipeFailed, pipeName), + cause); + } + connected.set(true); + } + fileHandle = file; + return connected.get(); + } + + @Override + public synchronized void close() throws IOException { + HANDLE file = fileHandle; + if (connected.getAndSet(false) && fileHandle != null) { + fileHandle = null; + LibraryHolder libs = LibraryHolder.getLibrary(); + boolean success = libs.kernel.CloseHandle(file); + if (!success) { + LastErrorException cause = new LastErrorException( + libs.systemError()); + throw new IOException(MessageFormat + .format(Texts.get().msgCloseFailed, pipeName), cause); + } + } + } + + @Override + public byte[] rpc(byte command, byte[] message) throws IOException { + prepareMessage(command, message); + HANDLE file = fileHandle; + if (!connected.get() || file == null) { + // No translation, internal error + throw new IllegalStateException("Not connected to SSH agent"); //$NON-NLS-1$ + } + LibraryHolder libs = LibraryHolder.getLibrary(); + writeFully(libs, file, message); + // Now receive the reply + byte[] lengthBuf = new byte[4]; + readFully(libs, file, lengthBuf); + int length = toLength(command, lengthBuf); + byte[] payload = new byte[length]; + readFully(libs, file, payload); + return payload; + } + + private void writeFully(LibraryHolder libs, HANDLE file, byte[] message) + throws IOException { + byte[] buf = message; + int toWrite = buf.length; + try { + while (toWrite > 0) { + IntByReference written = new IntByReference(); + boolean success = libs.kernel.WriteFile(file, buf, buf.length, + written, null); + if (!success) { + throw new LastErrorException(libs.systemError()); + } + int actuallyWritten = written.getValue(); + toWrite -= actuallyWritten; + if (actuallyWritten > 0 && toWrite > 0) { + buf = Arrays.copyOfRange(buf, actuallyWritten, buf.length); + } + } + } catch (LastErrorException e) { + throw new IOException(MessageFormat.format( + Texts.get().msgSendFailed, Integer.toString(message.length), + Integer.toString(toWrite)), e); + } + } + + private void readFully(LibraryHolder libs, HANDLE file, byte[] data) + throws IOException { + int n = 0; + int offset = 0; + while (offset < data.length && (n = read(libs, file, data, offset, + data.length - offset)) > 0) { + offset += n; + } + if (offset < data.length) { + throw new SshException(MessageFormat.format( + Texts.get().msgShortRead, Integer.toString(data.length), + Integer.toString(offset), Integer.toString(n))); + } + } + + private int read(LibraryHolder libs, HANDLE file, byte[] buffer, int offset, + int length) throws IOException { + try { + int toRead = length; + IntByReference read = new IntByReference(); + if (offset == 0) { + boolean success = libs.kernel.ReadFile(file, buffer, toRead, + read, null); + if (!success) { + throw new LastErrorException(libs.systemError()); + } + return read.getValue(); + } + byte[] data = new byte[length]; + boolean success = libs.kernel.ReadFile(file, buffer, toRead, read, + null); + if (!success) { + throw new LastErrorException(libs.systemError()); + } + int actuallyRead = read.getValue(); + if (actuallyRead > 0) { + System.arraycopy(data, 0, buffer, offset, actuallyRead); + } + return actuallyRead; + } catch (LastErrorException e) { + throw new IOException(MessageFormat.format( + Texts.get().msgReadFailed, Integer.toString(length)), e); + } + } +} diff --git a/org.eclipse.jgit.ssh.apache.test/META-INF/MANIFEST.MF b/org.eclipse.jgit.ssh.apache.test/META-INF/MANIFEST.MF index 9e4a8f7d50..0d046c86bb 100644 --- a/org.eclipse.jgit.ssh.apache.test/META-INF/MANIFEST.MF +++ b/org.eclipse.jgit.ssh.apache.test/META-INF/MANIFEST.MF @@ -7,20 +7,20 @@ Bundle-Version: 7.0.0.qualifier Bundle-Vendor: %Bundle-Vendor Bundle-Localization: plugin Bundle-RequiredExecutionEnvironment: JavaSE-11 -Import-Package: org.apache.sshd.client.config.hosts;version="[2.7.0,2.8.0)", - org.apache.sshd.common;version="[2.7.0,2.8.0)", - org.apache.sshd.common.auth;version="[2.7.0,2.8.0)", - org.apache.sshd.common.config.keys;version="[2.7.0,2.8.0)", - org.apache.sshd.common.helpers;version="[2.7.0,2.8.0)", - org.apache.sshd.common.kex;version="[2.7.0,2.8.0)", - org.apache.sshd.common.keyprovider;version="[2.7.0,2.8.0)", - org.apache.sshd.common.session;version="[2.7.0,2.8.0)", - org.apache.sshd.common.signature;version="[2.7.0,2.8.0)", - org.apache.sshd.common.util.net;version="[2.7.0,2.8.0)", - org.apache.sshd.common.util.security;version="[2.7.0,2.8.0)", - org.apache.sshd.core;version="[2.7.0,2.8.0)", - org.apache.sshd.server;version="[2.7.0,2.8.0)", - org.apache.sshd.server.forward;version="[2.7.0,2.8.0)", +Import-Package: org.apache.sshd.client.config.hosts;version="[2.8.0,2.9.0)", + org.apache.sshd.common;version="[2.8.0,2.9.0)", + org.apache.sshd.common.auth;version="[2.8.0,2.9.0)", + org.apache.sshd.common.config.keys;version="[2.8.0,2.9.0)", + org.apache.sshd.common.helpers;version="[2.8.0,2.9.0)", + org.apache.sshd.common.kex;version="[2.8.0,2.9.0)", + org.apache.sshd.common.keyprovider;version="[2.8.0,2.9.0)", + org.apache.sshd.common.session;version="[2.8.0,2.9.0)", + org.apache.sshd.common.signature;version="[2.8.0,2.9.0)", + org.apache.sshd.common.util.net;version="[2.8.0,2.9.0)", + org.apache.sshd.common.util.security;version="[2.8.0,2.9.0)", + org.apache.sshd.core;version="[2.8.0,2.9.0)", + org.apache.sshd.server;version="[2.8.0,2.9.0)", + org.apache.sshd.server.forward;version="[2.8.0,2.9.0)", org.eclipse.jgit.api;version="[7.0.0,7.1.0)", org.eclipse.jgit.api.errors;version="[7.0.0,7.1.0)", org.eclipse.jgit.internal.transport.sshd.proxy;version="[7.0.0,7.1.0)", diff --git a/org.eclipse.jgit.ssh.apache.test/build.properties b/org.eclipse.jgit.ssh.apache.test/build.properties index 406c5a768f..35d7145160 100644 --- a/org.eclipse.jgit.ssh.apache.test/build.properties +++ b/org.eclipse.jgit.ssh.apache.test/build.properties @@ -3,5 +3,4 @@ output.. = bin/ bin.includes = META-INF/,\ .,\ plugin.properties -additional.bundles = org.apache.log4j,\ - org.slf4j.binding.log4j12 +additional.bundles = org.slf4j.binding.simple diff --git a/org.eclipse.jgit.ssh.apache.test/tst/org/eclipse/jgit/transport/sshd/ApacheSshTest.java b/org.eclipse.jgit.ssh.apache.test/tst/org/eclipse/jgit/transport/sshd/ApacheSshTest.java index ccaf98ced0..a8fcca7b8e 100644 --- a/org.eclipse.jgit.ssh.apache.test/tst/org/eclipse/jgit/transport/sshd/ApacheSshTest.java +++ b/org.eclipse.jgit.ssh.apache.test/tst/org/eclipse/jgit/transport/sshd/ApacheSshTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018, 2020 Thomas Wolf <thomas.wolf@paranor.ch> and others + * Copyright (C) 2018, 2022 Thomas Wolf <thomas.wolf@paranor.ch> and others * * This program and the accompanying materials are made available under the * terms of the Eclipse Distribution License v. 1.0 which is available at @@ -107,6 +107,32 @@ public class ApacheSshTest extends SshTestBase { "IdentityFile " + privateKey1.getAbsolutePath()); } + /** + * Test for SSHD-1231. If authentication is attempted first with an RSA key, + * which is rejected, and then with some other key type (here ed25519), + * authentication fails in bug SSHD-1231. + * + * @throws Exception + * on errors + * @see <a href= + * "https://issues.apache.org/jira/browse/SSHD-1231">SSHD-1231</a> + */ + @Test + public void testWrongKeyFirst() throws Exception { + File userKey = new File(getTemporaryDirectory(), "userkey"); + copyTestResource("id_ed25519", userKey); + File publicKey = new File(getTemporaryDirectory(), "userkey.pub"); + copyTestResource("id_ed25519.pub", publicKey); + server.setTestUserPublicKey(publicKey.toPath()); + cloneWith("ssh://git/doesntmatter", defaultCloneDir, null, // + "Host git", // + "HostName localhost", // + "Port " + testPort, // + "User " + TEST_USER, // + "IdentityFile " + privateKey1.getAbsolutePath(), // RSA + "IdentityFile " + userKey.getAbsolutePath()); + } + @Test public void testHashedKnownHosts() throws Exception { assertTrue("Failed to delete known_hosts", knownHosts.delete()); @@ -763,4 +789,76 @@ public class ApacheSshTest extends SshTestBase { session.disconnect(); } } + + private void verifyAuthLog(String message, String first) { + assertTrue(message.contains(System.lineSeparator())); + String[] lines = message.split(System.lineSeparator()); + int pubkeyIndex = -1; + int passwordIndex = -1; + for (int i = 0; i < lines.length; i++) { + String line = lines[i]; + if (i == 0) { + assertTrue(line.contains(first)); + } + if (line.contains("publickey:")) { + if (pubkeyIndex < 0) { + pubkeyIndex = i; + assertTrue(line.contains("/userkey")); + } + } else if (line.contains("password:")) { + if (passwordIndex < 0) { + passwordIndex = i; + assertTrue(line.contains("attempt 1")); + } + } + } + assertTrue(pubkeyIndex > 0 && passwordIndex > 0); + assertTrue(pubkeyIndex < passwordIndex); + } + + @Test + public void testAuthFailureMessageCancel() throws Exception { + File userKey = new File(getTemporaryDirectory(), "userkey"); + copyTestResource("id_ed25519", userKey); + File publicKey = new File(getTemporaryDirectory(), "userkey.pub"); + copyTestResource("id_ed25519.pub", publicKey); + // Don't set this as the user's key; we do want to try with a wrong key. + server.enablePasswordAuthentication(); + TestCredentialsProvider provider = new TestCredentialsProvider( + "wrongpass"); + TransportException e = assertThrows(TransportException.class, + () -> cloneWith("ssh://git/doesntmatter", defaultCloneDir, + provider, // + "Host git", // + "HostName localhost", // + "Port " + testPort, // + "User " + TEST_USER, // + "IdentityFile " + userKey.getAbsolutePath(), // + "PreferredAuthentications publickey,password")); + verifyAuthLog(e.getMessage(), "canceled"); + } + + @Test + public void testAuthFailureMessage() throws Exception { + File userKey = new File(getTemporaryDirectory(), "userkey"); + copyTestResource("id_ed25519", userKey); + File publicKey = new File(getTemporaryDirectory(), "userkey.pub"); + copyTestResource("id_ed25519.pub", publicKey); + // Don't set this as the user's key; we do want to try with a wrong key. + server.enablePasswordAuthentication(); + // Enough passwords not to cancel authentication + TestCredentialsProvider provider = new TestCredentialsProvider( + "wrongpass", "wrongpass", "wrongpass"); + TransportException e = assertThrows(TransportException.class, + () -> cloneWith("ssh://git/doesntmatter", defaultCloneDir, + provider, // + "Host git", // + "HostName localhost", // + "Port " + testPort, // + "User " + TEST_USER, // + "IdentityFile " + userKey.getAbsolutePath(), // + "PreferredAuthentications publickey,password")); + verifyAuthLog(e.getMessage(), "log in"); + } + } diff --git a/org.eclipse.jgit.ssh.apache/META-INF/MANIFEST.MF b/org.eclipse.jgit.ssh.apache/META-INF/MANIFEST.MF index 3bec647dfa..f24ff80218 100644 --- a/org.eclipse.jgit.ssh.apache/META-INF/MANIFEST.MF +++ b/org.eclipse.jgit.ssh.apache/META-INF/MANIFEST.MF @@ -35,54 +35,57 @@ Export-Package: org.eclipse.jgit.internal.transport.sshd;version="7.0.0";x-inter org.apache.sshd.client.keyverifier", org.eclipse.jgit.transport.sshd.agent;version="7.0.0" Import-Package: net.i2p.crypto.eddsa;version="[0.3.0,0.4.0)", - org.apache.sshd.agent;version="[2.7.0,2.8.0)", - org.apache.sshd.client;version="[2.7.0,2.8.0)", - org.apache.sshd.client.auth;version="[2.7.0,2.8.0)", - org.apache.sshd.client.auth.keyboard;version="[2.7.0,2.8.0)", - org.apache.sshd.client.auth.password;version="[2.7.0,2.8.0)", - org.apache.sshd.client.auth.pubkey;version="[2.7.0,2.8.0)", - org.apache.sshd.client.channel;version="[2.7.0,2.8.0)", - org.apache.sshd.client.config.hosts;version="[2.7.0,2.8.0)", - org.apache.sshd.client.config.keys;version="[2.7.0,2.8.0)", - org.apache.sshd.client.future;version="[2.7.0,2.8.0)", - org.apache.sshd.client.keyverifier;version="[2.7.0,2.8.0)", - org.apache.sshd.client.session;version="[2.7.0,2.8.0)", - org.apache.sshd.client.session.forward;version="[2.7.0,2.8.0)", - org.apache.sshd.common;version="[2.7.0,2.8.0)", - org.apache.sshd.common.auth;version="[2.7.0,2.8.0)", - org.apache.sshd.common.channel;version="[2.7.0,2.8.0)", - org.apache.sshd.common.compression;version="[2.7.0,2.8.0)", - org.apache.sshd.common.config.keys;version="[2.7.0,2.8.0)", - org.apache.sshd.common.config.keys.loader;version="[2.7.0,2.8.0)", - org.apache.sshd.common.config.keys.loader.openssh.kdf;version="[2.7.0,2.8.0)", - org.apache.sshd.common.digest;version="[2.7.0,2.8.0)", - org.apache.sshd.common.forward;version="[2.7.0,2.8.0)", - org.apache.sshd.common.future;version="[2.7.0,2.8.0)", - org.apache.sshd.common.helpers;version="[2.7.0,2.8.0)", - org.apache.sshd.common.io;version="[2.7.0,2.8.0)", - org.apache.sshd.common.kex;version="[2.7.0,2.8.0)", - org.apache.sshd.common.kex.extension;version="[2.7.0,2.8.0)", - org.apache.sshd.common.kex.extension.parser;version="[2.7.0,2.8.0)", - org.apache.sshd.common.keyprovider;version="[2.7.0,2.8.0)", - org.apache.sshd.common.mac;version="[2.7.0,2.8.0)", - org.apache.sshd.common.random;version="[2.7.0,2.8.0)", - org.apache.sshd.common.session;version="[2.7.0,2.8.0)", - org.apache.sshd.common.session.helpers;version="[2.7.0,2.8.0)", - org.apache.sshd.common.signature;version="[2.7.0,2.8.0)", - org.apache.sshd.common.util;version="[2.7.0,2.8.0)", - org.apache.sshd.common.util.buffer;version="[2.7.0,2.8.0)", - org.apache.sshd.common.util.closeable;version="[2.7.0,2.8.0)", - org.apache.sshd.common.util.io;version="[2.7.0,2.8.0)", - org.apache.sshd.common.util.io.functors;version="[2.7.0,2.8.0)", - org.apache.sshd.common.util.io.resource;version="[2.7.0,2.8.0)", - org.apache.sshd.common.util.logging;version="[2.7.0,2.8.0)", - org.apache.sshd.common.util.net;version="[2.7.0,2.8.0)", - org.apache.sshd.common.util.security;version="[2.7.0,2.8.0)", - org.apache.sshd.core;version="[2.7.0,2.8.0)", - org.apache.sshd.server.auth;version="[2.7.0,2.8.0)", - org.apache.sshd.sftp;version="[2.7.0,2.8.0)", - org.apache.sshd.sftp.client;version="[2.7.0,2.8.0)", - org.apache.sshd.sftp.common;version="[2.7.0,2.8.0)", + org.apache.sshd.agent;version="[2.8.0,2.9.0)", + org.apache.sshd.client;version="[2.8.0,2.9.0)", + org.apache.sshd.client.auth;version="[2.8.0,2.9.0)", + org.apache.sshd.client.auth.keyboard;version="[2.8.0,2.9.0)", + org.apache.sshd.client.auth.password;version="[2.8.0,2.9.0)", + org.apache.sshd.client.auth.pubkey;version="[2.8.0,2.9.0)", + org.apache.sshd.client.channel;version="[2.8.0,2.9.0)", + org.apache.sshd.client.config.hosts;version="[2.8.0,2.9.0)", + org.apache.sshd.client.config.keys;version="[2.8.0,2.9.0)", + org.apache.sshd.client.future;version="[2.8.0,2.9.0)", + org.apache.sshd.client.keyverifier;version="[2.8.0,2.9.0)", + org.apache.sshd.client.session;version="[2.8.0,2.9.0)", + org.apache.sshd.client.session.forward;version="[2.8.0,2.9.0)", + org.apache.sshd.common;version="[2.8.0,2.9.0)", + org.apache.sshd.common.auth;version="[2.8.0,2.9.0)", + org.apache.sshd.common.channel;version="[2.8.0,2.9.0)", + org.apache.sshd.common.compression;version="[2.8.0,2.9.0)", + org.apache.sshd.common.config.keys;version="[2.8.0,2.9.0)", + org.apache.sshd.common.config.keys.loader;version="[2.8.0,2.9.0)", + org.apache.sshd.common.config.keys.loader.openssh.kdf;version="[2.8.0,2.9.0)", + org.apache.sshd.common.config.keys.u2f;version="[2.8.0,2.9.0)", + org.apache.sshd.common.digest;version="[2.8.0,2.9.0)", + org.apache.sshd.common.forward;version="[2.8.0,2.9.0)", + org.apache.sshd.common.future;version="[2.8.0,2.9.0)", + org.apache.sshd.common.helpers;version="[2.8.0,2.9.0)", + org.apache.sshd.common.io;version="[2.8.0,2.9.0)", + org.apache.sshd.common.kex;version="[2.8.0,2.9.0)", + org.apache.sshd.common.kex.extension;version="[2.8.0,2.9.0)", + org.apache.sshd.common.kex.extension.parser;version="[2.8.0,2.9.0)", + org.apache.sshd.common.keyprovider;version="[2.8.0,2.9.0)", + org.apache.sshd.common.mac;version="[2.8.0,2.9.0)", + org.apache.sshd.common.random;version="[2.8.0,2.9.0)", + org.apache.sshd.common.session;version="[2.8.0,2.9.0)", + org.apache.sshd.common.session.helpers;version="[2.8.0,2.9.0)", + org.apache.sshd.common.signature;version="[2.8.0,2.9.0)", + org.apache.sshd.common.util;version="[2.8.0,2.9.0)", + org.apache.sshd.common.util.buffer;version="[2.8.0,2.9.0)", + org.apache.sshd.common.util.buffer.keys;version="[2.8.0,2.9.0)", + org.apache.sshd.common.util.closeable;version="[2.8.0,2.9.0)", + org.apache.sshd.common.util.io;version="[2.8.0,2.9.0)", + org.apache.sshd.common.util.io.der;version="[2.8.0,2.9.0)", + org.apache.sshd.common.util.io.functors;version="[2.8.0,2.9.0)", + org.apache.sshd.common.util.io.resource;version="[2.8.0,2.9.0)", + org.apache.sshd.common.util.logging;version="[2.8.0,2.9.0)", + org.apache.sshd.common.util.net;version="[2.8.0,2.9.0)", + org.apache.sshd.common.util.security;version="[2.8.0,2.9.0)", + org.apache.sshd.core;version="[2.8.0,2.9.0)", + org.apache.sshd.server.auth;version="[2.8.0,2.9.0)", + org.apache.sshd.sftp;version="[2.8.0,2.9.0)", + org.apache.sshd.sftp.client;version="[2.8.0,2.9.0)", + org.apache.sshd.sftp.common;version="[2.8.0,2.9.0)", org.eclipse.jgit.annotations;version="[7.0.0,7.1.0)", org.eclipse.jgit.errors;version="[7.0.0,7.1.0)", org.eclipse.jgit.fnmatch;version="[7.0.0,7.1.0)", diff --git a/org.eclipse.jgit.ssh.apache/README.md b/org.eclipse.jgit.ssh.apache/README.md index cba87ac9cc..f06b2f6071 100644 --- a/org.eclipse.jgit.ssh.apache/README.md +++ b/org.eclipse.jgit.ssh.apache/README.md @@ -43,6 +43,53 @@ FetchCommand fetch = git.fetch() .call(); ``` +## Support for SSH agents + +There exist two IETF draft RFCs for communication with an SSH agent: + +* an older [SSH1 protocol](https://tools.ietf.org/html/draft-ietf-secsh-agent-02) that can deal only with DSA and RSA keys, and +* a newer [SSH2 protocol](https://tools.ietf.org/html/draft-miller-ssh-agent-04) (from OpenSSH). + +JGit only supports the newer OpenSSH protocol. + +Communication with an SSH agent can occur over any transport protocol, and different +SSH agents may use different transports for local communication. JGit provides some +transports via the [org.eclipse.jgit.ssh.apache.agent](../org.eclipse.jgit.ssh.apache.agent/README.md) +fragment, which are discovered from `org.eclipse.jgit.ssh.apache` also via the `ServiceLoader` mechanism; +the SPI (service provider interface) is `org.eclipse.jgit.transport.sshd.agent.ConnectorFactory`. + +If such a `ConnectorFactory` implementation is found, JGit may use an SSH agent. If none +is available, JGit cannot communicate with an SSH agent, and will not attempt to use one. + +### SSH configurations for SSH agents + +There are several SSH properties that can be used in the `~/.ssh/config` file to configure +the use of an SSH agent. For the details, see the [OpenBSD ssh-config documentation](https://man.openbsd.org/ssh_config.5). + +* **AddKeysToAgent** can be set to `no`, `yes`, or `ask`. If set to `yes`, keys will be added + to the agent if they're not yet in the agent. If set to `ask`, the user will be prompted + before doing so, and can opt out of adding the key. JGit also supports the additional + settings `confirm` and key lifetimes. +* **IdentityAgent** can be set to choose which SSH agent to use, if there are several running. + It can also be set to `none` to explicitly switch off using an SSH agent at all. +* **IdentitiesOnly** if set to `yes` and an SSH agent is used, only keys from the agent that are + also listed in an `IdentityFile` property will be considered. (It'll also switch off trying + default key names, such as `~/.ssh/id_rsa` or `~/.ssh/id_ed25519`; only keys listed explicitly + will be used.) + +### Limitations + +As mentioned above JGit only implements the newer OpenSSH protocol. OpenSSH fully implements this, +but some other SSH agents only offer partial implementations. In particular on Windows, neither +Pageant nor Win32-OpenSSH implement the `confirm` or lifetime constraints for `AddKeysToAgent`. With +such SSH agents, these settings should not be used in `~/.ssh/config`. GPG's gpg-agent can be run +with option `enable_putty_support` and can then be used as a Pageant replacement. gpg-agent appears +to support these key constraints. + +OpenSSH does not implement ed448 keys, and neither does Apache MINA sshd, and hence such keys are +not supported in JGit if its built-in SSH implementation is used. ed448 or other unsupported keys +provided by an SSH agent are ignored. + ## Using a different SSH implementation To use a different SSH implementation: diff --git a/org.eclipse.jgit.ssh.apache/pom.xml b/org.eclipse.jgit.ssh.apache/pom.xml index 024dae8524..3ea8b63ab7 100644 --- a/org.eclipse.jgit.ssh.apache/pom.xml +++ b/org.eclipse.jgit.ssh.apache/pom.xml @@ -154,6 +154,9 @@ <includes> <include>org.eclipse.jgit.*</include> </includes> + <excludes> + <exclude>*.internal.*</exclude> + </excludes> <accessModifier>public</accessModifier> <breakBuildOnModifications>false</breakBuildOnModifications> <breakBuildOnBinaryIncompatibleModifications>false</breakBuildOnBinaryIncompatibleModifications> @@ -207,6 +210,9 @@ <includes> <include>org.eclipse.jgit.*</include> </includes> + <excludes> + <exclude>*.internal.*</exclude> + </excludes> <accessModifier>public</accessModifier> <breakBuildOnModifications>false</breakBuildOnModifications> <breakBuildOnBinaryIncompatibleModifications>false</breakBuildOnBinaryIncompatibleModifications> diff --git a/org.eclipse.jgit.ssh.apache/resources/org/eclipse/jgit/internal/transport/sshd/SshdText.properties b/org.eclipse.jgit.ssh.apache/resources/org/eclipse/jgit/internal/transport/sshd/SshdText.properties index 2bba736aad..c676221800 100644 --- a/org.eclipse.jgit.ssh.apache/resources/org/eclipse/jgit/internal/transport/sshd/SshdText.properties +++ b/org.eclipse.jgit.ssh.apache/resources/org/eclipse/jgit/internal/transport/sshd/SshdText.properties @@ -1,5 +1,23 @@ authenticationCanceled=SSH authentication canceled: no password given authenticationOnClosedSession=Authentication canceled: session is already closing or closed +authGssApiAttempt={0}: trying mechanism OID {1} +authGssApiExhausted={0}: no more mechanisms to try +authGssApiFailure={0}: server refused authentication; mechanism {1} +authGssApiNotTried={0}: not tried +authGssApiPartialSuccess={0}: partial success with mechanism OID {1}, continue with authentication methods {2} +authPasswordAttempt={0}: attempt {1} +authPasswordChangeAttempt={0}: attempt {1} with password change +authPasswordExhausted={0}: no more attempts +authPasswordFailure={0}: server refused (wrong password) +authPasswordNotTried={0}: not tried +authPasswordPartialSuccess={0}: partial success, continue with authentication methods {1} +authPubkeyAttempt={0}: trying {1} key {2} with signature type {3} +authPubkeyAttemptAgent={0}: trying {1} key {2} from SSH agent with signature type {3} +authPubkeyExhausted={0}: no more keys to try +authPubkeyFailure={0}: server refused {1} key {2} +authPubkeyNoKeys={0}: no keys to try +authPubkeyPartialSuccess={0}: partial success for {1} key {2}, continue with authentication methods {3} +cannotReadPublicKey=Cannot read public key from file {0} closeListenerFailed=Ssh session close listener failed configInvalidPath=Invalid path in ssh config key {0}: {1} configInvalidPattern=Invalid pattern in ssh config key {0}: {1} @@ -77,6 +95,8 @@ proxySocksPasswordTooLong=Password for proxy {0} must be at most 255 bytes long, proxySocksUnexpectedMessage=Unexpected message received from SOCKS5 proxy {0}; client state {1}: {2} proxySocksUnexpectedVersion=Expected SOCKS version 5, got {0} proxySocksUsernameTooLong=User name for proxy {0} must be at most 255 bytes long, is {1} bytes: {2} +pubkeyAuthAddKeyToAgentError=Could not add {0} key with fingerprint {1} to the SSH agent +pubkeyAuthAddKeyToAgentQuestion=Add the {0} key with fingerprint {1} to the SSH agent? pubkeyAuthWrongCommand=Public key authentication received unknown SSH command {0} from {1} ({2}) pubkeyAuthWrongKey=Public key authentication received wrong key; sent {0}, got back {1} from {2} ({3}) pubkeyAuthWrongSignatureAlgorithm=Public key authentication requested signature type {0} but got back {1} from {2} ({3}) @@ -85,9 +105,13 @@ serverIdTooLong=Server identification is longer than 255 characters (including l serverIdWithNul=Server identification contains a NUL character: {0} sessionCloseFailed=Closing the session failed sessionWithoutUsername=SSH session created without user name; cannot authenticate +sshAgentEdDSAFormatError=Cannot add ed25519 key to the SSH agent because it is encoded as {0} instead of PKCS#8 +sshAgentPayloadLengthError=Expected {0,choice,0#no bytes|1#one byte|1<{0} bytes} but got {1} sshAgentReplyLengthError=Invalid SSH agent reply message length {0} after command {1} sshAgentReplyUnexpected=Unexpected reply from ssh-agent: {0} sshAgentShortReadBuffer=Short read from SSH agent +sshAgentUnknownKey=SSH agent delivered a key that cannot be handled +sshAgentWrongKeyLength=SSH agent delivered illogical key length {0} at offset {1} in buffer of length {2} sshAgentWrongNumberOfKeys=Invalid number of SSH agent keys: {0} sshClosingDown=Apache MINA sshd session factory is closing down; cannot create new ssh sessions on this factory sshCommandTimeout={0} timed out after {1} seconds while opening the channel diff --git a/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/AuthenticationLogger.java b/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/AuthenticationLogger.java new file mode 100644 index 0000000000..add79b35c9 --- /dev/null +++ b/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/AuthenticationLogger.java @@ -0,0 +1,238 @@ +/* + * Copyright (C) 2022 Thomas Wolf <thomas.wolf@paranor.ch> and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Distribution License v. 1.0 which is available at + * https://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: BSD-3-Clause + */ +package org.eclipse.jgit.internal.transport.sshd; + +import static org.eclipse.jgit.internal.transport.sshd.CachingKeyPairProvider.getKeyId; + +import java.security.KeyPair; +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.apache.sshd.client.auth.password.PasswordAuthenticationReporter; +import org.apache.sshd.client.auth.password.UserAuthPassword; +import org.apache.sshd.client.auth.pubkey.PublicKeyAuthenticationReporter; +import org.apache.sshd.client.auth.pubkey.UserAuthPublicKey; +import org.apache.sshd.client.session.ClientSession; +import org.apache.sshd.common.config.keys.KeyUtils; + +/** + * Provides a log of authentication attempts for a {@link ClientSession}. + */ +public class AuthenticationLogger { + + private final List<String> messages = new ArrayList<>(); + + // We're interested in this log only in the failure case, so we don't need + // to log authentication success. + + private final PublicKeyAuthenticationReporter pubkeyLogger = new PublicKeyAuthenticationReporter() { + + private boolean hasAttempts; + + @Override + public void signalAuthenticationAttempt(ClientSession session, + String service, KeyPair identity, String signature) + throws Exception { + hasAttempts = true; + String message; + if (identity.getPrivate() == null) { + // SSH agent key + message = MessageFormat.format( + SshdText.get().authPubkeyAttemptAgent, + UserAuthPublicKey.NAME, KeyUtils.getKeyType(identity), + getKeyId(session, identity), signature); + } else { + message = MessageFormat.format( + SshdText.get().authPubkeyAttempt, + UserAuthPublicKey.NAME, KeyUtils.getKeyType(identity), + getKeyId(session, identity), signature); + } + messages.add(message); + } + + @Override + public void signalAuthenticationExhausted(ClientSession session, + String service) throws Exception { + String message; + if (hasAttempts) { + message = MessageFormat.format( + SshdText.get().authPubkeyExhausted, + UserAuthPublicKey.NAME); + } else { + message = MessageFormat.format(SshdText.get().authPubkeyNoKeys, + UserAuthPublicKey.NAME); + } + messages.add(message); + hasAttempts = false; + } + + @Override + public void signalAuthenticationFailure(ClientSession session, + String service, KeyPair identity, boolean partial, + List<String> serverMethods) throws Exception { + String message; + if (partial) { + message = MessageFormat.format( + SshdText.get().authPubkeyPartialSuccess, + UserAuthPublicKey.NAME, KeyUtils.getKeyType(identity), + getKeyId(session, identity), serverMethods); + } else { + message = MessageFormat.format( + SshdText.get().authPubkeyFailure, + UserAuthPublicKey.NAME, KeyUtils.getKeyType(identity), + getKeyId(session, identity)); + } + messages.add(message); + } + }; + + private final PasswordAuthenticationReporter passwordLogger = new PasswordAuthenticationReporter() { + + private int attempts; + + @Override + public void signalAuthenticationAttempt(ClientSession session, + String service, String oldPassword, boolean modified, + String newPassword) throws Exception { + attempts++; + String message; + if (modified) { + message = MessageFormat.format( + SshdText.get().authPasswordChangeAttempt, + UserAuthPassword.NAME, Integer.valueOf(attempts)); + } else { + message = MessageFormat.format( + SshdText.get().authPasswordAttempt, + UserAuthPassword.NAME, Integer.valueOf(attempts)); + } + messages.add(message); + } + + @Override + public void signalAuthenticationExhausted(ClientSession session, + String service) throws Exception { + String message; + if (attempts > 0) { + message = MessageFormat.format( + SshdText.get().authPasswordExhausted, + UserAuthPassword.NAME); + } else { + message = MessageFormat.format( + SshdText.get().authPasswordNotTried, + UserAuthPassword.NAME); + } + messages.add(message); + attempts = 0; + } + + @Override + public void signalAuthenticationFailure(ClientSession session, + String service, String password, boolean partial, + List<String> serverMethods) throws Exception { + String message; + if (partial) { + message = MessageFormat.format( + SshdText.get().authPasswordPartialSuccess, + UserAuthPassword.NAME, serverMethods); + } else { + message = MessageFormat.format( + SshdText.get().authPasswordFailure, + UserAuthPassword.NAME); + } + messages.add(message); + } + }; + + private final GssApiWithMicAuthenticationReporter gssLogger = new GssApiWithMicAuthenticationReporter() { + + private boolean hasAttempts; + + @Override + public void signalAuthenticationAttempt(ClientSession session, + String service, String mechanism) { + hasAttempts = true; + String message = MessageFormat.format( + SshdText.get().authGssApiAttempt, + GssApiWithMicAuthFactory.NAME, mechanism); + messages.add(message); + } + + @Override + public void signalAuthenticationExhausted(ClientSession session, + String service) { + String message; + if (hasAttempts) { + message = MessageFormat.format( + SshdText.get().authGssApiExhausted, + GssApiWithMicAuthFactory.NAME); + } else { + message = MessageFormat.format( + SshdText.get().authGssApiNotTried, + GssApiWithMicAuthFactory.NAME); + } + messages.add(message); + hasAttempts = false; + } + + @Override + public void signalAuthenticationFailure(ClientSession session, + String service, String mechanism, boolean partial, + List<String> serverMethods) { + String message; + if (partial) { + message = MessageFormat.format( + SshdText.get().authGssApiPartialSuccess, + GssApiWithMicAuthFactory.NAME, mechanism, + serverMethods); + } else { + message = MessageFormat.format( + SshdText.get().authGssApiFailure, + GssApiWithMicAuthFactory.NAME, mechanism); + } + messages.add(message); + } + }; + + /** + * Creates a new {@link AuthenticationLogger} and configures the + * {@link ClientSession} to report authentication attempts through this + * instance. + * + * @param session + * to configure + */ + public AuthenticationLogger(ClientSession session) { + session.setPublicKeyAuthenticationReporter(pubkeyLogger); + session.setPasswordAuthenticationReporter(passwordLogger); + session.setAttribute( + GssApiWithMicAuthenticationReporter.GSS_AUTHENTICATION_REPORTER, + gssLogger); + // TODO: keyboard-interactive? sshd 2.8.0 has no callback + // interface for it. + } + + /** + * Retrieves the log messages for the authentication attempts. + * + * @return the messages as an unmodifiable list + */ + public List<String> getLog() { + return Collections.unmodifiableList(messages); + } + + /** + * Drops all previously recorded log messages. + */ + public void clear() { + messages.clear(); + } +} diff --git a/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/CachingKeyPairProvider.java b/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/CachingKeyPairProvider.java index 79b3637caa..cbd6a64140 100644 --- a/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/CachingKeyPairProvider.java +++ b/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/CachingKeyPairProvider.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018, Thomas Wolf <thomas.wolf@paranor.ch> and others + * Copyright (C) 2018, 2022 Thomas Wolf <thomas.wolf@paranor.ch> and others * * This program and the accompanying materials are made available under the * terms of the Eclipse Distribution License v. 1.0 which is available at @@ -11,6 +11,7 @@ package org.eclipse.jgit.internal.transport.sshd; import static java.text.MessageFormat.format; +import java.io.File; import java.io.IOException; import java.io.InputStream; import java.nio.file.Files; @@ -19,18 +20,24 @@ import java.security.GeneralSecurityException; import java.security.InvalidKeyException; import java.security.KeyPair; import java.security.PrivateKey; +import java.security.PublicKey; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.HashMap; import java.util.Iterator; import java.util.List; +import java.util.Map; import java.util.NoSuchElementException; import java.util.concurrent.CancellationException; import javax.security.auth.DestroyFailedException; +import org.apache.sshd.common.AttributeRepository.AttributeKey; +import org.apache.sshd.client.session.ClientSession; import org.apache.sshd.common.NamedResource; import org.apache.sshd.common.config.keys.FilePasswordProvider; +import org.apache.sshd.common.config.keys.KeyUtils; import org.apache.sshd.common.keyprovider.FileKeyPairProvider; import org.apache.sshd.common.session.SessionContext; import org.apache.sshd.common.util.io.resource.IoResource; @@ -43,6 +50,14 @@ import org.eclipse.jgit.transport.sshd.KeyCache; public class CachingKeyPairProvider extends FileKeyPairProvider implements Iterable<KeyPair> { + /** + * An attribute set on the {@link SessionContext} recording loaded keys by + * fingerprint. This enables us to provide nicer output by showing key + * paths, if possible. Users can identify key identities used easier by + * filename than by fingerprint. + */ + public static final AttributeKey<Map<String, Path>> KEY_PATHS_BY_FINGERPRINT = new AttributeKey<>(); + private final KeyCache cache; /** @@ -78,6 +93,33 @@ public class CachingKeyPairProvider extends FileKeyPairProvider return () -> iterator(session); } + static String getKeyId(ClientSession session, KeyPair identity) { + String fingerprint = KeyUtils.getFingerPrint(identity.getPublic()); + Map<String, Path> registered = session + .getAttribute(KEY_PATHS_BY_FINGERPRINT); + if (registered != null) { + Path path = registered.get(fingerprint); + if (path != null) { + Path home = session + .resolveAttribute(JGitSshClient.HOME_DIRECTORY); + if (home != null && path.startsWith(home)) { + try { + path = home.relativize(path); + String pathString = path.toString(); + if (!pathString.isEmpty()) { + return "~" + File.separator + pathString; //$NON-NLS-1$ + } + } catch (IllegalArgumentException e) { + // Cannot be relativized. Ignore, and work with the + // original path + } + } + return path.toString(); + } + } + return fingerprint; + } + private KeyPair loadKey(SessionContext session, Path path) throws IOException, GeneralSecurityException { if (!Files.exists(path)) { @@ -123,13 +165,23 @@ public class CachingKeyPairProvider extends FileKeyPairProvider SshdText.get().identityFileUnsupportedFormat, path)); } KeyPair result = keys.next(); + PublicKey pk = result.getPublic(); + if (pk != null) { + Map<String, Path> registered = session + .getAttribute(KEY_PATHS_BY_FINGERPRINT); + if (registered == null) { + registered = new HashMap<>(); + session.setAttribute(KEY_PATHS_BY_FINGERPRINT, registered); + } + registered.put(KeyUtils.getFingerPrint(pk), path); + } if (keys.hasNext()) { log.warn(format(SshdText.get().identityFileMultipleKeys, path)); keys.forEachRemaining(k -> { - PrivateKey pk = k.getPrivate(); - if (pk != null) { + PrivateKey priv = k.getPrivate(); + if (priv != null) { try { - pk.destroy(); + priv.destroy(); } catch (DestroyFailedException e) { // Ignore } diff --git a/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/GssApiWithMicAuthentication.java b/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/GssApiWithMicAuthentication.java index c3cac0c1df..df01db316b 100644 --- a/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/GssApiWithMicAuthentication.java +++ b/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/GssApiWithMicAuthentication.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018, Thomas Wolf <thomas.wolf@paranor.ch> and others + * Copyright (C) 2018, 2022 Thomas Wolf <thomas.wolf@paranor.ch> and others * * This program and the accompanying materials are made available under the * terms of the Eclipse Distribution License v. 1.0 which is available at @@ -18,6 +18,7 @@ import java.net.SocketAddress; import java.net.UnknownHostException; import java.util.Collection; import java.util.Iterator; +import java.util.List; import org.apache.sshd.client.auth.AbstractUserAuth; import org.apache.sshd.client.session.ClientSession; @@ -71,7 +72,10 @@ public class GssApiWithMicAuthentication extends AbstractUserAuth { if (context != null) { close(false); } + GssApiWithMicAuthenticationReporter reporter = session.getAttribute( + GssApiWithMicAuthenticationReporter.GSS_AUTHENTICATION_REPORTER); if (!nextMechanism.hasNext()) { + reporter.signalAuthenticationExhausted(session, service); return false; } state = ProtocolState.STARTED; @@ -79,6 +83,7 @@ public class GssApiWithMicAuthentication extends AbstractUserAuth { // RFC 4462 states that SPNEGO must not be used with ssh while (GssApiMechanisms.SPNEGO.equals(currentMechanism)) { if (!nextMechanism.hasNext()) { + reporter.signalAuthenticationExhausted(session, service); return false; } currentMechanism = nextMechanism.next(); @@ -102,6 +107,10 @@ public class GssApiWithMicAuthentication extends AbstractUserAuth { state = ProtocolState.FAILED; return false; } + if (reporter != null) { + reporter.signalAuthenticationAttempt(session, service, + currentMechanism.toString()); + } Buffer buffer = session .createBuffer(SshConstants.SSH_MSG_USERAUTH_REQUEST); buffer.putString(session.getUsername()); @@ -246,4 +255,26 @@ public class GssApiWithMicAuthentication extends AbstractUserAuth { return false; } + @Override + public void signalAuthMethodSuccess(ClientSession session, String service, + Buffer buffer) throws Exception { + GssApiWithMicAuthenticationReporter reporter = session.getAttribute( + GssApiWithMicAuthenticationReporter.GSS_AUTHENTICATION_REPORTER); + if (reporter != null) { + reporter.signalAuthenticationSuccess(session, service, + currentMechanism.toString()); + } + } + + @Override + public void signalAuthMethodFailure(ClientSession session, String service, + boolean partial, List<String> serverMethods, Buffer buffer) + throws Exception { + GssApiWithMicAuthenticationReporter reporter = session.getAttribute( + GssApiWithMicAuthenticationReporter.GSS_AUTHENTICATION_REPORTER); + if (reporter != null) { + reporter.signalAuthenticationFailure(session, service, + currentMechanism.toString(), partial, serverMethods); + } + } } diff --git a/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/GssApiWithMicAuthenticationReporter.java b/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/GssApiWithMicAuthenticationReporter.java new file mode 100644 index 0000000000..201a131650 --- /dev/null +++ b/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/GssApiWithMicAuthenticationReporter.java @@ -0,0 +1,93 @@ +/* + * Copyright (C) 2022 Thomas Wolf <thomas.wolf@paranor.ch> and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Distribution License v. 1.0 which is available at + * https://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: BSD-3-Clause + */ +package org.eclipse.jgit.internal.transport.sshd; + +import java.util.List; + +import org.apache.sshd.client.session.ClientSession; +import org.apache.sshd.common.AttributeRepository.AttributeKey; + +/** + * Callback interface for recording authentication state in + * {@link GssApiWithMicAuthentication}. + */ +public interface GssApiWithMicAuthenticationReporter { + + /** + * An {@link AttributeKey}Â for a {@link ClientSession} holding the + * {@link GssApiWithMicAuthenticationReporter}. + */ + static final AttributeKey<GssApiWithMicAuthenticationReporter> GSS_AUTHENTICATION_REPORTER = new AttributeKey<>(); + + /** + * Called when a new authentication attempt is made. + * + * @param session + * the {@link ClientSession} + * @param service + * the name of the requesting SSH service name + * @param mechanism + * the OID of the mechanism used + */ + default void signalAuthenticationAttempt(ClientSession session, + String service, String mechanism) { + // nothing + } + + /** + * Called when there are no more mechanisms to try. + * + * @param session + * the {@link ClientSession} + * @param service + * the name of the requesting SSH service name + */ + default void signalAuthenticationExhausted(ClientSession session, + String service) { + // nothing + } + + /** + * Called when authentication was succeessful. + * + * @param session + * the {@link ClientSession} + * @param service + * the name of the requesting SSH service name + * @param mechanism + * the OID of the mechanism used + */ + default void signalAuthenticationSuccess(ClientSession session, + String service, String mechanism) { + // nothing + } + + /** + * Called when the authentication was not successful. + * + * @param session + * the {@link ClientSession} + * @param service + * the name of the requesting SSH service name + * @param mechanism + * the OID of the mechanism used + * @param partial + * {@code true} if authentication was partially successful, + * meaning one continues with additional authentication methods + * given by {@code serverMethods} + * @param serverMethods + * the {@link List} of authentication methods that can continue + */ + default void signalAuthenticationFailure(ClientSession session, + String service, String mechanism, boolean partial, + List<String> serverMethods) { + // nothing + } +} diff --git a/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/JGitClientSession.java b/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/JGitClientSession.java index e2dbb4c466..5100bc9e54 100644 --- a/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/JGitClientSession.java +++ b/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/JGitClientSession.java @@ -42,7 +42,6 @@ import org.apache.sshd.common.io.IoSession; import org.apache.sshd.common.io.IoWriteFuture; import org.apache.sshd.common.kex.BuiltinDHFactories; import org.apache.sshd.common.kex.DHFactory; -import org.apache.sshd.common.kex.KexProposalOption; import org.apache.sshd.common.kex.KeyExchangeFactory; import org.apache.sshd.common.kex.extension.KexExtensionHandler; import org.apache.sshd.common.kex.extension.KexExtensionHandler.AvailabilityPhase; @@ -199,24 +198,6 @@ public class JGitClientSession extends ClientSessionImpl { } } - @Override - protected Map<KexProposalOption, String> setNegotiationResult( - Map<KexProposalOption, String> guess) { - Map<KexProposalOption, String> result = super.setNegotiationResult( - guess); - // This should be doable with a SessionListener, too, but I don't see - // how to add a listener in time to catch the negotiation end for sure - // given that the super-constructor already starts KEX. - // - // TODO: This override can be removed once we use sshd 2.8.0. - if (log.isDebugEnabled()) { - result.forEach((option, value) -> log.debug( - "setNegotiationResult({}) Kex: {} = {}", this, //$NON-NLS-1$ - option.getDescription(), value)); - } - return result; - } - Set<String> getAllAvailableSignatureAlgorithms() { Set<String> allAvailable = new HashSet<>(); BuiltinSignatures.VALUES.forEach(s -> allAvailable.add(s.getName())); diff --git a/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/JGitPasswordAuthentication.java b/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/JGitPasswordAuthentication.java index ff8caaacc0..33c3c608f6 100644 --- a/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/JGitPasswordAuthentication.java +++ b/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/JGitPasswordAuthentication.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018, Thomas Wolf <thomas.wolf@paranor.ch> and others + * Copyright (C) 2018, 2022 Thomas Wolf <thomas.wolf@paranor.ch> and others * * This program and the accompanying materials are made available under the * terms of the Eclipse Distribution License v. 1.0 which is available at @@ -11,13 +11,11 @@ package org.eclipse.jgit.internal.transport.sshd; import static org.apache.sshd.core.CoreModuleProperties.PASSWORD_PROMPTS; -import org.apache.sshd.client.auth.keyboard.UserInteraction; import org.apache.sshd.client.auth.password.UserAuthPassword; import org.apache.sshd.client.session.ClientSession; /** - * A password authentication handler that uses the {@link JGitUserInteraction} - * to ask the user for the password. It also respects the + * A password authentication handler that respects the * {@code NumberOfPasswordPrompts} ssh config. */ public class JGitPasswordAuthentication extends UserAuthPassword { @@ -35,30 +33,11 @@ public class JGitPasswordAuthentication extends UserAuthPassword { } @Override - protected boolean sendAuthDataRequest(ClientSession session, String service) - throws Exception { + protected String resolveAttemptedPassword(ClientSession session, + String service) throws Exception { if (++attempts > maxAttempts) { - return false; + return null; } - UserInteraction interaction = session.getUserInteraction(); - if (!interaction.isInteractionAllowed(session)) { - return false; - } - String password = getPassword(session, interaction); - if (password == null) { - throw new AuthenticationCanceledException(); - } - // sendPassword takes a buffer as first argument, but actually doesn't - // use it and creates its own buffer... - sendPassword(null, session, password, password); - return true; - } - - private String getPassword(ClientSession session, - UserInteraction interaction) { - String[] results = interaction.interactive(session, null, null, "", //$NON-NLS-1$ - new String[] { SshdText.get().passwordPrompt }, - new boolean[] { false }); - return (results == null || results.length == 0) ? null : results[0]; + return super.resolveAttemptedPassword(session, service); } } diff --git a/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/JGitPublicKeyAuthentication.java b/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/JGitPublicKeyAuthentication.java index c082a9a963..e1036c6283 100644 --- a/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/JGitPublicKeyAuthentication.java +++ b/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/JGitPublicKeyAuthentication.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018, 2021 Thomas Wolf <thomas.wolf@paranor.ch> and others + * Copyright (C) 2018, 2022 Thomas Wolf <thomas.wolf@paranor.ch> and others * * This program and the accompanying materials are made available under the * terms of the Eclipse Distribution License v. 1.0 which is available at @@ -12,25 +12,68 @@ package org.eclipse.jgit.internal.transport.sshd; import static java.text.MessageFormat.format; import static org.eclipse.jgit.transport.SshConstants.PUBKEY_ACCEPTED_ALGORITHMS; +import java.io.IOException; +import java.net.URISyntaxException; +import java.nio.file.Files; +import java.nio.file.InvalidPathException; +import java.nio.file.LinkOption; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.security.GeneralSecurityException; +import java.security.KeyPair; +import java.security.PublicKey; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; import java.util.Iterator; import java.util.List; +import java.util.Map; import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.stream.Collectors; +import org.apache.sshd.agent.SshAgent; +import org.apache.sshd.agent.SshAgentFactory; +import org.apache.sshd.agent.SshAgentKeyConstraint; import org.apache.sshd.client.auth.pubkey.KeyAgentIdentity; import org.apache.sshd.client.auth.pubkey.PublicKeyIdentity; import org.apache.sshd.client.auth.pubkey.UserAuthPublicKey; +import org.apache.sshd.client.auth.pubkey.UserAuthPublicKeyIterator; import org.apache.sshd.client.config.hosts.HostConfigEntry; import org.apache.sshd.client.session.ClientSession; +import org.apache.sshd.common.FactoryManager; import org.apache.sshd.common.NamedFactory; +import org.apache.sshd.common.config.keys.AuthorizedKeyEntry; +import org.apache.sshd.common.config.keys.KeyUtils; +import org.apache.sshd.common.config.keys.PublicKeyEntryResolver; +import org.apache.sshd.common.config.keys.u2f.SecurityKeyPublicKey; import org.apache.sshd.common.signature.Signature; +import org.apache.sshd.common.signature.SignatureFactoriesManager; +import org.eclipse.jgit.internal.transport.ssh.OpenSshConfigFile; +import org.eclipse.jgit.transport.CredentialItem; +import org.eclipse.jgit.transport.CredentialsProvider; +import org.eclipse.jgit.transport.SshConstants; +import org.eclipse.jgit.transport.URIish; import org.eclipse.jgit.util.StringUtils; /** * Custom {@link UserAuthPublicKey} implementation for handling SSH config - * PubkeyAcceptedAlgorithms. + * PubkeyAcceptedAlgorithms and interaction with the SSH agent. */ public class JGitPublicKeyAuthentication extends UserAuthPublicKey { + private SshAgent agent; + + private HostConfigEntry hostConfig; + + private boolean addKeysToAgent; + + private boolean askBeforeAdding; + + private String skProvider; + + private SshAgentKeyConstraint[] constraints; + JGitPublicKeyAuthentication(List<NamedFactory<Signature>> factories) { super(factories); } @@ -43,7 +86,7 @@ public class JGitPublicKeyAuthentication extends UserAuthPublicKey { + rawSession.getClass().getCanonicalName()); } JGitClientSession session = (JGitClientSession) rawSession; - HostConfigEntry hostConfig = session.getHostConfigEntry(); + hostConfig = session.getHostConfigEntry(); // Set signature algorithms for public key authentication String pubkeyAlgos = hostConfig.getProperty(PUBKEY_ACCEPTED_ALGORITHMS); if (!StringUtils.isEmptyOrNull(pubkeyAlgos)) { @@ -56,54 +99,304 @@ public class JGitPublicKeyAuthentication extends UserAuthPublicKey { log.debug(PUBKEY_ACCEPTED_ALGORITHMS + ' ' + signatures); } setSignatureFactoriesNames(signatures); - } else { - log.warn(format(SshdText.get().configNoKnownAlgorithms, - PUBKEY_ACCEPTED_ALGORITHMS, pubkeyAlgos)); + super.init(session, service); + return; } + log.warn(format(SshdText.get().configNoKnownAlgorithms, + PUBKEY_ACCEPTED_ALGORITHMS, pubkeyAlgos)); + } + // TODO: remove this once we're on an sshd version that has SSHD-1272 + // fixed + List<NamedFactory<Signature>> localFactories = getSignatureFactories(); + if (localFactories == null || localFactories.isEmpty()) { + setSignatureFactoriesNames(session.getSignatureFactoriesNames()); } - // If we don't set signature factories here, the default ones from the - // session will be used. super.init(session, service); - // In sshd 2.7.0, we end up now with a key iterator that uses keys - // provided by an ssh-agent even if IdentitiesOnly is true. So if - // needed, filter out any KeyAgentIdentity. - if (hostConfig.isIdentitiesOnly()) { - Iterator<PublicKeyIdentity> original = keys; - // The original iterator will already have gotten the identities - // from the agent. Unfortunately there's nothing we can do about - // that; it'll have to be fixed upstream. (As will, ultimately, - // respecting isIdentitiesOnly().) At least we can simply not - // use the keys the agent provided. - // - // See https://issues.apache.org/jira/browse/SSHD-1218 - keys = new Iterator<>() { - - private PublicKeyIdentity value; + } + + @Override + protected Iterator<PublicKeyIdentity> createPublicKeyIterator( + ClientSession session, SignatureFactoriesManager manager) + throws Exception { + agent = getAgent(session); + if (agent != null) { + parseAddKeys(hostConfig); + if (addKeysToAgent) { + skProvider = hostConfig.getProperty(SshConstants.SECURITY_KEY_PROVIDER); + } + } + return new KeyIterator(session, manager); + } + + @Override + protected PublicKeyIdentity resolveAttemptedPublicKeyIdentity( + ClientSession session, String service) throws Exception { + PublicKeyIdentity result = getNextKey(session, service); + // This fixes SSHD-1231. Can be removed once we're using Apache MINA + // sshd > 2.8.0. + // + // See https://issues.apache.org/jira/browse/SSHD-1231 + currentAlgorithms.clear(); + return result; + } + + private PublicKeyIdentity getNextKey(ClientSession session, String service) + throws Exception { + PublicKeyIdentity id = super.resolveAttemptedPublicKeyIdentity(session, + service); + if (addKeysToAgent && id != null && !(id instanceof KeyAgentIdentity)) { + KeyPair key = id.getKeyIdentity(); + if (key != null && key.getPublic() != null + && key.getPrivate() != null) { + // We've just successfully loaded a key that wasn't in the + // agent. Add it to the agent. + // + // Keys are added after loading, as in OpenSSH. The alternative + // might be to add a key only after (partially) successful + // authentication? + PublicKey pk = key.getPublic(); + String fingerprint = KeyUtils.getFingerPrint(pk); + String keyType = KeyUtils.getKeyType(key); + try { + // Check that the key is not in the agent already. + if (agentHasKey(pk)) { + return id; + } + if (askBeforeAdding + && (session instanceof JGitClientSession)) { + CredentialsProvider provider = ((JGitClientSession) session) + .getCredentialsProvider(); + CredentialItem.YesNoType question = new CredentialItem.YesNoType( + format(SshdText + .get().pubkeyAuthAddKeyToAgentQuestion, + keyType, fingerprint)); + boolean result = provider != null + && provider.supports(question) + && provider.get(getUri(), question); + if (!result || !question.getValue()) { + // Don't add the key. + return id; + } + } + SshAgentKeyConstraint[] rules = constraints; + if (pk instanceof SecurityKeyPublicKey && !StringUtils.isEmptyOrNull(skProvider)) { + rules = Arrays.copyOf(rules, rules.length + 1); + rules[rules.length - 1] = + new SshAgentKeyConstraint.FidoProviderExtension(skProvider); + } + // Unfortunately a comment associated with the key is lost + // by Apache MINA sshd, and there is also no way to get the + // original file name for keys loaded from a file. So add it + // without comment. + agent.addIdentity(key, null, rules); + } catch (IOException e) { + // Do not re-throw: we don't want authentication to fail if + // we cannot add the key to the agent. + log.error( + format(SshdText.get().pubkeyAuthAddKeyToAgentError, + keyType, fingerprint), + e); + // Note that as of Win32-OpenSSH 8.6 and Pageant 0.76, + // neither can handle key constraints. Pageant fails + // gracefully, not adding the key and returning + // SSH_AGENT_FAILURE. Win32-OpenSSH closes the connection + // without even returning a failure message, which violates + // the SSH agent protocol and makes all subsequent requests + // to the agent fail. + } + } + } + return id; + } + + private boolean agentHasKey(PublicKey pk) throws IOException { + Iterable<? extends Map.Entry<PublicKey, String>> ids = agent + .getIdentities(); + if (ids == null) { + return false; + } + Iterator<? extends Map.Entry<PublicKey, String>> iter = ids.iterator(); + while (iter.hasNext()) { + if (KeyUtils.compareKeys(iter.next().getKey(), pk)) { + return true; + } + } + return false; + } + + private URIish getUri() { + String uri = SshConstants.SSH_SCHEME + "://"; //$NON-NLS-1$ + String userName = hostConfig.getUsername(); + if (!StringUtils.isEmptyOrNull(userName)) { + uri += userName + '@'; + } + uri += hostConfig.getHost(); + int port = hostConfig.getPort(); + if (port > 0 && port != SshConstants.SSH_DEFAULT_PORT) { + uri += ":" + port; //$NON-NLS-1$ + } + try { + return new URIish(uri); + } catch (URISyntaxException e) { + log.error(e.getLocalizedMessage(), e); + } + return new URIish(); + } + + private SshAgent getAgent(ClientSession session) throws Exception { + FactoryManager manager = Objects.requireNonNull( + session.getFactoryManager(), "No session factory manager"); //$NON-NLS-1$ + SshAgentFactory factory = manager.getAgentFactory(); + if (factory == null) { + return null; + } + return factory.createClient(session, manager); + } + + private void parseAddKeys(HostConfigEntry config) { + String value = config.getProperty(SshConstants.ADD_KEYS_TO_AGENT); + if (StringUtils.isEmptyOrNull(value)) { + addKeysToAgent = false; + return; + } + String[] values = value.split(","); //$NON-NLS-1$ + List<SshAgentKeyConstraint> rules = new ArrayList<>(2); + switch (values[0]) { + case "yes": //$NON-NLS-1$ + addKeysToAgent = true; + break; + case "no": //$NON-NLS-1$ + addKeysToAgent = false; + break; + case "ask": //$NON-NLS-1$ + addKeysToAgent = true; + askBeforeAdding = true; + break; + case "confirm": //$NON-NLS-1$ + addKeysToAgent = true; + rules.add(SshAgentKeyConstraint.CONFIRM); + if (values.length > 1) { + int seconds = OpenSshConfigFile.timeSpec(values[1]); + if (seconds > 0) { + rules.add(new SshAgentKeyConstraint.LifeTime(seconds)); + } + } + break; + default: + int seconds = OpenSshConfigFile.timeSpec(values[0]); + if (seconds > 0) { + addKeysToAgent = true; + rules.add(new SshAgentKeyConstraint.LifeTime(seconds)); + } + break; + } + constraints = rules.toArray(new SshAgentKeyConstraint[0]); + } + + @Override + protected void releaseKeys() throws IOException { + addKeysToAgent = false; + askBeforeAdding = false; + skProvider = null; + constraints = null; + try { + if (agent != null) { + try { + agent.close(); + } finally { + agent = null; + } + } + } finally { + super.releaseKeys(); + } + } + + private class KeyIterator extends UserAuthPublicKeyIterator { + + private Iterable<? extends Map.Entry<PublicKey, String>> agentKeys; + + // If non-null, all the public keys from explicitly given key files. Any + // agent key not matching one of these public keys will be ignored in + // getIdentities(). + private Collection<PublicKey> identityFiles; + + public KeyIterator(ClientSession session, + SignatureFactoriesManager manager) + throws Exception { + super(session, manager); + } + + private List<PublicKey> getExplicitKeys( + Collection<String> explicitFiles) { + if (explicitFiles == null) { + return null; + } + return explicitFiles.stream().map(s -> { + try { + Path p = Paths.get(s + ".pub"); //$NON-NLS-1$ + if (Files.isRegularFile(p, LinkOption.NOFOLLOW_LINKS)) { + return AuthorizedKeyEntry.readAuthorizedKeys(p).get(0) + .resolvePublicKey(null, + PublicKeyEntryResolver.IGNORING); + } + } catch (InvalidPathException | IOException + | GeneralSecurityException e) { + log.warn(format(SshdText.get().cannotReadPublicKey, s), e); + } + return null; + }).filter(Objects::nonNull).collect(Collectors.toList()); + } + + @Override + protected Iterable<KeyAgentIdentity> initializeAgentIdentities( + ClientSession session) throws IOException { + if (agent == null) { + return null; + } + agentKeys = agent.getIdentities(); + if (hostConfig != null && hostConfig.isIdentitiesOnly()) { + identityFiles = getExplicitKeys(hostConfig.getIdentities()); + } + return () -> new Iterator<>() { + + private final Iterator<? extends Map.Entry<PublicKey, String>> iter = agentKeys + .iterator(); + + private Map.Entry<PublicKey, String> next; @Override public boolean hasNext() { - if (value != null) { - return true; - } - PublicKeyIdentity next = null; - while (original.hasNext()) { - next = original.next(); - if (!(next instanceof KeyAgentIdentity)) { - value = next; + while (next == null && iter.hasNext()) { + Map.Entry<PublicKey, String> val = iter.next(); + PublicKey pk = val.getKey(); + // This checks against all explicit keys for any agent + // key, but since identityFiles.size() is typically 1, + // it should be fine. + if (identityFiles == null || identityFiles.stream() + .anyMatch(k -> KeyUtils.compareKeys(k, pk))) { + next = val; return true; } + if (log.isTraceEnabled()) { + log.trace( + "Ignoring SSH agent {} key not in explicit IdentityFile in SSH config: {}", //$NON-NLS-1$ + KeyUtils.getKeyType(pk), + KeyUtils.getFingerPrint(pk)); + } } - return false; + return next != null; } @Override - public PublicKeyIdentity next() { - if (hasNext()) { - PublicKeyIdentity result = value; - value = null; - return result; + public KeyAgentIdentity next() { + if (!hasNext()) { + throw new NoSuchElementException(); } - throw new NoSuchElementException(); + KeyAgentIdentity result = new KeyAgentIdentity(agent, + next.getKey(), next.getValue()); + next = null; + return result; } }; } diff --git a/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/JGitSshClient.java b/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/JGitSshClient.java index 71e8e61585..72f0bdb6ee 100644 --- a/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/JGitSshClient.java +++ b/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/JGitSshClient.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018, 2021 Thomas Wolf <thomas.wolf@paranor.ch> and others + * Copyright (C) 2018, 2022 Thomas Wolf <thomas.wolf@paranor.ch> and others * * This program and the accompanying materials are made available under the * terms of the Eclipse Distribution License v. 1.0 which is available at @@ -87,6 +87,11 @@ public class JGitSshClient extends SshClient { public static final AttributeKey<String> PREFERRED_AUTHENTICATIONS = new AttributeKey<>(); /** + * An attribute key for the home directory. + */ + public static final AttributeKey<Path> HOME_DIRECTORY = new AttributeKey<>(); + + /** * An attribute key for storing an alternate local address to connect to if * a local forward from a ProxyJump ssh config is present. If set, * {@link #connect(HostConfigEntry, AttributeRepository, SocketAddress)} diff --git a/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/JGitUserInteraction.java b/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/JGitUserInteraction.java index c51a75bc6f..2a725ea16a 100644 --- a/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/JGitUserInteraction.java +++ b/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/JGitUserInteraction.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018, Thomas Wolf <thomas.wolf@paranor.ch> and others + * Copyright (C) 2018, 2022 Thomas Wolf <thomas.wolf@paranor.ch> and others * * This program and the accompanying materials are made available under the * terms of the Eclipse Distribution License v. 1.0 which is available at @@ -120,15 +120,16 @@ public class JGitUserInteraction implements UserInteraction { return null; }).filter(s -> s != null).toArray(String[]::new); } - // TODO What to throw to abort the connection/authentication process? - // In UserAuthKeyboardInteractive.getUserResponses() it's clear that - // returning null is valid and signifies "an error"; we'll try the - // next authentication method. But if the user explicitly canceled, - // then we don't want to try the next methods... - // - // Probably not a serious issue with the typical order of public-key, - // keyboard-interactive, password. - return null; + throw new AuthenticationCanceledException(); + } + + @Override + public String resolveAuthPasswordAttempt(ClientSession session) + throws Exception { + String[] results = interactive(session, null, null, "", //$NON-NLS-1$ + new String[] { SshdText.get().passwordPrompt }, + new boolean[] { false }); + return (results == null || results.length == 0) ? null : results[0]; } @Override diff --git a/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/SshdText.java b/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/SshdText.java index 00ee62d6dd..39332d9fca 100644 --- a/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/SshdText.java +++ b/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/SshdText.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018, 2021 Thomas Wolf <thomas.wolf@paranor.ch> and others + * Copyright (C) 2018, 2022 Thomas Wolf <thomas.wolf@paranor.ch> and others * * This program and the accompanying materials are made available under the * terms of the Eclipse Distribution License v. 1.0 which is available at @@ -29,7 +29,25 @@ public final class SshdText extends TranslationBundle { // @formatter:off /***/ public String authenticationCanceled; /***/ public String authenticationOnClosedSession; + /***/ public String authGssApiAttempt; + /***/ public String authGssApiExhausted; + /***/ public String authGssApiFailure; + /***/ public String authGssApiNotTried; + /***/ public String authGssApiPartialSuccess; + /***/ public String authPasswordAttempt; + /***/ public String authPasswordChangeAttempt; + /***/ public String authPasswordExhausted; + /***/ public String authPasswordFailure; + /***/ public String authPasswordNotTried; + /***/ public String authPasswordPartialSuccess; + /***/ public String authPubkeyAttempt; + /***/ public String authPubkeyAttemptAgent; + /***/ public String authPubkeyExhausted; + /***/ public String authPubkeyFailure; + /***/ public String authPubkeyNoKeys; + /***/ public String authPubkeyPartialSuccess; /***/ public String closeListenerFailed; + /***/ public String cannotReadPublicKey; /***/ public String configInvalidPath; /***/ public String configInvalidPattern; /***/ public String configInvalidPositive; @@ -98,6 +116,8 @@ public final class SshdText extends TranslationBundle { /***/ public String proxySocksUnexpectedMessage; /***/ public String proxySocksUnexpectedVersion; /***/ public String proxySocksUsernameTooLong; + /***/ public String pubkeyAuthAddKeyToAgentError; + /***/ public String pubkeyAuthAddKeyToAgentQuestion; /***/ public String pubkeyAuthWrongCommand; /***/ public String pubkeyAuthWrongKey; /***/ public String pubkeyAuthWrongSignatureAlgorithm; @@ -106,9 +126,13 @@ public final class SshdText extends TranslationBundle { /***/ public String serverIdWithNul; /***/ public String sessionCloseFailed; /***/ public String sessionWithoutUsername; + /***/ public String sshAgentEdDSAFormatError; + /***/ public String sshAgentPayloadLengthError; /***/ public String sshAgentReplyLengthError; /***/ public String sshAgentReplyUnexpected; /***/ public String sshAgentShortReadBuffer; + /***/ public String sshAgentUnknownKey; + /***/ public String sshAgentWrongKeyLength; /***/ public String sshAgentWrongNumberOfKeys; /***/ public String sshClosingDown; /***/ public String sshCommandTimeout; diff --git a/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/agent/JGitSshAgentFactory.java b/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/agent/JGitSshAgentFactory.java index 1ed2ab9d78..a0ffd540f2 100644 --- a/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/agent/JGitSshAgentFactory.java +++ b/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/agent/JGitSshAgentFactory.java @@ -17,10 +17,14 @@ import java.util.List; import org.apache.sshd.agent.SshAgent; import org.apache.sshd.agent.SshAgentFactory; import org.apache.sshd.agent.SshAgentServer; +import org.apache.sshd.client.config.hosts.HostConfigEntry; import org.apache.sshd.common.FactoryManager; import org.apache.sshd.common.channel.ChannelFactory; import org.apache.sshd.common.session.ConnectionService; +import org.apache.sshd.common.session.Session; import org.eclipse.jgit.annotations.NonNull; +import org.eclipse.jgit.internal.transport.sshd.JGitClientSession; +import org.eclipse.jgit.transport.SshConstants; import org.eclipse.jgit.transport.sshd.agent.ConnectorFactory; /** @@ -49,18 +53,24 @@ public class JGitSshAgentFactory implements SshAgentFactory { @Override public List<ChannelFactory> getChannelForwardingFactories( FactoryManager manager) { - // No agent forwarding supported yet. + // No agent forwarding supported. return Collections.emptyList(); } @Override - public SshAgent createClient(FactoryManager manager) throws IOException { - // sshd 2.8.0 will pass us the session here. At that point, we can get - // the HostConfigEntry and extract and handle the IdentityAgent setting. - // For now, pass null to let the ConnectorFactory do its default - // behavior (Pageant on Windows, SSH_AUTH_SOCK on Unixes with the - // jgit-builtin factory). - return new SshAgentClient(factory.create(null, homeDir)); + public SshAgent createClient(Session session, FactoryManager manager) + throws IOException { + String identityAgent = null; + if (session instanceof JGitClientSession) { + HostConfigEntry hostConfig = ((JGitClientSession) session) + .getHostConfigEntry(); + identityAgent = hostConfig.getProperty(SshConstants.IDENTITY_AGENT, + null); + } + if (SshConstants.NONE.equals(identityAgent)) { + return null; + } + return new SshAgentClient(factory.create(identityAgent, homeDir)); } @Override diff --git a/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/agent/SshAgentClient.java b/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/agent/SshAgentClient.java index 08483e4c20..cbcb4d240e 100644 --- a/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/agent/SshAgentClient.java +++ b/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/agent/SshAgentClient.java @@ -11,10 +11,12 @@ package org.eclipse.jgit.internal.transport.sshd.agent; import java.io.IOException; import java.security.KeyPair; +import java.security.PrivateKey; import java.security.PublicKey; import java.text.MessageFormat; import java.util.AbstractMap; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Map; @@ -22,21 +24,27 @@ import java.util.concurrent.atomic.AtomicBoolean; import org.apache.sshd.agent.SshAgent; import org.apache.sshd.agent.SshAgentConstants; +import org.apache.sshd.agent.SshAgentKeyConstraint; import org.apache.sshd.common.SshException; import org.apache.sshd.common.config.keys.KeyUtils; +import org.apache.sshd.common.keyprovider.KeyPairProvider; import org.apache.sshd.common.session.SessionContext; import org.apache.sshd.common.util.buffer.Buffer; import org.apache.sshd.common.util.buffer.BufferException; import org.apache.sshd.common.util.buffer.BufferUtils; import org.apache.sshd.common.util.buffer.ByteArrayBuffer; +import org.apache.sshd.common.util.buffer.keys.BufferPublicKeyParser; +import org.apache.sshd.common.util.io.der.DERParser; import org.eclipse.jgit.internal.transport.sshd.SshdText; import org.eclipse.jgit.transport.sshd.agent.Connector; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * A client for an SSH2 agent. This client supports only querying identities and - * signature requests. + * A client for an SSH2 agent. This client supports querying identities, + * signature requests, and adding keys to an agent (with or without + * constraints). Removing keys is not supported, and the older SSH1 protocol is + * not supported. * * @see <a href="https://tools.ietf.org/html/draft-miller-ssh-agent-04">SSH * Agent Protocol, RFC draft</a> @@ -72,11 +80,18 @@ public class SshAgentClient implements SshAgent { } return false; } - boolean connected = connector != null && connector.connect(); - if (!connected) { + boolean connected; + try { + connected = connector != null && connector.connect(); + if (!connected && debugging) { + LOG.debug("No SSH agent"); //$NON-NLS-1$ + } + } catch (IOException e) { + // Agent not running? if (debugging) { - LOG.debug("No SSH agent (SSH_AUTH_SOCK not set)"); //$NON-NLS-1$ + LOG.debug("No SSH agent", e); //$NON-NLS-1$ } + throw e; } return connected; } @@ -127,14 +142,17 @@ public class SshAgentClient implements SshAgent { List<Map.Entry<PublicKey, String>> keys = new ArrayList<>( numberOfKeys); for (int i = 0; i < numberOfKeys; i++) { - PublicKey key = reply.getPublicKey(); + PublicKey key = readKey(reply); String comment = reply.getString(); - if (tracing) { - LOG.trace("Got SSH agent {} key: {} {}", //$NON-NLS-1$ - KeyUtils.getKeyType(key), - KeyUtils.getFingerPrint(key), comment); + if (key != null) { + if (tracing) { + LOG.trace("Got SSH agent {} key: {} {}", //$NON-NLS-1$ + KeyUtils.getKeyType(key), + KeyUtils.getFingerPrint(key), comment); + } + keys.add(new AbstractMap.SimpleImmutableEntry<>(key, + comment)); } - keys.add(new AbstractMap.SimpleImmutableEntry<>(key, comment)); } return keys; } catch (BufferException e) { @@ -216,6 +234,222 @@ public class SshAgentClient implements SshAgent { } } + @Override + public void addIdentity(KeyPair key, String comment, + SshAgentKeyConstraint... constraints) throws IOException { + boolean debugging = LOG.isDebugEnabled(); + if (!open(debugging)) { + return; + } + + // Neither Pageant 0.76 nor Win32-OpenSSH 8.6 support command + // SSH2_AGENTC_ADD_ID_CONSTRAINED. Adding a key with constraints will + // fail. The only work-around for users is not to use "confirm" or "time + // spec" with AddKeysToAgent, and not to use sk-* keys. + // + // With a true OpenSSH SSH agent, key constraints work. + byte cmd = (constraints != null && constraints.length > 0) + ? SshAgentConstants.SSH2_AGENTC_ADD_ID_CONSTRAINED + : SshAgentConstants.SSH2_AGENTC_ADD_IDENTITY; + byte[] message = null; + ByteArrayBuffer msg = new ByteArrayBuffer(); + try { + msg.putInt(0); + msg.putByte(cmd); + String keyType = KeyUtils.getKeyType(key); + if (KeyPairProvider.SSH_ED25519.equals(keyType)) { + // Apache MINA sshd 2.8.0 lacks support for writing ed25519 + // private keys to a buffer. + putEd25519Key(msg, key); + } else { + msg.putKeyPair(key); + } + msg.putString(comment == null ? "" : comment); //$NON-NLS-1$ + if (constraints != null) { + for (SshAgentKeyConstraint constraint : constraints) { + constraint.put(msg); + } + } + if (debugging) { + LOG.debug( + "addIdentity: adding {} key {} to SSH agent; comment {}", //$NON-NLS-1$ + keyType, KeyUtils.getFingerPrint(key.getPublic()), + comment); + } + message = msg.getCompactData(); + } finally { + // The message contains the private key data, so clear intermediary + // data ASAP. + msg.clear(); + } + Buffer reply; + try { + reply = rpc(cmd, message); + } finally { + Arrays.fill(message, (byte) 0); + } + int replyLength = reply.available(); + if (replyLength != 1) { + throw new SshException(MessageFormat.format( + SshdText.get().sshAgentReplyUnexpected, + MessageFormat.format( + SshdText.get().sshAgentPayloadLengthError, + Integer.valueOf(1), Integer.valueOf(replyLength)))); + + } + cmd = reply.getByte(); + if (cmd != SshAgentConstants.SSH_AGENT_SUCCESS) { + throw new SshException( + MessageFormat.format(SshdText.get().sshAgentReplyUnexpected, + SshAgentConstants.getCommandMessageName(cmd))); + } + } + + /** + * Writes an ed25519 {@link KeyPair} to a {@link Buffer}. OpenSSH specifies + * that it expects the 32 public key bytes, followed by 64 bytes formed by + * concatenating the 32 private key bytes with the 32 public key bytes. + * + * @param msg + * {@link Buffer} to write to + * @param key + * {@link KeyPair} to write + * @throws IOException + * if the private key cannot be written + */ + private static void putEd25519Key(Buffer msg, KeyPair key) + throws IOException { + Buffer tmp = new ByteArrayBuffer(36); + tmp.putRawPublicKeyBytes(key.getPublic()); + byte[] publicBytes = tmp.getBytes(); + msg.putString(KeyPairProvider.SSH_ED25519); + msg.putBytes(publicBytes); + // Next is the concatenation of the 32 byte private key value with the + // 32 bytes of the public key. + PrivateKey pk = key.getPrivate(); + String format = pk.getFormat(); + if (!"PKCS#8".equalsIgnoreCase(format)) { //$NON-NLS-1$ + throw new IOException(MessageFormat + .format(SshdText.get().sshAgentEdDSAFormatError, format)); + } + byte[] privateBytes = null; + byte[] encoded = pk.getEncoded(); + try { + privateBytes = asn1Parse(encoded, 32); + byte[] combined = Arrays.copyOf(privateBytes, 64); + Arrays.fill(privateBytes, (byte) 0); + privateBytes = combined; + System.arraycopy(publicBytes, 0, privateBytes, 32, 32); + msg.putBytes(privateBytes); + } finally { + if (privateBytes != null) { + Arrays.fill(privateBytes, (byte) 0); + } + Arrays.fill(encoded, (byte) 0); + } + } + + /** + * Extracts the private key bytes from an encoded ed25519 private key by + * parsing the bytes as ASN.1 according to RFC 5958 (PKCS #8 encoding): + * + * <pre> + * OneAsymmetricKey ::= SEQUENCE { + * version Version, + * privateKeyAlgorithm PrivateKeyAlgorithmIdentifier, + * privateKey PrivateKey, + * ... + * } + * + * Version ::= INTEGER + * PrivateKeyAlgorithmIdentifier ::= AlgorithmIdentifier + * PrivateKey ::= OCTET STRING + * + * AlgorithmIdentifier ::= SEQUENCE { + * algorithm OBJECT IDENTIFIER, + * parameters ANY DEFINED BY algorithm OPTIONAL + * } + * </pre> + * <p> + * and RFC 8410: "... when encoding a OneAsymmetricKey object, the private + * key is wrapped in a CurvePrivateKey object and wrapped by the OCTET + * STRING of the 'privateKey' field." + * </p> + * + * <pre> + * CurvePrivateKey ::= OCTET STRING + * </pre> + * + * @param encoded + * encoded private key to extract the private key bytes from + * @param n + * number of bytes expected + * @return the extracted private key bytes; of length {@code n} + * @throws IOException + * if the private key cannot be extracted + * @see <a href="https://tools.ietf.org/html/rfc5958">RFC 5958</a> + * @see <a href="https://tools.ietf.org/html/rfc8410">RFC 8410</a> + */ + private static byte[] asn1Parse(byte[] encoded, int n) throws IOException { + byte[] privateKey = null; + try (DERParser byteParser = new DERParser(encoded); + DERParser oneAsymmetricKey = byteParser.readObject() + .createParser()) { + oneAsymmetricKey.readObject(); // skip version + oneAsymmetricKey.readObject(); // skip algorithm identifier + privateKey = oneAsymmetricKey.readObject().getValue(); + // The last n bytes of this must be the private key bytes + return Arrays.copyOfRange(privateKey, + privateKey.length - n, privateKey.length); + } finally { + if (privateKey != null) { + Arrays.fill(privateKey, (byte) 0); + } + } + } + + /** + * A safe version of {@link Buffer#getPublicKey()}. Upon return the + * buffers's read position is always after the key blob; any exceptions + * thrown by trying to read the key are logged and <em>not</em> propagated. + * <p> + * This is needed because an SSH agent might contain and deliver keys that + * we cannot handle (for instance ed448 keys). + * </p> + * + * @param buffer + * to read the key from + * @return the {@link PublicKey}, or {@code null} if the key could not be + * read + * @throws BufferException + * if the length of the key blob cannot be read or is corrupted + */ + private static PublicKey readKey(Buffer buffer) throws BufferException { + int endOfBuffer = buffer.wpos(); + int keyLength = buffer.getInt(); + int afterKey = buffer.rpos() + keyLength; + if (keyLength <= 0 || afterKey > endOfBuffer) { + throw new BufferException( + MessageFormat.format(SshdText.get().sshAgentWrongKeyLength, + Integer.toString(keyLength), + Integer.toString(buffer.rpos()), + Integer.toString(endOfBuffer))); + } + // Limit subsequent reads to the public key blob + buffer.wpos(afterKey); + try { + return buffer.getRawPublicKey(BufferPublicKeyParser.DEFAULT); + } catch (Exception e) { + LOG.warn(SshdText.get().sshAgentUnknownKey, e); + return null; + } finally { + // Restore real buffer end + buffer.wpos(endOfBuffer); + // Set the read position to after this key, even if failed + buffer.rpos(afterKey); + } + } + private Buffer rpc(byte command, byte[] message) throws IOException { return new ByteArrayBuffer(connector.rpc(command, message)); } @@ -230,11 +464,6 @@ public class SshAgentClient implements SshAgent { } @Override - public void addIdentity(KeyPair key, String comment) throws IOException { - throw new UnsupportedOperationException(); - } - - @Override public void removeIdentity(PublicKey key) throws IOException { throw new UnsupportedOperationException(); } diff --git a/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/transport/sshd/SshdSession.java b/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/transport/sshd/SshdSession.java index c270b44956..b94ccc6d4f 100644 --- a/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/transport/sshd/SshdSession.java +++ b/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/transport/sshd/SshdSession.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018, 2021 Thomas Wolf <thomas.wolf@paranor.ch> and others + * Copyright (C) 2018, 2022 Thomas Wolf <thomas.wolf@paranor.ch> and others * * This program and the accompanying materials are made available under the * terms of the Eclipse Distribution License v. 1.0 which is available at @@ -51,6 +51,9 @@ import org.apache.sshd.sftp.client.SftpClientFactory; import org.apache.sshd.sftp.common.SftpException; import org.eclipse.jgit.annotations.NonNull; import org.eclipse.jgit.errors.TransportException; +import org.eclipse.jgit.internal.transport.ssh.OpenSshConfigFile; +import org.eclipse.jgit.internal.transport.sshd.AuthenticationCanceledException; +import org.eclipse.jgit.internal.transport.sshd.AuthenticationLogger; import org.eclipse.jgit.internal.transport.sshd.JGitSshClient; import org.eclipse.jgit.internal.transport.sshd.SshdText; import org.eclipse.jgit.transport.FtpChannel; @@ -118,6 +121,7 @@ public class SshdSession implements RemoteSession2 { ClientSession resultSession = null; ClientSession proxySession = null; PortForwardingTracker portForward = null; + AuthenticationLogger authLog = null; try { if (!hops.isEmpty()) { URIish hop = hops.remove(0); @@ -138,7 +142,11 @@ public class SshdSession implements RemoteSession2 { JGitSshClient.LOCAL_FORWARD_ADDRESS, portForward.getBoundAddress()); } - resultSession = connect(hostConfig, context, timeout); + int timeoutInSec = OpenSshConfigFile.timeSpec( + hostConfig.getProperty(SshConstants.CONNECT_TIMEOUT)); + resultSession = connect(hostConfig, context, + timeoutInSec > 0 ? Duration.ofSeconds(timeoutInSec) + : timeout); if (proxySession != null) { final PortForwardingTracker tracker = portForward; final ClientSession pSession = proxySession; @@ -160,6 +168,7 @@ public class SshdSession implements RemoteSession2 { resultSession.addCloseFutureListener(listener); } // Authentication timeout is by default 2 minutes. + authLog = new AuthenticationLogger(resultSession); resultSession.auth().verify(resultSession.getAuthTimeout()); return resultSession; } catch (IOException e) { @@ -168,15 +177,32 @@ public class SshdSession implements RemoteSession2 { close(resultSession, e); if (e instanceof SshException && ((SshException) e) .getDisconnectCode() == SSH2_DISCONNECT_NO_MORE_AUTH_METHODS_AVAILABLE) { - // Ensure the user gets to know on which URI the authentication - // was denied. + String message = format(SshdText.get().loginDenied, host, + Integer.toString(port)); throw new TransportException(target, - format(SshdText.get().loginDenied, host, - Integer.toString(port)), - e); + withAuthLog(message, authLog), e); + } else if (e instanceof SshException && e + .getCause() instanceof AuthenticationCanceledException) { + String message = e.getCause().getMessage(); + throw new TransportException(target, + withAuthLog(message, authLog), e.getCause()); } throw e; + } finally { + if (authLog != null) { + authLog.clear(); + } + } + } + + private String withAuthLog(String message, AuthenticationLogger authLog) { + if (authLog != null) { + String log = String.join(System.lineSeparator(), authLog.getLog()); + if (!log.isEmpty()) { + return message + System.lineSeparator() + log; + } } + return message; } private ClientSession connect(HostConfigEntry config, diff --git a/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/transport/sshd/SshdSessionFactory.java b/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/transport/sshd/SshdSessionFactory.java index 58cf8e1ddd..c792c1889c 100644 --- a/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/transport/sshd/SshdSessionFactory.java +++ b/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/transport/sshd/SshdSessionFactory.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018, 2021 Thomas Wolf <thomas.wolf@paranor.ch> and others + * Copyright (C) 2018, 2022 Thomas Wolf <thomas.wolf@paranor.ch> and others * * This program and the accompanying materials are made available under the * terms of the Eclipse Distribution License v. 1.0 which is available at @@ -13,6 +13,7 @@ import java.io.Closeable; import java.io.File; import java.io.IOException; import java.nio.file.Files; +import java.nio.file.InvalidPathException; import java.nio.file.Path; import java.security.KeyPair; import java.time.Duration; @@ -34,7 +35,6 @@ import org.apache.sshd.client.auth.UserAuthFactory; import org.apache.sshd.client.auth.keyboard.UserAuthKeyboardInteractiveFactory; import org.apache.sshd.client.config.hosts.HostConfigEntryResolver; import org.apache.sshd.common.NamedFactory; -import org.apache.sshd.common.SshException; import org.apache.sshd.common.compression.BuiltinCompressions; import org.apache.sshd.common.config.keys.FilePasswordProvider; import org.apache.sshd.common.config.keys.loader.openssh.kdf.BCryptKdfOptions; @@ -44,7 +44,6 @@ import org.apache.sshd.common.signature.Signature; import org.eclipse.jgit.annotations.NonNull; import org.eclipse.jgit.errors.TransportException; import org.eclipse.jgit.internal.transport.ssh.OpenSshConfigFile; -import org.eclipse.jgit.internal.transport.sshd.AuthenticationCanceledException; import org.eclipse.jgit.internal.transport.sshd.CachingKeyPairProvider; import org.eclipse.jgit.internal.transport.sshd.GssApiWithMicAuthFactory; import org.eclipse.jgit.internal.transport.sshd.JGitPasswordAuthFactory; @@ -243,6 +242,12 @@ public class SshdSessionFactory extends SshSessionFactory implements Closeable { JGitSshClient.PREFERRED_AUTHENTICATIONS, defaultAuths); } + try { + jgitClient.setAttribute(JGitSshClient.HOME_DIRECTORY, + home.getAbsoluteFile().toPath()); + } catch (SecurityException | InvalidPathException e) { + // Ignore + } // Other things? return client; }); @@ -255,13 +260,7 @@ public class SshdSessionFactory extends SshSessionFactory implements Closeable { if (e instanceof TransportException) { throw (TransportException) e; } - Throwable cause = e; - if (e instanceof SshException && e - .getCause() instanceof AuthenticationCanceledException) { - // Results in a nicer error message - cause = e.getCause(); - } - throw new TransportException(uri, cause.getMessage(), cause); + throw new TransportException(uri, e.getMessage(), e); } } diff --git a/org.eclipse.jgit.test/BUILD b/org.eclipse.jgit.test/BUILD index c9b5d37265..6f6c88ce8d 100644 --- a/org.eclipse.jgit.test/BUILD +++ b/org.eclipse.jgit.test/BUILD @@ -13,6 +13,7 @@ HELPERS = glob( ) + [PKG + c for c in [ "api/AbstractRemoteCommandTest.java", "diff/AbstractDiffTestCase.java", + "internal/diffmergetool/ExternalToolTestCase.java", "internal/revwalk/ObjectReachabilityTestCase.java", "internal/revwalk/ReachabilityCheckerTestCase.java", "internal/storage/file/GcTestCase.java", @@ -42,6 +43,7 @@ DATA = [ EXCLUDED = [ PKG + "api/SecurityManagerTest.java", PKG + "api/SecurityManagerMissingPermissionsTest.java", + PKG + "lib/CommitTemplateConfigTest.java", ] tests(tests = glob( diff --git a/org.eclipse.jgit.test/META-INF/MANIFEST.MF b/org.eclipse.jgit.test/META-INF/MANIFEST.MF index 2952efbdfc..832a93e5d4 100644 --- a/org.eclipse.jgit.test/META-INF/MANIFEST.MF +++ b/org.eclipse.jgit.test/META-INF/MANIFEST.MF @@ -33,6 +33,7 @@ Import-Package: com.googlecode.javaewah;version="[1.1.6,2.0.0)", org.eclipse.jgit.ignore;version="[7.0.0,7.1.0)", org.eclipse.jgit.ignore.internal;version="[7.0.0,7.1.0)", org.eclipse.jgit.internal;version="[7.0.0,7.1.0)", + org.eclipse.jgit.internal.diff;version="[7.0.0,7.1.0)", org.eclipse.jgit.internal.diffmergetool;version="[7.0.0,7.1.0)", org.eclipse.jgit.internal.fsck;version="[7.0.0,7.1.0)", org.eclipse.jgit.internal.revwalk;version="[7.0.0,7.1.0)", diff --git a/org.eclipse.jgit.test/build.properties b/org.eclipse.jgit.test/build.properties index b527a74790..212c8bd4d7 100644 --- a/org.eclipse.jgit.test/build.properties +++ b/org.eclipse.jgit.test/build.properties @@ -7,5 +7,4 @@ bin.includes = META-INF/,\ plugin.properties,\ bin-tst/,\ bin/ -additional.bundles = org.apache.log4j,\ - org.slf4j.binding.log4j12 +additional.bundles = org.slf4j.binding.simple diff --git a/org.eclipse.jgit.test/tests.bzl b/org.eclipse.jgit.test/tests.bzl index 34df07d5e6..e201bdbcb3 100644 --- a/org.eclipse.jgit.test/tests.bzl +++ b/org.eclipse.jgit.test/tests.bzl @@ -36,7 +36,7 @@ def tests(tests): ] if src.endswith("SecurityManagerMissingPermissionsTest.java"): additional_deps = [ - "//lib:log4j", + "//lib:slf4j-simple", ] if src.endswith("JDKHttpConnectionTest.java"): additional_deps = [ @@ -68,6 +68,7 @@ def tests(tests): "//lib:javaewah", "//lib:junit", "//lib:slf4j-api", + "//lib:slf4j-simple", "//org.eclipse.jgit:jgit", "//org.eclipse.jgit.junit:junit", "//org.eclipse.jgit.lfs:jgit-lfs", diff --git a/org.eclipse.jgit.test/tst-rsrc/jgit-s3-config.disabled.properties b/org.eclipse.jgit.test/tst-rsrc/jgit-s3-config.disabled.properties index d540977e94..3f36282b9e 100644 --- a/org.eclipse.jgit.test/tst-rsrc/jgit-s3-config.disabled.properties +++ b/org.eclipse.jgit.test/tst-rsrc/jgit-s3-config.disabled.properties @@ -40,6 +40,15 @@ # * https://docs.aws.amazon.com/AmazonS3/latest/dev/manage-lifecycle-using-console.html # +# AWS API signature version (defaults to 2) +# aws.api.signature.version=4 + +# AWS S3 Region Domain (defaults to s3.amazonaws.com) +# domain: s3-us-east-2.amazonaws.com + +# AWS S3 Region (required if aws.api.signature.version=4, must match domain) +# region: us-east-2 + # Test bucket name test.bucket=jgit.eclipse.org diff --git a/org.eclipse.jgit.test/tst-rsrc/log4j.properties b/org.eclipse.jgit.test/tst-rsrc/log4j.properties deleted file mode 100644 index 856a731ab9..0000000000 --- a/org.eclipse.jgit.test/tst-rsrc/log4j.properties +++ /dev/null @@ -1,14 +0,0 @@ - -# Root logger option -log4j.rootLogger=INFO, stdout - -# Direct log messages to stdout -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.Target=System.out -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n -log4j.appender.fileLogger.bufferedIO = true -log4j.appender.fileLogger.bufferSize = 4096 - -#log4j.logger.org.eclipse.jgit.util.FS = DEBUG -#log4j.logger.org.eclipse.jgit.internal.storage.file.FileSnapshot = DEBUG diff --git a/org.eclipse.jgit.test/tst-rsrc/simplelogger.properties b/org.eclipse.jgit.test/tst-rsrc/simplelogger.properties index 011b2f8bb0..235fea21ac 100644 --- a/org.eclipse.jgit.test/tst-rsrc/simplelogger.properties +++ b/org.eclipse.jgit.test/tst-rsrc/simplelogger.properties @@ -1,9 +1,9 @@ -org.slf4j.simpleLogger.logFile = System.err -org.slf4j.simpleLogger.cacheOutputStream = true -org.slf4j.simpleLogger.defaultLogLevel = info -org.slf4j.simpleLogger.showDateTime = true -org.slf4j.simpleLogger.dateTimeFormat = HH:mm:ss.SSSXXX -org.slf4j.simpleLogger.showThreadName = true +org.slf4j.simpleLogger.defaultLogLevel=info +org.slf4j.simpleLogger.logFile=System.err +org.slf4j.simpleLogger.showDateTime=true +org.slf4j.simpleLogger.dateTimeFormat=yyyy-MM-dd HH:mm:ss +org.slf4j.simpleLogger.showThreadName=true +org.slf4j.simpleLogger.showLogName=true #org.slf4j.simpleLogger.log.org.eclipse.jgit.util.FS = debug #org.slf4j.simpleLogger.log.org.eclipse.jgit.internal.storage.file.FileSnapshot = debug 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 867310b60c..584d149631 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 @@ -32,6 +32,7 @@ import org.eclipse.jgit.diff.RawText; import org.eclipse.jgit.junit.RepositoryTestCase; import org.eclipse.jgit.lib.Config; import org.eclipse.jgit.lib.ConfigConstants; +import org.eclipse.jgit.util.FS; import org.eclipse.jgit.util.IO; import org.junit.Test; @@ -402,7 +403,9 @@ public class ApplyCommandTest extends RepositoryTestCase { public void testAddM1() throws Exception { ApplyResult result = init("M1", false, true); assertEquals(1, result.getUpdatedFiles().size()); - assertTrue(result.getUpdatedFiles().get(0).canExecute()); + if (FS.DETECTED.supportsExecute()) { + assertTrue(FS.DETECTED.canExecute(result.getUpdatedFiles().get(0))); + } checkFile(new File(db.getWorkTree(), "M1"), b.getString(0, b.size(), false)); } @@ -411,7 +414,9 @@ public class ApplyCommandTest extends RepositoryTestCase { public void testModifyM2() throws Exception { ApplyResult result = init("M2", true, true); assertEquals(1, result.getUpdatedFiles().size()); - assertTrue(result.getUpdatedFiles().get(0).canExecute()); + if (FS.DETECTED.supportsExecute()) { + assertTrue(FS.DETECTED.canExecute(result.getUpdatedFiles().get(0))); + } checkFile(new File(db.getWorkTree(), "M2"), b.getString(0, b.size(), false)); } @@ -420,7 +425,10 @@ public class ApplyCommandTest extends RepositoryTestCase { public void testModifyM3() throws Exception { ApplyResult result = init("M3", true, true); assertEquals(1, result.getUpdatedFiles().size()); - assertFalse(result.getUpdatedFiles().get(0).canExecute()); + if (FS.DETECTED.supportsExecute()) { + assertFalse( + FS.DETECTED.canExecute(result.getUpdatedFiles().get(0))); + } checkFile(new File(db.getWorkTree(), "M3"), b.getString(0, b.size(), false)); } 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 e7ed102f13..87be813c85 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 @@ -71,6 +71,7 @@ public class BranchCommandTest extends RepositoryTestCase { private Git setUpRepoWithRemote() throws Exception { Repository remoteRepository = createWorkRepository(); + addRepoToClose(remoteRepository); try (Git remoteGit = new Git(remoteRepository)) { // commit something writeTrashFile("Test.txt", "Hello world"); @@ -85,6 +86,7 @@ public class BranchCommandTest extends RepositoryTestCase { rup.forceUpdate(); Repository localRepository = createWorkRepository(); + addRepoToClose(localRepository); Git localGit = new Git(localRepository); StoredConfig config = localRepository.getConfig(); RemoteConfig rc = new RemoteConfig(config, "origin"); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java index e520732513..ab0184bd4a 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java @@ -292,6 +292,7 @@ public class CheckoutCommandTest extends RepositoryTestCase { @Test public void testCheckoutRemoteTrackingWithUpstream() throws Exception { Repository db2 = createRepositoryWithRemote(); + addRepoToClose(db2); Git.wrap(db2).checkout().setCreateBranch(true).setName("test") .setStartPoint("origin/test") @@ -311,6 +312,7 @@ public class CheckoutCommandTest extends RepositoryTestCase { @Test public void testCheckoutRemoteTrackingWithoutLocalBranch() throws Exception { Repository db2 = createRepositoryWithRemote(); + addRepoToClose(db2); // checkout remote tracking branch in second repository // (no local branches exist yet in second repository) @@ -868,7 +870,7 @@ public class CheckoutCommandTest extends RepositoryTestCase { coCommand.setName(crudCommit.getName()).call(); CheckoutResult result = coCommand.getResult(); assertEquals(Status.NONDELETED, result.getStatus()); - assertEquals("[Test.txt, toBeDeleted.txt]", + assertEquals("[toBeDeleted.txt]", result.getRemovedList().toString()); assertEquals("[toBeCreated.txt, toBeModified.txt]", result.getModifiedList().toString()); 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 f4f0ecd689..0d38197d9a 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 @@ -175,7 +175,8 @@ public class CherryPickCommandTest extends RepositoryTestCase { assertEquals(CherryPickStatus.CONFLICTING, result.getStatus()); assertTrue(new File(db.getDirectory(), Constants.MERGE_MSG).exists()); - assertEquals("side\n\nConflicts:\n\ta\n", db.readMergeCommitMsg()); + assertEquals("side\n\n# Conflicts:\n#\ta\n", + db.readMergeCommitMsg()); assertTrue(new File(db.getDirectory(), Constants.CHERRY_PICK_HEAD) .exists()); assertEquals(sideCommit.getId(), db.readCherryPickHead()); @@ -207,7 +208,7 @@ public class CherryPickCommandTest extends RepositoryTestCase { String expected = "<<<<<<< master\na(master)\n=======\na(side)\n>>>>>>> 527460a side\n"; assertEquals(expected, read("a")); assertTrue(new File(db.getDirectory(), Constants.MERGE_MSG).exists()); - assertEquals("side\n\nConflicts:\n\ta\n", db.readMergeCommitMsg()); + assertEquals("side\n\n# Conflicts:\n#\ta\n", db.readMergeCommitMsg()); assertFalse(new File(db.getDirectory(), Constants.CHERRY_PICK_HEAD) .exists()); assertEquals(RepositoryState.SAFE, db.getRepositoryState()); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java index de25870bd0..c928d2ad22 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java @@ -22,6 +22,7 @@ import java.net.URISyntaxException; import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.stream.Stream; import org.eclipse.jgit.api.ListBranchCommand.ListMode; import org.eclipse.jgit.api.errors.GitAPIException; @@ -115,6 +116,49 @@ public class CloneCommandTest extends RepositoryTestCase { } @Test + public void testCloneRepository_refLogForLocalRefs() + throws IOException, JGitInternalException, GitAPIException { + File directory = createTempDirectory("testCloneRepository"); + CloneCommand command = Git.cloneRepository(); + command.setDirectory(directory); + command.setURI(fileUri()); + Git git2 = command.call(); + Repository clonedRepo = git2.getRepository(); + addRepoToClose(clonedRepo); + + List<Ref> clonedRefs = clonedRepo.getRefDatabase().getRefs(); + Stream<Ref> remoteRefs = clonedRefs.stream() + .filter(CloneCommandTest::isRemote); + Stream<Ref> localHeadsRefs = clonedRefs.stream() + .filter(CloneCommandTest::isLocalHead); + + remoteRefs.forEach(ref -> assertFalse( + "Ref " + ref.getName() + + " is remote and should not have a reflog", + hasRefLog(clonedRepo, ref))); + localHeadsRefs.forEach(ref -> assertTrue( + "Ref " + ref.getName() + + " is local head and should have a reflog", + hasRefLog(clonedRepo, ref))); + } + + private static boolean isRemote(Ref ref) { + return ref.getName().startsWith(Constants.R_REMOTES); + } + + private static boolean isLocalHead(Ref ref) { + return !isRemote(ref) && ref.getName().startsWith(Constants.R_HEADS); + } + + private static boolean hasRefLog(Repository repo, Ref ref) { + try { + return repo.getReflogReader(ref.getName()).getLastEntry() != null; + } catch (IOException ioe) { + throw new IllegalStateException(ioe); + } + } + + @Test public void testCloneRepositoryExplicitGitDir() throws IOException, JGitInternalException, GitAPIException { File directory = createTempDirectory("testCloneRepository"); 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 8084505c10..35de73e204 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 @@ -46,6 +46,7 @@ import org.eclipse.jgit.lib.RefUpdate.Result; import org.eclipse.jgit.lib.ReflogEntry; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.StoredConfig; +import org.eclipse.jgit.lib.CommitConfig.CleanupMode; import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.storage.file.FileBasedConfig; import org.eclipse.jgit.submodule.SubmoduleWalk; @@ -515,6 +516,62 @@ public class CommitCommandTest extends RepositoryTestCase { } @Test + public void commitMessageVerbatim() throws Exception { + try (Git git = new Git(db)) { + writeTrashFile("file1", "file1"); + git.add().addFilepattern("file1").call(); + RevCommit committed = git.commit().setMessage("#initial commit") + .call(); + + assertEquals("#initial commit", committed.getFullMessage()); + } + } + + @Test + public void commitMessageStrip() throws Exception { + try (Git git = new Git(db)) { + writeTrashFile("file1", "file1"); + git.add().addFilepattern("file1").call(); + RevCommit committed = git.commit().setMessage( + "#Comment\ninitial commit\t\n\n commit body \n \t#another comment") + .setCleanupMode(CleanupMode.STRIP).call(); + + assertEquals("initial commit\n\n commit body", + committed.getFullMessage()); + } + } + + @Test + public void commitMessageDefault() throws Exception { + try (Git git = new Git(db)) { + writeTrashFile("file1", "file1"); + git.add().addFilepattern("file1").call(); + RevCommit committed = git.commit().setMessage( + "#Comment\ninitial commit\t\n\n commit body \n\n\n \t#another comment ") + .setCleanupMode(CleanupMode.DEFAULT).call(); + + assertEquals("initial commit\n\n commit body", + committed.getFullMessage()); + } + } + + @Test + public void commitMessageDefaultWhitespace() throws Exception { + try (Git git = new Git(db)) { + writeTrashFile("file1", "file1"); + git.add().addFilepattern("file1").call(); + RevCommit committed = git.commit().setMessage( + "#Comment\ninitial commit\t\n\n commit body \n\n\n \t#another comment ") + .setCleanupMode(CleanupMode.DEFAULT).setDefaultClean(false) + .call(); + + assertEquals( + "#Comment\ninitial commit\n\n commit body\n\n \t#another comment", + committed.getFullMessage()); + } + } + + @Test public void commitEmptyCommits() throws Exception { try (Git git = new Git(db)) { 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 b460e3f52e..ab87fa9662 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 @@ -10,9 +10,10 @@ package org.eclipse.jgit.api; import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.OBJECT_ID_ABBREV_STRING_LENGTH; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import java.io.BufferedWriter; @@ -100,6 +101,12 @@ public class DescribeCommandTest extends RepositoryTestCase { 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*")); + + assertEquals("bob-t2", describe(c4, false, true, 0)); + assertEquals("bob-t2-1-g3e56", describe(c4, false, true, 1)); + assertEquals("bob-t2-1-g3e56", describe(c4, false, true, -10)); + assertEquals("bob-t2-1-g3e563c55927905f21e3bc7c00a3d83a31bf4ed3a", + describe(c4, false, true, 50)); } else { assertEquals(null, describe(c2)); assertEquals(null, describe(c3)); @@ -108,6 +115,18 @@ public class DescribeCommandTest extends RepositoryTestCase { assertEquals("3747db3", describe(c2, false, true)); assertEquals("44579eb", describe(c3, false, true)); assertEquals("3e563c5", describe(c4, false, true)); + + assertEquals("3747db3267", describe(c2, false, true, 10)); + assertEquals("44579ebe7f", describe(c3, false, true, 10)); + assertEquals("3e563c5592", describe(c4, false, true, 10)); + + assertEquals("3e56", describe(c4, false, true, -10)); + assertEquals("3e56", describe(c4, false, true, 0)); + assertEquals("3e56", describe(c4, false, true, 2)); + assertEquals("3e563c55927905f21e3bc7c00a3d83a31bf4ed3a", + describe(c4, false, true, 40)); + assertEquals("3e563c55927905f21e3bc7c00a3d83a31bf4ed3a", + describe(c4, false, true, 42)); } // test default target @@ -474,10 +493,15 @@ public class DescribeCommandTest extends RepositoryTestCase { } } + private String describe(ObjectId c1, boolean longDesc, boolean always, + int abbrev) throws GitAPIException, IOException { + return git.describe().setTarget(c1).setTags(describeUseAllTags) + .setLong(longDesc).setAlways(always).setAbbrev(abbrev).call(); + } + private String describe(ObjectId c1, boolean longDesc, boolean always) throws GitAPIException, IOException { - return git.describe().setTarget(c1).setTags(describeUseAllTags) - .setLong(longDesc).setAlways(always).call(); + return describe(c1, longDesc, always, OBJECT_ID_ABBREV_STRING_LENGTH); } private String describe(ObjectId c1) throws GitAPIException, IOException { diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/EolRepositoryTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/EolRepositoryTest.java index d0dfd1ab92..b937b1f6a9 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/EolRepositoryTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/EolRepositoryTest.java @@ -1,40 +1,11 @@ /* - * Copyright (C) 2015, Ivan Motsch <ivan.motsch@bsiag.com> + * Copyright (C) 2015, 2022 Ivan Motsch <ivan.motsch@bsiag.com> and others * - * 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 + * This program and the accompanying materials are made available under the + * terms of the Eclipse Distribution License v. 1.0 which is available at + * https://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. + * SPDX-License-Identifier: BSD-3-Clause */ package org.eclipse.jgit.api; @@ -173,15 +144,22 @@ public class EolRepositoryTest extends RepositoryTestCase { private DirCache dirCache; + private boolean isDefaultCrLf() { + String eol = mockSystemReader.getProperty("line.separator"); + return "\r\n".equals(eol); + } + @Test public void testDefaultSetup() throws Exception { // for EOL to work, the text attribute must be set setupGitAndDoHardReset(null, null, null, null, "* text=auto"); collectRepositoryState(); assertEquals("text=auto", entryCRLF.attrs); - checkEntryContent(entryCRLF, CONTENT_LF, CONTENT_LF); - checkEntryContent(entryLF, CONTENT_LF, CONTENT_LF); - checkEntryContent(entryMixed, CONTENT_LF, CONTENT_LF); + // eol=native is the default! + String expected = isDefaultCrLf() ? CONTENT_CRLF : CONTENT_LF; + checkEntryContent(entryCRLF, expected, CONTENT_LF); + checkEntryContent(entryLF, expected, CONTENT_LF); + checkEntryContent(entryMixed, expected, CONTENT_LF); } public void checkEntryContent(ActualEntry entry, String fileContent, @@ -199,9 +177,11 @@ public class EolRepositoryTest extends RepositoryTestCase { setupGitAndDoHardReset(AutoCRLF.FALSE, null, null, null, "* text=auto"); collectRepositoryState(); assertEquals("text=auto", entryCRLF.attrs); - checkEntryContent(entryCRLF, CONTENT_LF, CONTENT_LF); - checkEntryContent(entryLF, CONTENT_LF, CONTENT_LF); - checkEntryContent(entryMixed, CONTENT_LF, CONTENT_LF); + // eol=native is the default! + String expected = isDefaultCrLf() ? CONTENT_CRLF : CONTENT_LF; + checkEntryContent(entryCRLF, expected, CONTENT_LF); + checkEntryContent(entryLF, expected, CONTENT_LF); + checkEntryContent(entryMixed, expected, CONTENT_LF); } @Test @@ -250,34 +230,24 @@ public class EolRepositoryTest extends RepositoryTestCase { @Test public void test_ConfigEOL_native_windows() throws Exception { - String origLineSeparator = System.getProperty("line.separator", "\n"); - System.setProperty("line.separator", "\r\n"); - try { - // for EOL to work, the text attribute must be set - setupGitAndDoHardReset(null, EOL.NATIVE, "*.txt text", null, null); - collectRepositoryState(); - assertEquals("text", entryCRLF.attrs); - checkEntryContent(entryCRLF, CONTENT_LF, CONTENT_LF); - checkEntryContent(entryLF, CONTENT_LF, CONTENT_LF); - } finally { - System.setProperty("line.separator", origLineSeparator); - } + mockSystemReader.setWindows(); + // for EOL to work, the text attribute must be set + setupGitAndDoHardReset(null, EOL.NATIVE, "*.txt text", null, null); + collectRepositoryState(); + assertEquals("text", entryCRLF.attrs); + checkEntryContent(entryCRLF, CONTENT_CRLF, CONTENT_LF); + checkEntryContent(entryLF, CONTENT_CRLF, CONTENT_LF); } @Test public void test_ConfigEOL_native_xnix() throws Exception { - String origLineSeparator = System.getProperty("line.separator", "\n"); - System.setProperty("line.separator", "\n"); - try { - // for EOL to work, the text attribute must be set - setupGitAndDoHardReset(null, EOL.NATIVE, "*.txt text", null, null); - collectRepositoryState(); - assertEquals("text", entryCRLF.attrs); - checkEntryContent(entryCRLF, CONTENT_LF, CONTENT_LF); - checkEntryContent(entryLF, CONTENT_LF, CONTENT_LF); - } finally { - System.setProperty("line.separator", origLineSeparator); - } + mockSystemReader.setUnix(); + // for EOL to work, the text attribute must be set + setupGitAndDoHardReset(null, EOL.NATIVE, "*.txt text", null, null); + collectRepositoryState(); + assertEquals("text", entryCRLF.attrs); + checkEntryContent(entryCRLF, CONTENT_LF, CONTENT_LF); + checkEntryContent(entryLF, CONTENT_LF, CONTENT_LF); } @Test @@ -297,9 +267,10 @@ public class EolRepositoryTest extends RepositoryTestCase { setupGitAndDoHardReset(AutoCRLF.FALSE, EOL.NATIVE, "*.txt text", null, null); collectRepositoryState(); assertEquals("text", entryCRLF.attrs); - checkEntryContent(entryCRLF, CONTENT_LF, CONTENT_LF); - checkEntryContent(entryLF, CONTENT_LF, CONTENT_LF); - checkEntryContent(entryMixed, CONTENT_LF, CONTENT_LF); + String expected = isDefaultCrLf() ? CONTENT_CRLF : CONTENT_LF; + checkEntryContent(entryCRLF, expected, CONTENT_LF); + checkEntryContent(entryLF, expected, CONTENT_LF); + checkEntryContent(entryMixed, expected, CONTENT_LF); } @Test @@ -524,9 +495,12 @@ public class EolRepositoryTest extends RepositoryTestCase { // info overrides all collectRepositoryState(); assertEquals("text", entryCRLF.attrs); - checkEntryContent(entryCRLF, CONTENT_LF, CONTENT_LF); - checkEntryContent(entryLF, CONTENT_LF, CONTENT_LF); - checkEntryContent(entryMixed, CONTENT_LF, CONTENT_LF); + // !eol means unspecified, so use the default of core.eol, which is + // native. + String expected = isDefaultCrLf() ? CONTENT_CRLF : CONTENT_LF; + checkEntryContent(entryCRLF, expected, CONTENT_LF); + checkEntryContent(entryLF, expected, CONTENT_LF); + checkEntryContent(entryMixed, expected, CONTENT_LF); } @Test diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/FetchAndPullCommandsRecurseSubmodulesTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/FetchAndPullCommandsRecurseSubmodulesTest.java index 36ba7ce5ac..9ea64efc64 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/FetchAndPullCommandsRecurseSubmodulesTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/FetchAndPullCommandsRecurseSubmodulesTest.java @@ -259,7 +259,8 @@ public class FetchAndPullCommandsRecurseSubmodulesTest extends RepositoryTestCas // the commit that was created try (SubmoduleWalk w = SubmoduleWalk.forIndex(git.getRepository())) { assertTrue(w.next()); - try (Git g = new Git(w.getRepository())) { + try (Repository repository = w.getRepository(); + Git g = new Git(repository)) { g.fetch().setRemote(REMOTE).setRefSpecs(REFSPEC).call(); g.reset().setMode(ResetType.HARD).setRef(commit1.name()).call(); } 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 6479d157eb..3ec454cfc3 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 @@ -77,6 +77,26 @@ public class FetchCommandTest extends RepositoryTestCase { } @Test + public void testFetchHasRefLogForRemoteRef() throws Exception { + // create an initial commit SHA1 for the default branch + ObjectId defaultBranchSha1 = remoteGit.commit() + .setMessage("initial commit").call().getId(); + + git.fetch().setRemote("test") + .setRefSpecs("refs/heads/*:refs/remotes/origin/*").call(); + + List<Ref> allFetchedRefs = git.getRepository().getRefDatabase() + .getRefs(); + assertEquals(allFetchedRefs.size(), 1); + Ref remoteRef = allFetchedRefs.get(0); + + assertTrue(remoteRef.getName().startsWith(Constants.R_REMOTES)); + assertEquals(defaultBranchSha1, remoteRef.getObjectId()); + assertNotNull(git.getRepository().getReflogReader(remoteRef.getName()) + .getLastEntry()); + } + + @Test public void testForcedFetch() throws Exception { remoteGit.commit().setMessage("commit").call(); remoteGit.commit().setMessage("commit2").call(); @@ -96,6 +116,53 @@ public class FetchCommandTest extends RepositoryTestCase { } @Test + public void testFetchSimpleNegativeRefSpec() throws Exception { + remoteGit.commit().setMessage("commit").call(); + + FetchResult res = git.fetch().setRemote("test") + .setRefSpecs("refs/heads/master:refs/heads/test", + "^:refs/heads/test") + .call(); + assertNull(res.getTrackingRefUpdate("refs/heads/test")); + + res = git.fetch().setRemote("test") + .setRefSpecs("refs/heads/master:refs/heads/test", + "^refs/heads/master") + .call(); + assertNull(res.getTrackingRefUpdate("refs/heads/test")); + } + + @Test + public void negativeRefSpecFilterBySource() throws Exception { + remoteGit.commit().setMessage("commit").call(); + remoteGit.branchCreate().setName("test").call(); + remoteGit.commit().setMessage("commit1").call(); + remoteGit.branchCreate().setName("dev").call(); + + FetchResult res = git.fetch().setRemote("test") + .setRefSpecs("refs/*:refs/origins/*", "^refs/*/test") + .call(); + assertNotNull(res.getTrackingRefUpdate("refs/origins/heads/master")); + assertNull(res.getTrackingRefUpdate("refs/origins/heads/test")); + assertNotNull(res.getTrackingRefUpdate("refs/origins/heads/dev")); + } + + @Test + public void negativeRefSpecFilterByDestination() throws Exception { + remoteGit.commit().setMessage("commit").call(); + remoteGit.branchCreate().setName("meta").call(); + remoteGit.commit().setMessage("commit1").call(); + remoteGit.branchCreate().setName("data").call(); + + FetchResult res = git.fetch().setRemote("test") + .setRefSpecs("refs/*:refs/secret/*", "^:refs/secret/*/meta") + .call(); + assertNotNull(res.getTrackingRefUpdate("refs/secret/heads/master")); + assertNull(res.getTrackingRefUpdate("refs/secret/heads/meta")); + assertNotNull(res.getTrackingRefUpdate("refs/secret/heads/data")); + } + + @Test public void fetchAddsBranches() throws Exception { final String branch1 = "b1"; final String branch2 = "b2"; diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/LsRemoteCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/LsRemoteCommandTest.java index 12ec2aae57..05af175cfa 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/LsRemoteCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/LsRemoteCommandTest.java @@ -21,6 +21,8 @@ import org.eclipse.jgit.junit.RepositoryTestCase; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.lib.RefUpdate; +import org.eclipse.jgit.lib.StoredConfig; +import org.eclipse.jgit.util.SystemReader; import org.junit.Test; public class LsRemoteCommandTest extends RepositoryTestCase { @@ -107,6 +109,20 @@ public class LsRemoteCommandTest extends RepositoryTestCase { } @Test + public void testLsRemoteWithoutLocalRepositoryUrlInsteadOf() + throws Exception { + String uri = fileUri(); + StoredConfig userConfig = SystemReader.getInstance().getUserConfig(); + userConfig.load(); + userConfig.setString("url", uri, "insteadOf", "file:///foo"); + userConfig.save(); + Collection<Ref> refs = Git.lsRemoteRepository().setRemote("file:///foo") + .setHeads(true).call(); + assertNotNull(refs); + assertEquals(2, refs.size()); + } + + @Test public void testLsRemoteWithSymRefs() throws Exception { File directory = createTempDirectory("testRepository"); CloneCommand command = Git.cloneRepository(); 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 bc4e9405ea..917b6c3297 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 @@ -36,6 +36,7 @@ import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.RepositoryState; import org.eclipse.jgit.lib.Sets; +import org.eclipse.jgit.lib.StoredConfig; import org.eclipse.jgit.merge.ContentMergeStrategy; import org.eclipse.jgit.merge.MergeStrategy; import org.eclipse.jgit.merge.ResolveMerger.MergeFailureReason; @@ -554,7 +555,7 @@ public class MergeCommandTest extends RepositoryTestCase { git.merge().include(sideBranch) .setStrategy(MergeStrategy.RESOLVE).call(); - assertEquals("Merge branch 'side'\n\nConflicts:\n\ta\n", + assertEquals("Merge branch 'side'\n\n# Conflicts:\n#\ta\n", db.readMergeCommitMsg()); } @@ -1787,7 +1788,7 @@ public class MergeCommandTest extends RepositoryTestCase { + dateFormatter.formatDate(third .getAuthorIdent()) + "\n\n\tthird commit\n", db.readSquashCommitMsg()); - assertEquals("\nConflicts:\n\tfile2\n", db.readMergeCommitMsg()); + assertEquals("\n# Conflicts:\n#\tfile2\n", db.readMergeCommitMsg()); Status stat = git.status().call(); assertEquals(Sets.of("file2"), stat.getConflicting()); @@ -1881,6 +1882,7 @@ public class MergeCommandTest extends RepositoryTestCase { @Test public void testRecursiveMergeWithConflict() throws Exception { try (TestRepository<Repository> db_t = new TestRepository<>(db)) { + db.incrementOpen(); BranchBuilder master = db_t.branch("master"); RevCommit m0 = master.commit() .add("f", "1\n2\n3\n4\n5\n6\n7\n8\n9\n").message("m0") @@ -2012,7 +2014,74 @@ public class MergeCommandTest extends RepositoryTestCase { git.merge().include(sideBranch).setStrategy(MergeStrategy.RESOLVE) .setMessage("user message").call(); - assertEquals("user message\n\nConflicts:\n\ta\n", + assertEquals("user message\n\n# Conflicts:\n#\ta\n", + db.readMergeCommitMsg()); + } + } + + @Test + public void testMergeConflictWithMessageAndCommentChar() 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(); + + createBranch(initialCommit, "refs/heads/side"); + checkoutBranch("refs/heads/side"); + + writeTrashFile("a", "1\na(side)\n3\n"); + git.add().addFilepattern("a").call(); + git.commit().setMessage("side").call(); + + checkoutBranch("refs/heads/master"); + + writeTrashFile("a", "1\na(main)\n3\n"); + git.add().addFilepattern("a").call(); + git.commit().setMessage("main").call(); + + StoredConfig config = db.getConfig(); + config.setString("core", null, "commentChar", "^"); + + Ref sideBranch = db.exactRef("refs/heads/side"); + + git.merge().include(sideBranch).setStrategy(MergeStrategy.RESOLVE) + .setMessage("user message").call(); + + assertEquals("user message\n\n^ Conflicts:\n^\ta\n", + db.readMergeCommitMsg()); + } + } + + @Test + public void testMergeConflictWithMessageAndCommentCharAuto() + 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(); + + createBranch(initialCommit, "refs/heads/side"); + checkoutBranch("refs/heads/side"); + + writeTrashFile("a", "1\na(side)\n3\n"); + git.add().addFilepattern("a").call(); + git.commit().setMessage("side").call(); + + checkoutBranch("refs/heads/master"); + + writeTrashFile("a", "1\na(main)\n3\n"); + git.add().addFilepattern("a").call(); + git.commit().setMessage("main").call(); + + StoredConfig config = db.getConfig(); + config.setString("core", null, "commentChar", "auto"); + + Ref sideBranch = db.exactRef("refs/heads/side"); + + git.merge().include(sideBranch).setStrategy(MergeStrategy.RESOLVE) + .setMessage("#user message").call(); + + assertEquals("#user message\n\n; Conflicts:\n;\ta\n", db.readMergeCommitMsg()); } } 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 9af77aa3e8..6a84f0a38d 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 @@ -567,6 +567,7 @@ public class PullCommandTest extends RepositoryTestCase { public void setUp() throws Exception { super.setUp(); dbTarget = createWorkRepository(); + addRepoToClose(dbTarget); source = new Git(db); target = new Git(dbTarget); 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 cce04f471b..e2d7923cee 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 @@ -323,6 +323,7 @@ public class PullCommandWithRebaseTest extends RepositoryTestCase { dbTarget = createWorkRepository(); source = new Git(db); target = new Git(dbTarget); + addRepoToClose(dbTarget); // put some file in the source repo sourceFile = new File(db.getWorkTree(), "SomeFile.txt"); 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 a786065561..6f7aa63edc 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 @@ -10,7 +10,9 @@ package org.eclipse.jgit.api; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -19,10 +21,13 @@ import java.io.IOException; import java.net.URISyntaxException; import java.util.Properties; +import org.eclipse.jgit.api.errors.DetachedHeadException; import org.eclipse.jgit.api.errors.GitAPIException; +import org.eclipse.jgit.api.errors.InvalidRefNameException; import org.eclipse.jgit.api.errors.JGitInternalException; import org.eclipse.jgit.api.errors.TransportException; import org.eclipse.jgit.errors.MissingObjectException; +import org.eclipse.jgit.errors.NoRemoteRepositoryException; import org.eclipse.jgit.hooks.PrePushHook; import org.eclipse.jgit.junit.JGitTestUtil; import org.eclipse.jgit.junit.RepositoryTestCase; @@ -32,6 +37,7 @@ import org.eclipse.jgit.lib.RefUpdate; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.StoredConfig; import org.eclipse.jgit.revwalk.RevCommit; +import org.eclipse.jgit.transport.PushConfig.PushDefault; import org.eclipse.jgit.transport.PushResult; import org.eclipse.jgit.transport.RefLeaseSpec; import org.eclipse.jgit.transport.RefSpec; @@ -50,6 +56,7 @@ public class PushCommandTest extends RepositoryTestCase { // create other repository Repository db2 = createWorkRepository(); + addRepoToClose(db2); final StoredConfig config2 = db2.getConfig(); // this tests that this config can be parsed properly @@ -289,6 +296,770 @@ public class PushCommandTest extends RepositoryTestCase { } /** + * Check that pushing from a detached HEAD without refspec throws a + * DetachedHeadException. + * + * @throws Exception + */ + @Test + public void testPushDefaultDetachedHead() throws Exception { + try (Git git = new Git(db); + Git git2 = new Git(createBareRepository())) { + final StoredConfig config = git.getRepository().getConfig(); + RemoteConfig remoteConfig = new RemoteConfig(config, "test"); + URIish uri = new URIish( + git2.getRepository().getDirectory().toURI().toURL()); + remoteConfig.addURI(uri); + remoteConfig.addFetchRefSpec( + new RefSpec("+refs/heads/*:refs/remotes/origin/*")); + remoteConfig.update(config); + config.save(); + + writeTrashFile("f", "content of f"); + git.add().addFilepattern("f").call(); + RevCommit commit = git.commit().setMessage("adding f").call(); + + git.checkout().setName("not-pushed").setCreateBranch(true).call(); + git.checkout().setName("branchtopush").setCreateBranch(true).call(); + git.checkout().setName(commit.getName()).call(); + String head = git.getRepository().getFullBranch(); + assertTrue(ObjectId.isId(head)); + assertEquals(commit.getName(), head); + assertThrows(DetachedHeadException.class, + () -> git.push().setRemote("test").call()); + } + } + + /** + * Check that push.default=nothing without refspec throws an + * InvalidRefNameException. + * + * @throws Exception + */ + @Test + public void testPushDefaultNothing() throws Exception { + try (Git git = new Git(db); + Git git2 = new Git(createBareRepository())) { + final StoredConfig config = git.getRepository().getConfig(); + RemoteConfig remoteConfig = new RemoteConfig(config, "test"); + URIish uri = new URIish( + git2.getRepository().getDirectory().toURI().toURL()); + remoteConfig.addURI(uri); + remoteConfig.addFetchRefSpec( + new RefSpec("+refs/heads/*:refs/remotes/origin/*")); + remoteConfig.update(config); + config.save(); + + writeTrashFile("f", "content of f"); + git.add().addFilepattern("f").call(); + git.commit().setMessage("adding f").call(); + + git.checkout().setName("not-pushed").setCreateBranch(true).call(); + git.checkout().setName("branchtopush").setCreateBranch(true).call(); + + assertEquals(null, + git2.getRepository().resolve("refs/heads/branchtopush")); + assertEquals(null, + git2.getRepository().resolve("refs/heads/not-pushed")); + assertEquals(null, + git2.getRepository().resolve("refs/heads/master")); + assertThrows(InvalidRefNameException.class, + () -> git.push().setRemote("test") + .setPushDefault(PushDefault.NOTHING).call()); + } + } + + /** + * Check that push.default=matching without refspec pushes all matching + * branches. + * + * @throws Exception + */ + @Test + public void testPushDefaultMatching() throws Exception { + try (Git git = new Git(db); + Git git2 = new Git(createBareRepository())) { + final StoredConfig config = git.getRepository().getConfig(); + RemoteConfig remoteConfig = new RemoteConfig(config, "test"); + URIish uri = new URIish( + git2.getRepository().getDirectory().toURI().toURL()); + remoteConfig.addURI(uri); + remoteConfig.addFetchRefSpec( + new RefSpec("+refs/heads/*:refs/remotes/origin/*")); + remoteConfig.update(config); + config.save(); + + writeTrashFile("f", "content of f"); + git.add().addFilepattern("f").call(); + RevCommit commit = git.commit().setMessage("adding f").call(); + + git.checkout().setName("not-pushed").setCreateBranch(true).call(); + git.checkout().setName("branchtopush").setCreateBranch(true).call(); + + assertEquals(null, + git2.getRepository().resolve("refs/heads/branchtopush")); + assertEquals(null, + git2.getRepository().resolve("refs/heads/not-pushed")); + assertEquals(null, + git2.getRepository().resolve("refs/heads/master")); + // push master and branchtopush + git.push().setRemote("test").setRefSpecs( + new RefSpec("refs/heads/master:refs/heads/master"), + new RefSpec( + "refs/heads/branchtopush:refs/heads/branchtopush")) + .call(); + assertEquals(commit.getId(), + git2.getRepository().resolve("refs/heads/master")); + assertEquals(commit.getId(), + git2.getRepository().resolve("refs/heads/branchtopush")); + assertEquals(null, + git2.getRepository().resolve("refs/heads/not-pushed")); + // Create two different commits on these two branches + writeTrashFile("b", "on branchtopush"); + git.add().addFilepattern("b").call(); + RevCommit bCommit = git.commit().setMessage("on branchtopush") + .call(); + git.checkout().setName("master").call(); + writeTrashFile("m", "on master"); + git.add().addFilepattern("m").call(); + RevCommit mCommit = git.commit().setMessage("on master").call(); + // Now push with mode "matching": should push both branches. + Iterable<PushResult> result = git.push().setRemote("test") + .setPushDefault(PushDefault.MATCHING) + .call(); + int n = 0; + for (PushResult r : result) { + n++; + assertEquals(1, n); + assertEquals(2, r.getRemoteUpdates().size()); + for (RemoteRefUpdate update : r.getRemoteUpdates()) { + assertFalse(update.isMatching()); + assertTrue(update.getSrcRef() + .equals("refs/heads/branchtopush") + || update.getSrcRef().equals("refs/heads/master")); + assertEquals(RemoteRefUpdate.Status.OK, update.getStatus()); + } + } + assertEquals(bCommit.getId(), + git2.getRepository().resolve("refs/heads/branchtopush")); + assertEquals(null, + git2.getRepository().resolve("refs/heads/not-pushed")); + assertEquals(mCommit.getId(), + git2.getRepository().resolve("refs/heads/master")); + assertEquals(bCommit.getId(), git.getRepository() + .resolve("refs/remotes/origin/branchtopush")); + assertEquals(null, git.getRepository() + .resolve("refs/remotes/origin/not-pushed")); + assertEquals(mCommit.getId(), + git.getRepository().resolve("refs/remotes/origin/master")); + } + } + + /** + * Check that push.default=upstream without refspec pushes only the current + * branch to the configured upstream. + * + * @throws Exception + */ + @Test + public void testPushDefaultUpstream() throws Exception { + try (Git git = new Git(db); + Git git2 = new Git(createBareRepository())) { + StoredConfig config = git.getRepository().getConfig(); + RemoteConfig remoteConfig = new RemoteConfig(config, "test"); + URIish uri = new URIish( + git2.getRepository().getDirectory().toURI().toURL()); + remoteConfig.addURI(uri); + remoteConfig.addFetchRefSpec( + new RefSpec("+refs/heads/*:refs/remotes/origin/*")); + remoteConfig.update(config); + config.save(); + + writeTrashFile("f", "content of f"); + git.add().addFilepattern("f").call(); + RevCommit commit = git.commit().setMessage("adding f").call(); + + git.checkout().setName("not-pushed").setCreateBranch(true).call(); + git.checkout().setName("branchtopush").setCreateBranch(true).call(); + + config = git.getRepository().getConfig(); + config.setString("branch", "branchtopush", "remote", "test"); + config.setString("branch", "branchtopush", "merge", + "refs/heads/upstreambranch"); + config.save(); + + assertEquals(null, + git2.getRepository().resolve("refs/heads/branchtopush")); + assertEquals(null, + git2.getRepository().resolve("refs/heads/upstreambranch")); + assertEquals(null, + git2.getRepository().resolve("refs/heads/not-pushed")); + assertEquals(null, + git2.getRepository().resolve("refs/heads/master")); + git.push().setRemote("test").setPushDefault(PushDefault.UPSTREAM) + .call(); + assertEquals(null, + git2.getRepository().resolve("refs/heads/branchtopush")); + assertEquals(commit.getId(), + git2.getRepository().resolve("refs/heads/upstreambranch")); + assertEquals(null, + git2.getRepository().resolve("refs/heads/not-pushed")); + assertEquals(null, + git2.getRepository().resolve("refs/heads/master")); + assertEquals(commit.getId(), git.getRepository() + .resolve("refs/remotes/origin/upstreambranch")); + assertEquals(null, git.getRepository() + .resolve("refs/remotes/origin/branchtopush")); + } + } + + /** + * Check that push.default=upstream without refspec throws an + * InvalidRefNameException if the current branch has no upstream. + * + * @throws Exception + */ + @Test + public void testPushDefaultUpstreamNoTracking() throws Exception { + try (Git git = new Git(db); + Git git2 = new Git(createBareRepository())) { + StoredConfig config = git.getRepository().getConfig(); + RemoteConfig remoteConfig = new RemoteConfig(config, "test"); + URIish uri = new URIish( + git2.getRepository().getDirectory().toURI().toURL()); + remoteConfig.addURI(uri); + remoteConfig.addFetchRefSpec( + new RefSpec("+refs/heads/*:refs/remotes/origin/*")); + remoteConfig.update(config); + config.save(); + + writeTrashFile("f", "content of f"); + git.add().addFilepattern("f").call(); + git.commit().setMessage("adding f").call(); + + git.checkout().setName("not-pushed").setCreateBranch(true).call(); + git.checkout().setName("branchtopush").setCreateBranch(true).call(); + + config = git.getRepository().getConfig(); + config.setString("branch", "branchtopush", "remote", "test"); + config.save(); + + assertThrows(InvalidRefNameException.class, + () -> git.push().setRemote("test") + .setPushDefault(PushDefault.UPSTREAM).call()); + } + } + + /** + * Check that push.default=upstream without refspec throws an + * InvalidRefNameException if the push remote is not the same as the fetch + * remote. + * + * @throws Exception + */ + @Test + public void testPushDefaultUpstreamTriangular() throws Exception { + try (Git git = new Git(db); + Git git2 = new Git(createBareRepository())) { + StoredConfig config = git.getRepository().getConfig(); + RemoteConfig remoteConfig = new RemoteConfig(config, "test"); + URIish uri = new URIish( + git2.getRepository().getDirectory().toURI().toURL()); + remoteConfig.addURI(uri); + remoteConfig.addFetchRefSpec( + new RefSpec("+refs/heads/*:refs/remotes/origin/*")); + remoteConfig.update(config); + config.save(); + + writeTrashFile("f", "content of f"); + git.add().addFilepattern("f").call(); + git.commit().setMessage("adding f").call(); + + git.checkout().setName("not-pushed").setCreateBranch(true).call(); + git.checkout().setName("branchtopush").setCreateBranch(true).call(); + + config = git.getRepository().getConfig(); + // Don't configure a remote; it'll default to "origin". + config.setString("branch", "branchtopush", "merge", + "upstreambranch"); + config.save(); + + assertThrows(InvalidRefNameException.class, + () -> git.push().setRemote("test") + .setPushDefault(PushDefault.UPSTREAM).call()); + } + } + + /** + * Check that push.default=simple without refspec pushes only the current + * branch to the configured upstream name. + * + * @throws Exception + */ + @Test + public void testPushDefaultSimple() throws Exception { + try (Git git = new Git(db); + Git git2 = new Git(createBareRepository())) { + StoredConfig config = git.getRepository().getConfig(); + RemoteConfig remoteConfig = new RemoteConfig(config, "test"); + URIish uri = new URIish( + git2.getRepository().getDirectory().toURI().toURL()); + remoteConfig.addURI(uri); + remoteConfig.addFetchRefSpec( + new RefSpec("+refs/heads/*:refs/remotes/origin/*")); + remoteConfig.update(config); + config.save(); + + writeTrashFile("f", "content of f"); + git.add().addFilepattern("f").call(); + RevCommit commit = git.commit().setMessage("adding f").call(); + + git.checkout().setName("not-pushed").setCreateBranch(true).call(); + git.checkout().setName("branchtopush").setCreateBranch(true).call(); + + config = git.getRepository().getConfig(); + config.setString("branch", "branchtopush", "remote", "test"); + config.setString("branch", "branchtopush", "merge", + "refs/heads/branchtopush"); + config.save(); + + assertEquals(null, + git2.getRepository().resolve("refs/heads/branchtopush")); + assertEquals(null, + git2.getRepository().resolve("refs/heads/not-pushed")); + assertEquals(null, + git2.getRepository().resolve("refs/heads/master")); + git.push().setRemote("test").setPushDefault(PushDefault.SIMPLE) + .call(); + assertEquals(commit.getId(), + git2.getRepository().resolve("refs/heads/branchtopush")); + assertEquals(null, + git2.getRepository().resolve("refs/heads/not-pushed")); + assertEquals(null, + git2.getRepository().resolve("refs/heads/master")); + assertEquals(commit.getId(), git.getRepository() + .resolve("refs/remotes/origin/branchtopush")); + } + } + + /** + * Check that push.default=simple without refspec pushes only the current + * branch to a branch with the same name in a triangular workflow. + * + * @throws Exception + */ + @Test + public void testPushDefaultSimpleTriangular() throws Exception { + try (Git git = new Git(db); + Git git2 = new Git(createBareRepository())) { + StoredConfig config = git.getRepository().getConfig(); + RemoteConfig remoteConfig = new RemoteConfig(config, "test"); + URIish uri = new URIish( + git2.getRepository().getDirectory().toURI().toURL()); + remoteConfig.addURI(uri); + remoteConfig.addFetchRefSpec( + new RefSpec("+refs/heads/*:refs/remotes/origin/*")); + remoteConfig.update(config); + config.save(); + + writeTrashFile("f", "content of f"); + git.add().addFilepattern("f").call(); + RevCommit commit = git.commit().setMessage("adding f").call(); + + git.checkout().setName("not-pushed").setCreateBranch(true).call(); + git.checkout().setName("branchtopush").setCreateBranch(true).call(); + + config = git.getRepository().getConfig(); + // Don't set remote, it'll default to "origin". Configure a + // different branch name; should be ignored. + config.setString("branch", "branchtopush", "merge", + "refs/heads/upstreambranch"); + config.save(); + + assertEquals(null, + git2.getRepository().resolve("refs/heads/branchtopush")); + assertEquals(null, + git2.getRepository().resolve("refs/heads/upstreambranch")); + assertEquals(null, + git2.getRepository().resolve("refs/heads/not-pushed")); + assertEquals(null, + git2.getRepository().resolve("refs/heads/master")); + git.push().setRemote("test").setPushDefault(PushDefault.SIMPLE) + .call(); + assertEquals(commit.getId(), + git2.getRepository().resolve("refs/heads/branchtopush")); + assertEquals(null, + git2.getRepository().resolve("refs/heads/upstreambranch")); + assertEquals(null, + git2.getRepository().resolve("refs/heads/not-pushed")); + assertEquals(null, + git2.getRepository().resolve("refs/heads/master")); + assertEquals(commit.getId(), git.getRepository() + .resolve("refs/remotes/origin/branchtopush")); + } + } + + /** + * Check that push.default=simple without refspec throws an + * InvalidRefNameException if the current branch has no upstream. + * + * @throws Exception + */ + @Test + public void testPushDefaultSimpleNoTracking() throws Exception { + try (Git git = new Git(db); + Git git2 = new Git(createBareRepository())) { + StoredConfig config = git.getRepository().getConfig(); + RemoteConfig remoteConfig = new RemoteConfig(config, "test"); + URIish uri = new URIish( + git2.getRepository().getDirectory().toURI().toURL()); + remoteConfig.addURI(uri); + remoteConfig.addFetchRefSpec( + new RefSpec("+refs/heads/*:refs/remotes/origin/*")); + remoteConfig.update(config); + config.save(); + + writeTrashFile("f", "content of f"); + git.add().addFilepattern("f").call(); + git.commit().setMessage("adding f").call(); + + git.checkout().setName("not-pushed").setCreateBranch(true).call(); + git.checkout().setName("branchtopush").setCreateBranch(true).call(); + + config = git.getRepository().getConfig(); + config.setString("branch", "branchtopush", "remote", "test"); + config.save(); + + assertThrows(InvalidRefNameException.class, + () -> git.push().setRemote("test") + .setPushDefault(PushDefault.SIMPLE).call()); + } + } + + /** + * Check that push.default=simple without refspec throws an + * InvalidRefNameException if the current branch has an upstream with a + * different name. + * + * @throws Exception + */ + @Test + public void testPushDefaultSimpleDifferentTracking() throws Exception { + try (Git git = new Git(db); + Git git2 = new Git(createBareRepository())) { + StoredConfig config = git.getRepository().getConfig(); + RemoteConfig remoteConfig = new RemoteConfig(config, "test"); + URIish uri = new URIish( + git2.getRepository().getDirectory().toURI().toURL()); + remoteConfig.addURI(uri); + remoteConfig.addFetchRefSpec( + new RefSpec("+refs/heads/*:refs/remotes/origin/*")); + remoteConfig.update(config); + config.save(); + + writeTrashFile("f", "content of f"); + git.add().addFilepattern("f").call(); + git.commit().setMessage("adding f").call(); + + git.checkout().setName("not-pushed").setCreateBranch(true).call(); + git.checkout().setName("branchtopush").setCreateBranch(true).call(); + + config = git.getRepository().getConfig(); + config.setString("branch", "branchtopush", "remote", "test"); + config.setString("branch", "branchtopush", "merge", + "refs/heads/upstreambranch"); + config.save(); + + assertThrows(InvalidRefNameException.class, + () -> git.push().setRemote("test") + .setPushDefault(PushDefault.SIMPLE).call()); + } + } + + /** + * Check that if no PushDefault is set, the value is read from the git + * config. + * + * @throws Exception + */ + @Test + public void testPushDefaultFromConfig() throws Exception { + try (Git git = new Git(db); + Git git2 = new Git(createBareRepository())) { + StoredConfig config = git.getRepository().getConfig(); + RemoteConfig remoteConfig = new RemoteConfig(config, "test"); + URIish uri = new URIish( + git2.getRepository().getDirectory().toURI().toURL()); + remoteConfig.addURI(uri); + remoteConfig.addFetchRefSpec( + new RefSpec("+refs/heads/*:refs/remotes/origin/*")); + remoteConfig.update(config); + config.setString("push", null, "default", "upstream"); + config.save(); + + writeTrashFile("f", "content of f"); + git.add().addFilepattern("f").call(); + RevCommit commit = git.commit().setMessage("adding f").call(); + + git.checkout().setName("not-pushed").setCreateBranch(true).call(); + git.checkout().setName("branchtopush").setCreateBranch(true).call(); + + config = git.getRepository().getConfig(); + config.setString("branch", "branchtopush", "remote", "test"); + config.setString("branch", "branchtopush", "merge", + "refs/heads/upstreambranch"); + config.save(); + + assertEquals(null, + git2.getRepository().resolve("refs/heads/branchtopush")); + assertEquals(null, + git2.getRepository().resolve("refs/heads/upstreambranch")); + assertEquals(null, + git2.getRepository().resolve("refs/heads/not-pushed")); + assertEquals(null, + git2.getRepository().resolve("refs/heads/master")); + PushCommand cmd = git.push(); + cmd.setRemote("test").setPushDefault(null).call(); + assertEquals(PushDefault.UPSTREAM, cmd.getPushDefault()); + assertEquals(null, + git2.getRepository().resolve("refs/heads/branchtopush")); + assertEquals(commit.getId(), + git2.getRepository().resolve("refs/heads/upstreambranch")); + assertEquals(null, + git2.getRepository().resolve("refs/heads/not-pushed")); + assertEquals(null, + git2.getRepository().resolve("refs/heads/master")); + assertEquals(commit.getId(), git.getRepository() + .resolve("refs/remotes/origin/upstreambranch")); + assertEquals(null, git.getRepository() + .resolve("refs/remotes/origin/branchtopush")); + } + } + + /** + * Check that if no PushDefault is set and none is set in the git config, it + * defaults to "simple". + * + * @throws Exception + */ + @Test + public void testPushDefaultFromConfigDefault() throws Exception { + try (Git git = new Git(db); + Git git2 = new Git(createBareRepository())) { + StoredConfig config = git.getRepository().getConfig(); + RemoteConfig remoteConfig = new RemoteConfig(config, "test"); + URIish uri = new URIish( + git2.getRepository().getDirectory().toURI().toURL()); + remoteConfig.addURI(uri); + remoteConfig.addFetchRefSpec( + new RefSpec("+refs/heads/*:refs/remotes/origin/*")); + remoteConfig.update(config); + config.save(); + + writeTrashFile("f", "content of f"); + git.add().addFilepattern("f").call(); + RevCommit commit = git.commit().setMessage("adding f").call(); + + git.checkout().setName("not-pushed").setCreateBranch(true).call(); + git.checkout().setName("branchtopush").setCreateBranch(true).call(); + + config = git.getRepository().getConfig(); + config.setString("branch", "branchtopush", "remote", "test"); + config.setString("branch", "branchtopush", "merge", + "refs/heads/branchtopush"); + config.save(); + + assertEquals(null, + git2.getRepository().resolve("refs/heads/branchtopush")); + assertEquals(null, + git2.getRepository().resolve("refs/heads/not-pushed")); + assertEquals(null, + git2.getRepository().resolve("refs/heads/master")); + PushCommand cmd = git.push(); + cmd.setRemote("test").setPushDefault(null).call(); + assertEquals(PushDefault.SIMPLE, cmd.getPushDefault()); + assertEquals(commit.getId(), + git2.getRepository().resolve("refs/heads/branchtopush")); + assertEquals(null, + git2.getRepository().resolve("refs/heads/not-pushed")); + assertEquals(null, + git2.getRepository().resolve("refs/heads/master")); + assertEquals(commit.getId(), git.getRepository() + .resolve("refs/remotes/origin/branchtopush")); + } + } + + /** + * Check that branch.<name>.pushRemote overrides anything else. + * + * @throws Exception + */ + @Test + public void testBranchPushRemote() throws Exception { + try (Git git = new Git(db); + Git git2 = new Git(createBareRepository())) { + StoredConfig config = git.getRepository().getConfig(); + RemoteConfig remoteConfig = new RemoteConfig(config, "test"); + URIish uri = new URIish( + git2.getRepository().getDirectory().toURI().toURL()); + remoteConfig.addURI(uri); + remoteConfig.addFetchRefSpec( + new RefSpec("+refs/heads/*:refs/remotes/origin/*")); + remoteConfig.update(config); + config.setString("remote", null, "pushDefault", "test"); + config.save(); + + writeTrashFile("f", "content of f"); + git.add().addFilepattern("f").call(); + git.commit().setMessage("adding f").call(); + + git.checkout().setName("not-pushed").setCreateBranch(true).call(); + git.checkout().setName("branchtopush").setCreateBranch(true).call(); + + config = git.getRepository().getConfig(); + config.setString("branch", "branchtopush", "remote", "test"); + config.setString("branch", "branchtopush", "pushremote", "origin"); + config.setString("branch", "branchtopush", "merge", + "refs/heads/branchtopush"); + config.save(); + + assertThrows(InvalidRefNameException.class, () -> git.push() + .setPushDefault(PushDefault.UPSTREAM).call()); + } + } + + /** + * Check that remote.pushDefault overrides branch.<name>.remote + * + * @throws Exception + */ + @Test + public void testRemotePushDefault() throws Exception { + try (Git git = new Git(db); + Git git2 = new Git(createBareRepository())) { + StoredConfig config = git.getRepository().getConfig(); + RemoteConfig remoteConfig = new RemoteConfig(config, "test"); + URIish uri = new URIish( + git2.getRepository().getDirectory().toURI().toURL()); + remoteConfig.addURI(uri); + remoteConfig.addFetchRefSpec( + new RefSpec("+refs/heads/*:refs/remotes/origin/*")); + remoteConfig.update(config); + config.setString("remote", null, "pushDefault", "origin"); + config.save(); + + writeTrashFile("f", "content of f"); + git.add().addFilepattern("f").call(); + git.commit().setMessage("adding f").call(); + + git.checkout().setName("not-pushed").setCreateBranch(true).call(); + git.checkout().setName("branchtopush").setCreateBranch(true).call(); + + config = git.getRepository().getConfig(); + config.setString("branch", "branchtopush", "remote", "test"); + config.setString("branch", "branchtopush", "merge", + "refs/heads/branchtopush"); + config.save(); + + assertThrows(InvalidRefNameException.class, () -> git.push() + .setPushDefault(PushDefault.UPSTREAM).call()); + } + } + + /** + * Check that ultimately we fall back to "origin". + * + * @throws Exception + */ + @Test + public void testDefaultRemote() throws Exception { + try (Git git = new Git(db); + Git git2 = new Git(createBareRepository())) { + StoredConfig config = git.getRepository().getConfig(); + RemoteConfig remoteConfig = new RemoteConfig(config, "test"); + URIish uri = new URIish( + git2.getRepository().getDirectory().toURI().toURL()); + remoteConfig.addURI(uri); + remoteConfig.addFetchRefSpec( + new RefSpec("+refs/heads/*:refs/remotes/origin/*")); + remoteConfig.update(config); + config.save(); + + writeTrashFile("f", "content of f"); + git.add().addFilepattern("f").call(); + git.commit().setMessage("adding f").call(); + + git.checkout().setName("not-pushed").setCreateBranch(true).call(); + git.checkout().setName("branchtopush").setCreateBranch(true).call(); + + config = git.getRepository().getConfig(); + config.setString("branch", "branchtopush", "merge", + "refs/heads/branchtopush"); + config.save(); + + PushCommand cmd = git.push().setPushDefault(PushDefault.UPSTREAM); + TransportException e = assertThrows(TransportException.class, + () -> cmd.call()); + assertEquals(NoRemoteRepositoryException.class, + e.getCause().getClass()); + assertEquals("origin", cmd.getRemote()); + } + } + + /** + * Check that a push without specifying a remote or mode or anything can + * succeed if the git config is correct. + * + * @throws Exception + */ + @Test + public void testDefaultPush() throws Exception { + try (Git git = new Git(db); + Git git2 = new Git(createBareRepository())) { + StoredConfig config = git.getRepository().getConfig(); + RemoteConfig remoteConfig = new RemoteConfig(config, "test"); + URIish uri = new URIish( + git2.getRepository().getDirectory().toURI().toURL()); + remoteConfig.addURI(uri); + remoteConfig.addFetchRefSpec( + new RefSpec("+refs/heads/*:refs/remotes/origin/*")); + remoteConfig.update(config); + config.save(); + + writeTrashFile("f", "content of f"); + git.add().addFilepattern("f").call(); + RevCommit commit = git.commit().setMessage("adding f").call(); + + git.checkout().setName("not-pushed").setCreateBranch(true).call(); + git.checkout().setName("branchtopush").setCreateBranch(true).call(); + + config = git.getRepository().getConfig(); + config.setString("branch", "branchtopush", "remote", "test"); + config.save(); + + assertEquals(null, + git2.getRepository().resolve("refs/heads/branchtopush")); + assertEquals(null, + git2.getRepository().resolve("refs/heads/not-pushed")); + assertEquals(null, + git2.getRepository().resolve("refs/heads/master")); + // Should use remote "test", push.default=current + PushCommand cmd = git.push(); + cmd.call(); + assertEquals("test", cmd.getRemote()); + assertEquals(PushDefault.CURRENT, cmd.getPushDefault()); + assertEquals(commit.getId(), + git2.getRepository().resolve("refs/heads/branchtopush")); + assertEquals(null, + git2.getRepository().resolve("refs/heads/not-pushed")); + assertEquals(null, + git2.getRepository().resolve("refs/heads/master")); + assertEquals(commit.getId(), git.getRepository() + .resolve("refs/remotes/origin/branchtopush")); + } + } + + /** * Check that missing refs don't cause errors during push * * @throws Exception @@ -297,6 +1068,7 @@ public class PushCommandTest extends RepositoryTestCase { public void testPushAfterGC() throws Exception { // create other repository Repository db2 = createWorkRepository(); + addRepoToClose(db2); // setup the first repository final StoredConfig config = db.getConfig(); @@ -360,6 +1132,7 @@ public class PushCommandTest extends RepositoryTestCase { // create other repository Repository db2 = createWorkRepository(); + addRepoToClose(db2); // setup the first repository final StoredConfig config = db.getConfig(); 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 86239023dc..d574e45f6f 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 @@ -30,6 +30,7 @@ import java.util.List; import org.eclipse.jgit.api.MergeResult.MergeStatus; import org.eclipse.jgit.api.RebaseCommand.InteractiveHandler; +import org.eclipse.jgit.api.RebaseCommand.InteractiveHandler2; import org.eclipse.jgit.api.RebaseCommand.Operation; import org.eclipse.jgit.api.RebaseResult.Status; import org.eclipse.jgit.api.errors.InvalidRebaseStepException; @@ -46,6 +47,7 @@ import org.eclipse.jgit.events.ChangeRecorder; import org.eclipse.jgit.events.ListenerHandle; import org.eclipse.jgit.junit.RepositoryTestCase; import org.eclipse.jgit.lib.AbbreviatedObjectId; +import org.eclipse.jgit.lib.CommitConfig.CleanupMode; import org.eclipse.jgit.lib.ConfigConstants; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.ObjectId; @@ -56,6 +58,7 @@ import org.eclipse.jgit.lib.RebaseTodoLine.Action; import org.eclipse.jgit.lib.RefUpdate; import org.eclipse.jgit.lib.ReflogEntry; import org.eclipse.jgit.lib.RepositoryState; +import org.eclipse.jgit.lib.StoredConfig; import org.eclipse.jgit.merge.MergeStrategy; import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevSort; @@ -2927,8 +2930,8 @@ public class RebaseCommandTest extends RepositoryTestCase { } } - @Test - public void testRebaseInteractiveFixupWithBlankLines() throws Exception { + private void simpleFixup(String firstMessage, String secondMessage) + throws Exception { // create file1 on master writeTrashFile(FILE1, FILE1); git.add().addFilepattern(FILE1).call(); @@ -2938,13 +2941,13 @@ public class RebaseCommandTest extends RepositoryTestCase { // create file2 on master writeTrashFile("file2", "file2"); git.add().addFilepattern("file2").call(); - git.commit().setMessage("Add file2").call(); + git.commit().setMessage(firstMessage).call(); assertTrue(new File(db.getWorkTree(), "file2").exists()); // update FILE1 on master writeTrashFile(FILE1, "blah"); git.add().addFilepattern(FILE1).call(); - git.commit().setMessage("updated file1 on master\n\nsome text").call(); + git.commit().setMessage(secondMessage).call(); git.rebase().setUpstream("HEAD~2") .runInteractively(new InteractiveHandler() { @@ -2968,9 +2971,31 @@ public class RebaseCommandTest extends RepositoryTestCase { try (RevWalk walk = new RevWalk(db)) { ObjectId headId = db.resolve(Constants.HEAD); RevCommit headCommit = walk.parseCommit(headId); - assertEquals("Add file2", - headCommit.getFullMessage()); + assertEquals(firstMessage, headCommit.getFullMessage()); } + + } + + @Test + public void testRebaseInteractiveFixupWithBlankLines() throws Exception { + simpleFixup("Add file2", "updated file1 on master\n\nsome text"); + } + + @Test + public void testRebaseInteractiveFixupWithBlankLines2() throws Exception { + simpleFixup("Add file2\n\nBody\n", + "updated file1 on master\n\nsome text"); + } + + @Test + public void testRebaseInteractiveFixupWithHash() throws Exception { + simpleFixup("#Add file2", "updated file1 on master"); + } + + @Test + public void testRebaseInteractiveFixupWithHash2() throws Exception { + simpleFixup("#Add file2\n\nHeader has hash\n", + "#updated file1 on master"); } @Test(expected = InvalidRebaseStepException.class) @@ -3388,6 +3413,99 @@ public class RebaseCommandTest extends RepositoryTestCase { } + @Test + public void testInteractiveRebaseSquashFixupSequence() throws Exception { + // create file1, add and commit + writeTrashFile(FILE1, "file1"); + git.add().addFilepattern(FILE1).call(); + git.commit().setMessage("commit1").call(); + + // modify file1, add and commit + writeTrashFile(FILE1, "modified file1"); + git.add().addFilepattern(FILE1).call(); + git.commit().setMessage("commit2").call(); + + // modify file1, add and commit + writeTrashFile(FILE1, "modified file1 a second time"); + git.add().addFilepattern(FILE1).call(); + // Make it difficult; use git standard comment characters in the commit + // messages + git.commit().setMessage("#commit3").call(); + + // modify file1, add and commit + writeTrashFile(FILE1, "modified file1 a third time"); + git.add().addFilepattern(FILE1).call(); + git.commit().setMessage("@commit4").call(); + + // modify file1, add and commit + writeTrashFile(FILE1, "modified file1 a fourth time"); + git.add().addFilepattern(FILE1).call(); + git.commit().setMessage(";commit5").call(); + + StoredConfig config = git.getRepository().getConfig(); + config.setString("core", null, "commentChar", "auto"); + // With "auto", we should end up with '@' being used as comment + // character (commit4 is skipped, so it should not advance the + // character). + RebaseResult result = git.rebase().setUpstream("HEAD~4") + .runInteractively(new InteractiveHandler2() { + + @Override + public void prepareSteps(List<RebaseTodoLine> steps) { + try { + steps.get(0).setAction(Action.PICK); + steps.get(1).setAction(Action.SQUASH); + steps.get(2).setAction(Action.FIXUP); + steps.get(3).setAction(Action.SQUASH); + } catch (IllegalTodoFileModification e) { + fail("unexpected exception: " + e); + } + } + + @Override + public String modifyCommitMessage(String commit) { + fail("should not be called"); + return commit; + } + + @Override + public ModifyResult editCommitMessage(String message, + CleanupMode mode, char commentChar) { + assertEquals('@', commentChar); + assertEquals("@ This is a combination of 4 commits.\n" + + "@ The first commit's message is:\n" + + "commit2\n" + + "@ This is the 2nd commit message:\n" + + "#commit3\n" + + "@ The 3rd commit message will be skipped:\n" + + "@ @commit4\n" + + "@ This is the 4th commit message:\n" + + ";commit5", message); + return new ModifyResult() { + + @Override + public String getMessage() { + return message; + } + + @Override + public CleanupMode getCleanupMode() { + return mode; + } + + @Override + public boolean shouldAddChangeId() { + return false; + } + }; + } + }).call(); + assertEquals(Status.OK, result.getStatus()); + Iterator<RevCommit> logIterator = git.log().all().call().iterator(); + String actualCommitMsg = logIterator.next().getFullMessage(); + assertEquals("commit2\n#commit3\n;commit5", actualCommitMsg); + } + private File getTodoFile() { File todoFile = new File(db.getDirectory(), GIT_REBASE_TODO); return todoFile; 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 cfa8486ac5..1c7b8d13a8 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 @@ -9,6 +9,7 @@ */ package org.eclipse.jgit.api; +import static org.eclipse.jgit.lib.Constants.OBJECT_ID_ABBREV_STRING_LENGTH; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; @@ -166,7 +167,9 @@ public class RevertCommandTest extends RepositoryTestCase { checkFile(new File(db.getWorkTree(), "a"), "first\n" + "<<<<<<< master\n" + "second\n" + "third\n" + "=======\n" - + ">>>>>>> " + secondCommit.getId().abbreviate(7).name() + + ">>>>>>> " + + secondCommit.getId() + .abbreviate(OBJECT_ID_ABBREV_STRING_LENGTH).name() + " add second\n"); Iterator<RevCommit> history = git.log().call().iterator(); RevCommit revertCommit = history.next(); @@ -232,7 +235,7 @@ public class RevertCommandTest extends RepositoryTestCase { assertTrue(new File(db.getDirectory(), Constants.MERGE_MSG).exists()); assertEquals("Revert \"" + sideCommit.getShortMessage() + "\"\n\nThis reverts commit " + sideCommit.getId().getName() - + ".\n\nConflicts:\n\ta\n", + + ".\n\n# Conflicts:\n#\ta\n", db.readMergeCommitMsg()); assertTrue(new File(db.getDirectory(), Constants.REVERT_HEAD) .exists()); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/SecurityManagerMissingPermissionsTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/SecurityManagerMissingPermissionsTest.java index a07f37009e..d0fbdbd090 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/SecurityManagerMissingPermissionsTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/SecurityManagerMissingPermissionsTest.java @@ -13,17 +13,15 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; -import java.io.StringWriter; +import java.io.PrintStream; import java.nio.file.Files; import java.nio.file.Path; import java.security.Policy; import java.util.Collections; -import org.apache.log4j.Logger; -import org.apache.log4j.PatternLayout; -import org.apache.log4j.WriterAppender; import org.eclipse.jgit.junit.RepositoryTestCase; import org.eclipse.jgit.util.FileUtils; import org.junit.After; @@ -38,25 +36,21 @@ public class SecurityManagerMissingPermissionsTest extends RepositoryTestCase { /** * Collects all logging sent to the logging system. */ - private final StringWriter errorOutputWriter = new StringWriter(); - - /** - * Appender to intercept all logging sent to the logging system. - */ - private WriterAppender appender; + private final ByteArrayOutputStream errorOutput = new ByteArrayOutputStream(); private SecurityManager originalSecurityManager; + private PrintStream defaultErrorOutput; + @Override @Before public void setUp() throws Exception { originalSecurityManager = System.getSecurityManager(); - appender = new WriterAppender( - new PatternLayout(PatternLayout.TTCC_CONVERSION_PATTERN), - errorOutputWriter); - - Logger.getRootLogger().addAppender(appender); + // slf4j-simple logs to System.err, redirect it to enable asserting + // logged errors + defaultErrorOutput = System.err; + System.setErr(new PrintStream(errorOutput)); refreshPolicyAllPermission(Policy.getPolicy()); System.setSecurityManager(new SecurityManager()); @@ -85,14 +79,14 @@ public class SecurityManagerMissingPermissionsTest extends RepositoryTestCase { addRepoToClose(git.getRepository()); - assertEquals("", errorOutputWriter.toString()); + assertEquals("", errorOutput.toString()); } @Override @After public void tearDown() throws Exception { System.setSecurityManager(originalSecurityManager); - Logger.getRootLogger().removeAppender(appender); + System.setErr(defaultErrorOutput); super.tearDown(); } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StatusCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StatusCommandTest.java index 5311edb0eb..19281f6c99 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StatusCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StatusCommandTest.java @@ -21,8 +21,10 @@ import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.api.errors.NoFilepatternException; import org.eclipse.jgit.errors.NoWorkTreeException; import org.eclipse.jgit.junit.RepositoryTestCase; +import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.Sets; import org.eclipse.jgit.storage.file.FileBasedConfig; +import org.eclipse.jgit.storage.file.FileRepositoryBuilder; import org.eclipse.jgit.util.FS; import org.junit.Test; @@ -181,4 +183,31 @@ public class StatusCommandTest extends RepositoryTestCase { } } + @Test + public void testNestedCommittedGitRepoAndPathFilter() throws Exception { + commitFile("file.txt", "file", "master"); + try (Repository inner = new FileRepositoryBuilder() + .setWorkTree(new File(db.getWorkTree(), "subgit")).build()) { + inner.create(); + writeTrashFile("subgit/sub.txt", "sub"); + try (Git outerGit = new Git(db); Git innerGit = new Git(inner)) { + innerGit.add().addFilepattern("sub.txt").call(); + innerGit.commit().setMessage("Inner commit").call(); + outerGit.add().addFilepattern("subgit").call(); + outerGit.commit().setMessage("Outer commit").call(); + assertTrue(innerGit.status().call().isClean()); + assertTrue(outerGit.status().call().isClean()); + writeTrashFile("subgit/sub.txt", "sub2"); + assertFalse(innerGit.status().call().isClean()); + assertFalse(outerGit.status().call().isClean()); + assertTrue( + outerGit.status().addPath("file.txt").call().isClean()); + assertTrue(outerGit.status().addPath("doesntexist").call() + .isClean()); + assertFalse( + outerGit.status().addPath("subgit").call().isClean()); + } + } + } + } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/AbstractRenameDetectionTestCase.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/AbstractRenameDetectionTestCase.java new file mode 100644 index 0000000000..a8967f27ec --- /dev/null +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/AbstractRenameDetectionTestCase.java @@ -0,0 +1,101 @@ +/* + * Copyright (C) 2022, Google Inc. and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Distribution License v. 1.0 which is available at + * https://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +package org.eclipse.jgit.diff; + +import static org.junit.Assert.assertEquals; + +import org.eclipse.jgit.diff.DiffEntry.ChangeType; +import org.eclipse.jgit.junit.RepositoryTestCase; +import org.eclipse.jgit.junit.TestRepository; +import org.eclipse.jgit.lib.AbbreviatedObjectId; +import org.eclipse.jgit.lib.FileMode; +import org.eclipse.jgit.lib.ObjectId; +import org.eclipse.jgit.lib.Repository; +import org.junit.Before; + +public abstract class AbstractRenameDetectionTestCase + extends RepositoryTestCase { + + protected static final String PATH_A = "src/A"; + + protected static final String PATH_B = "src/B"; + + protected static final String PATH_H = "src/H"; + + protected static final String PATH_Q = "src/Q"; + + protected TestRepository<Repository> testDb; + + @Override + @Before + public void setUp() throws Exception { + super.setUp(); + testDb = new TestRepository<>(db); + } + + protected ObjectId blob(String content) throws Exception { + return testDb.blob(content).copy(); + } + + protected static void assertRename(DiffEntry o, DiffEntry n, int score, + DiffEntry rename) { + assertEquals(ChangeType.RENAME, rename.getChangeType()); + + assertEquals(o.getOldPath(), rename.getOldPath()); + assertEquals(n.getNewPath(), rename.getNewPath()); + + assertEquals(o.getOldMode(), rename.getOldMode()); + assertEquals(n.getNewMode(), rename.getNewMode()); + + assertEquals(o.getOldId(), rename.getOldId()); + assertEquals(n.getNewId(), rename.getNewId()); + + assertEquals(score, rename.getScore()); + } + + protected static void assertCopy(DiffEntry o, DiffEntry n, int score, + DiffEntry copy) { + assertEquals(ChangeType.COPY, copy.getChangeType()); + + assertEquals(o.getOldPath(), copy.getOldPath()); + assertEquals(n.getNewPath(), copy.getNewPath()); + + assertEquals(o.getOldMode(), copy.getOldMode()); + assertEquals(n.getNewMode(), copy.getNewMode()); + + assertEquals(o.getOldId(), copy.getOldId()); + assertEquals(n.getNewId(), copy.getNewId()); + + assertEquals(score, copy.getScore()); + } + + protected static void assertAdd(String newName, ObjectId newId, + FileMode newMode, DiffEntry add) { + assertEquals(DiffEntry.DEV_NULL, add.oldPath); + assertEquals(DiffEntry.A_ZERO, add.oldId); + assertEquals(FileMode.MISSING, add.oldMode); + assertEquals(ChangeType.ADD, add.changeType); + assertEquals(newName, add.newPath); + assertEquals(AbbreviatedObjectId.fromObjectId(newId), add.newId); + assertEquals(newMode, add.newMode); + } + + protected static void assertDelete(String oldName, ObjectId oldId, + FileMode oldMode, DiffEntry delete) { + assertEquals(DiffEntry.DEV_NULL, delete.newPath); + assertEquals(DiffEntry.A_ZERO, delete.newId); + assertEquals(FileMode.MISSING, delete.newMode); + assertEquals(ChangeType.DELETE, delete.changeType); + assertEquals(oldName, delete.oldPath); + assertEquals(AbbreviatedObjectId.fromObjectId(oldId), delete.oldId); + assertEquals(oldMode, delete.oldMode); + } +} diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/FilteredRenameDetectorTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/FilteredRenameDetectorTest.java new file mode 100644 index 0000000000..bfda36db76 --- /dev/null +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/FilteredRenameDetectorTest.java @@ -0,0 +1,154 @@ +/* + * Copyright (C) 2022, Simeon Andreev and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Distribution License v. 1.0 which is available at + * https://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +package org.eclipse.jgit.diff; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertSame; + +import java.util.Arrays; +import java.util.List; +import org.eclipse.jgit.internal.diff.FilteredRenameDetector; +import org.eclipse.jgit.lib.ObjectId; +import org.eclipse.jgit.treewalk.filter.PathFilter; +import org.junit.Before; +import org.junit.Test; + +public class FilteredRenameDetectorTest extends AbstractRenameDetectionTestCase { + + private FilteredRenameDetector frd; + + @Override + @Before + public void setUp() throws Exception { + super.setUp(); + frd = new FilteredRenameDetector(db); + } + + @Test + public void testExactRename() throws Exception { + ObjectId foo = blob("foo"); + ObjectId bar = blob("bar"); + + DiffEntry a = DiffEntry.add(PATH_A, foo); + DiffEntry b = DiffEntry.delete(PATH_Q, foo); + + DiffEntry c = DiffEntry.add(PATH_H, bar); + DiffEntry d = DiffEntry.delete(PATH_B, bar); + + List<DiffEntry> changes = Arrays.asList(a, b, c, d); + PathFilter filter = PathFilter.create(PATH_A); + List<DiffEntry> entries = frd.compute(changes, filter); + assertEquals("Unexpected entries in: " + entries, 1, entries.size()); + assertRename(b, a, 100, entries.get(0)); + } + + @Test + public void testExactRename_multipleFilters() throws Exception { + ObjectId foo = blob("foo"); + ObjectId bar = blob("bar"); + + DiffEntry a = DiffEntry.add(PATH_A, foo); + DiffEntry b = DiffEntry.delete(PATH_Q, foo); + + DiffEntry c = DiffEntry.add(PATH_H, bar); + DiffEntry d = DiffEntry.delete(PATH_B, bar); + + List<DiffEntry> changes = Arrays.asList(a, b, c, d); + List<PathFilter> filters = Arrays.asList(PathFilter.create(PATH_A), + PathFilter.create(PATH_H)); + List<DiffEntry> entries = frd.compute(changes, filters); + assertEquals("Unexpected entries in: " + entries, 2, entries.size()); + assertRename(b, a, 100, entries.get(0)); + assertRename(d, c, 100, entries.get(1)); + } + + @Test + public void testInexactRename() throws Exception { + ObjectId aId = blob("foo\nbar\nbaz\nblarg\n"); + ObjectId bId = blob("foo\nbar\nbaz\nblah\n"); + DiffEntry a = DiffEntry.add(PATH_A, aId); + DiffEntry b = DiffEntry.delete(PATH_Q, bId); + + ObjectId cId = blob("some\nsort\nof\ntext\n"); + ObjectId dId = blob("completely\nunrelated\ntext\n"); + DiffEntry c = DiffEntry.add(PATH_B, cId); + DiffEntry d = DiffEntry.delete(PATH_H, dId); + + List<DiffEntry> changes = Arrays.asList(a, b, c, d); + PathFilter filter = PathFilter.create(PATH_A); + List<DiffEntry> entries = frd.compute(changes, filter); + assertEquals("Unexpected entries: " + entries, 1, entries.size()); + assertRename(b, a, 66, entries.get(0)); + } + + @Test + public void testInexactRename_multipleFilters() throws Exception { + ObjectId aId = blob("foo\nbar\nbaz\nblarg\n"); + ObjectId bId = blob("foo\nbar\nbaz\nblah\n"); + DiffEntry a = DiffEntry.add(PATH_A, aId); + DiffEntry b = DiffEntry.delete(PATH_Q, bId); + + ObjectId cId = blob("some\nsort\nof\ntext\n"); + ObjectId dId = blob("completely\nunrelated\ntext\n"); + DiffEntry c = DiffEntry.add(PATH_B, cId); + DiffEntry d = DiffEntry.delete(PATH_H, dId); + + List<DiffEntry> changes = Arrays.asList(a, b, c, d); + List<PathFilter> filters = Arrays.asList(PathFilter.create(PATH_A), + PathFilter.create(PATH_H)); + List<DiffEntry> entries = frd.compute(changes, filters); + assertEquals("Unexpected entries: " + entries, 2, entries.size()); + assertRename(b, a, 66, entries.get(0)); + assertSame(d, entries.get(1)); + } + + @Test + public void testNoRenames() throws Exception { + ObjectId aId = blob(""); + ObjectId bId = blob("blah1"); + ObjectId cId = blob(""); + ObjectId dId = blob("blah2"); + + DiffEntry a = DiffEntry.add(PATH_A, aId); + DiffEntry b = DiffEntry.delete(PATH_Q, bId); + + DiffEntry c = DiffEntry.add(PATH_H, cId); + DiffEntry d = DiffEntry.delete(PATH_B, dId); + + List<DiffEntry> changes = Arrays.asList(a, b, c, d); + PathFilter filter = PathFilter.create(PATH_A); + List<DiffEntry> entries = frd.compute(changes, filter); + assertEquals("Unexpected entries in: " + entries, 1, entries.size()); + assertSame(a, entries.get(0)); + } + + @Test + public void testNoRenames_multipleFilters() throws Exception { + ObjectId aId = blob(""); + ObjectId bId = blob("blah1"); + ObjectId cId = blob(""); + ObjectId dId = blob("blah2"); + + DiffEntry a = DiffEntry.add(PATH_A, aId); + DiffEntry b = DiffEntry.delete(PATH_Q, bId); + + DiffEntry c = DiffEntry.add(PATH_H, cId); + DiffEntry d = DiffEntry.delete(PATH_B, dId); + + List<DiffEntry> changes = Arrays.asList(a, b, c, d); + List<PathFilter> filters = Arrays.asList(PathFilter.create(PATH_A), + PathFilter.create(PATH_H)); + List<DiffEntry> entries = frd.compute(changes, filters); + assertEquals("Unexpected entries in: " + entries, 2, entries.size()); + assertSame(a, entries.get(0)); + assertSame(c, entries.get(1)); + } +} diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RenameDetectorTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RenameDetectorTest.java index 5edb60ce37..ad560e3b8a 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RenameDetectorTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RenameDetectorTest.java @@ -18,31 +18,20 @@ import static org.junit.Assert.fail; import java.util.Arrays; import java.util.List; -import org.eclipse.jgit.diff.DiffEntry.ChangeType; -import org.eclipse.jgit.junit.RepositoryTestCase; -import org.eclipse.jgit.junit.TestRepository; import org.eclipse.jgit.lib.AbbreviatedObjectId; import org.eclipse.jgit.lib.FileMode; import org.eclipse.jgit.lib.ObjectId; -import org.eclipse.jgit.lib.Repository; import org.junit.Before; import org.junit.Test; -public class RenameDetectorTest extends RepositoryTestCase { - private static final String PATH_A = "src/A"; - private static final String PATH_B = "src/B"; - private static final String PATH_H = "src/H"; - private static final String PATH_Q = "src/Q"; +public class RenameDetectorTest extends AbstractRenameDetectionTestCase { private RenameDetector rd; - private TestRepository<Repository> testDb; - @Override @Before public void setUp() throws Exception { super.setUp(); - testDb = new TestRepository<>(db); rd = new RenameDetector(db); } @@ -675,62 +664,4 @@ public class RenameDetectorTest extends RepositoryTestCase { assertSame(c, entries.get(2)); assertSame(d, entries.get(3)); } - - private ObjectId blob(String content) throws Exception { - return testDb.blob(content).copy(); - } - - private static void assertRename(DiffEntry o, DiffEntry n, int score, - DiffEntry rename) { - assertEquals(ChangeType.RENAME, rename.getChangeType()); - - assertEquals(o.getOldPath(), rename.getOldPath()); - assertEquals(n.getNewPath(), rename.getNewPath()); - - assertEquals(o.getOldMode(), rename.getOldMode()); - assertEquals(n.getNewMode(), rename.getNewMode()); - - assertEquals(o.getOldId(), rename.getOldId()); - assertEquals(n.getNewId(), rename.getNewId()); - - assertEquals(score, rename.getScore()); - } - - private static void assertCopy(DiffEntry o, DiffEntry n, int score, - DiffEntry copy) { - assertEquals(ChangeType.COPY, copy.getChangeType()); - - assertEquals(o.getOldPath(), copy.getOldPath()); - assertEquals(n.getNewPath(), copy.getNewPath()); - - assertEquals(o.getOldMode(), copy.getOldMode()); - assertEquals(n.getNewMode(), copy.getNewMode()); - - assertEquals(o.getOldId(), copy.getOldId()); - assertEquals(n.getNewId(), copy.getNewId()); - - assertEquals(score, copy.getScore()); - } - - private static void assertAdd(String newName, ObjectId newId, - FileMode newMode, DiffEntry add) { - assertEquals(DiffEntry.DEV_NULL, add.oldPath); - assertEquals(DiffEntry.A_ZERO, add.oldId); - assertEquals(FileMode.MISSING, add.oldMode); - assertEquals(ChangeType.ADD, add.changeType); - assertEquals(newName, add.newPath); - assertEquals(AbbreviatedObjectId.fromObjectId(newId), add.newId); - assertEquals(newMode, add.newMode); - } - - private static void assertDelete(String oldName, ObjectId oldId, - FileMode oldMode, DiffEntry delete) { - assertEquals(DiffEntry.DEV_NULL, delete.newPath); - assertEquals(DiffEntry.A_ZERO, delete.newId); - assertEquals(FileMode.MISSING, delete.newMode); - assertEquals(ChangeType.DELETE, delete.changeType); - assertEquals(oldName, delete.oldPath); - assertEquals(AbbreviatedObjectId.fromObjectId(oldId), delete.oldId); - assertEquals(oldMode, delete.oldMode); - } } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/BareSuperprojectWriterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/BareSuperprojectWriterTest.java new file mode 100644 index 0000000000..c3b93879b2 --- /dev/null +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/BareSuperprojectWriterTest.java @@ -0,0 +1,106 @@ +/* + * Copyright (C) 2021, Google Inc. and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Distribution License v. 1.0 which is available at + * https://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: BSD-3-Clause + */ +package org.eclipse.jgit.gitrepo; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.is; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.nio.charset.StandardCharsets; +import java.util.Arrays; +import java.util.List; + +import org.eclipse.jgit.gitrepo.BareSuperprojectWriter.BareWriterConfig; +import org.eclipse.jgit.gitrepo.RepoCommand.RemoteReader; +import org.eclipse.jgit.junit.RepositoryTestCase; +import org.eclipse.jgit.lib.ObjectId; +import org.eclipse.jgit.lib.ObjectReader; +import org.eclipse.jgit.lib.Repository; +import org.eclipse.jgit.revwalk.RevCommit; +import org.junit.Test; + +public class BareSuperprojectWriterTest extends RepositoryTestCase { + + private static final String SHA1_A = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; + + @Override + public void setUp() throws Exception { + super.setUp(); + } + + @Test + public void write_setGitModulesContents() throws Exception { + try (Repository bareRepo = createBareRepository()) { + RepoProject repoProject = new RepoProject("subprojectX", "path/to", + "refs/heads/branch-x", "remote", ""); + repoProject.setUrl("http://example.com/a"); + + RemoteReader mockRemoteReader = mock(RemoteReader.class); + when(mockRemoteReader.sha1("http://example.com/a", + "refs/heads/branch-x")) + .thenReturn(ObjectId.fromString(SHA1_A)); + + BareSuperprojectWriter w = new BareSuperprojectWriter(bareRepo, + null, "refs/heads/master", author, mockRemoteReader, + BareWriterConfig.getDefault(), List.of()); + + RevCommit commit = w.write(Arrays.asList(repoProject)); + + String contents = readContents(bareRepo, commit, ".gitmodules"); + List<String> contentLines = Arrays + .asList(contents.split("\n")); + assertThat(contentLines.get(0), + is("[submodule \"subprojectX\"]")); + assertThat(contentLines.subList(1, contentLines.size()), + containsInAnyOrder(is("\tbranch = refs/heads/branch-x"), + is("\tpath = path/to"), + is("\turl = http://example.com/a"))); + } + } + + @Test + public void write_setExtraContents() throws Exception { + try (Repository bareRepo = createBareRepository()) { + RepoProject repoProject = new RepoProject("subprojectX", "path/to", + "refs/heads/branch-x", "remote", ""); + repoProject.setUrl("http://example.com/a"); + + RemoteReader mockRemoteReader = mock(RemoteReader.class); + when(mockRemoteReader.sha1("http://example.com/a", + "refs/heads/branch-x")) + .thenReturn(ObjectId.fromString(SHA1_A)); + + BareSuperprojectWriter w = new BareSuperprojectWriter(bareRepo, + null, "refs/heads/master", author, mockRemoteReader, + BareWriterConfig.getDefault(), + List.of(new BareSuperprojectWriter.ExtraContent("x", + "extra-content"))); + + RevCommit commit = w.write(Arrays.asList(repoProject)); + + String contents = readContents(bareRepo, commit, "x"); + assertThat(contents, is("extra-content")); + } + } + + private String readContents(Repository repo, RevCommit commit, + String path) throws Exception { + String idStr = commit.getId().name() + ":" + path; + ObjectId modId = repo.resolve(idStr); + try (ObjectReader reader = repo.newObjectReader()) { + return new String( + reader.open(modId).getCachedBytes(Integer.MAX_VALUE), + StandardCharsets.UTF_8); + + } + } +} 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 509adc2cb2..3e6d13a67e 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 @@ -15,6 +15,7 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import static org.junit.Assume.assumeTrue; import java.io.BufferedReader; import java.io.ByteArrayInputStream; @@ -546,24 +547,29 @@ 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()); - assertFalse("The original file should not be executable", - hello.canExecute()); + if (FS.DETECTED.supportsExecute()) { + assertFalse("The original file should not be executable", + FS.DETECTED.canExecute(hello)); + } assertContents(hello.toPath(), "master world"); // The dest file should also exist hello = new File(localDb.getWorkTree(), "Hello"); assertTrue("The destination file should exist", hello.exists()); - assertFalse("The destination file should not be executable", - hello.canExecute()); + if (FS.DETECTED.supportsExecute()) { + assertFalse("The destination file should not be executable", + FS.DETECTED.canExecute(hello)); + } assertContents(hello.toPath(), "master world"); } @Test public void testRepoManifestCopyFile_executable() throws Exception { + assumeTrue(FS.DETECTED.supportsExecute()); try (Git git = new Git(defaultDb)) { git.checkout().setName("master").call(); File f = JGitTestUtil.writeTrashFile(defaultDb, "hello.sh", "content of the executable file"); - f.setExecutable(true); + FS.DETECTED.setExecute(f, true); git.add().addFilepattern("hello.sh").call(); git.commit().setMessage("Add binary file").call(); } @@ -588,7 +594,8 @@ public class RepoCommandTest extends RepositoryTestCase { // The original file should exist and be an executable File hello = new File(localDb.getWorkTree(), "foo/hello.sh"); assertTrue("The original file should exist", hello.exists()); - assertTrue("The original file must be executable", hello.canExecute()); + assertTrue("The original file must be executable", + FS.DETECTED.canExecute(hello)); try (BufferedReader reader = Files.newBufferedReader(hello.toPath(), UTF_8)) { String content = reader.readLine(); @@ -600,7 +607,7 @@ public class RepoCommandTest extends RepositoryTestCase { hello = new File(localDb.getWorkTree(), "copy-hello.sh"); assertTrue("The destination file should exist", hello.exists()); assertTrue("The destination file must be executable", - hello.canExecute()); + FS.DETECTED.canExecute(hello)); try (BufferedReader reader = Files.newBufferedReader(hello.toPath(), UTF_8)) { String content = reader.readLine(); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/diffmergetool/ExternalDiffToolTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/diffmergetool/ExternalDiffToolTest.java index b141a86f76..f69a1794ef 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/diffmergetool/ExternalDiffToolTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/diffmergetool/ExternalDiffToolTest.java @@ -10,42 +10,156 @@ package org.eclipse.jgit.internal.diffmergetool; import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_DIFFTOOL_SECTION; +import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_DIFF_SECTION; import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_CMD; import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_GUITOOL; import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_PATH; import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_PROMPT; +import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_TOOL; import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_TRUST_EXIT_CODE; 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.assertTrue; +import static org.junit.Assert.fail; +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.util.Arrays; import java.util.Collections; import java.util.LinkedHashSet; +import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.Set; +import org.eclipse.jgit.junit.TestRepository; +import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.internal.BooleanTriState; import org.eclipse.jgit.storage.file.FileBasedConfig; +import org.eclipse.jgit.util.FS.ExecutionResult; import org.junit.Test; /** * Testing external diff tools. */ -public class ExternalDiffToolTest extends ExternalToolTest { +public class ExternalDiffToolTest extends ExternalToolTestCase { + + @Test(expected = ToolException.class) + public void testUserToolWithError() throws Exception { + String toolName = "customTool"; + + int errorReturnCode = 1; + String command = "exit " + errorReturnCode; + + FileBasedConfig config = db.getConfig(); + config.setString(CONFIG_DIFFTOOL_SECTION, toolName, CONFIG_KEY_CMD, + command); + + invokeCompare(toolName); + + fail("Expected exception to be thrown due to external tool exiting with error code: " + + errorReturnCode); + } + + @Test(expected = ToolException.class) + public void testUserToolWithCommandNotFoundError() throws Exception { + String toolName = "customTool"; + + int errorReturnCode = 127; // command not found + String command = "exit " + errorReturnCode; + + FileBasedConfig config = db.getConfig(); + config.setString(CONFIG_DIFFTOOL_SECTION, toolName, CONFIG_KEY_CMD, + command); + + invokeCompare(toolName); + fail("Expected exception to be thrown due to external tool exiting with error code: " + + errorReturnCode); + } + + @Test + public void testUserDefinedTool() throws Exception { + String command = getEchoCommand(); + + FileBasedConfig config = db.getConfig(); + String customToolName = "customTool"; + config.setString(CONFIG_DIFFTOOL_SECTION, customToolName, + CONFIG_KEY_CMD, command); + + DiffTools manager = new DiffTools(db); + + Map<String, ExternalDiffTool> tools = manager.getUserDefinedTools(); + ExternalDiffTool externalTool = tools.get(customToolName); + boolean trustExitCode = true; + manager.compare(local, remote, externalTool, trustExitCode); + + assertEchoCommandHasCorrectOutput(); + } + + @Test + public void testUserDefinedToolWithPrompt() throws Exception { + String command = getEchoCommand(); + + FileBasedConfig config = db.getConfig(); + String customToolName = "customTool"; + config.setString(CONFIG_DIFFTOOL_SECTION, customToolName, + CONFIG_KEY_CMD, command); + + DiffTools manager = new DiffTools(db); + + PromptHandler promptHandler = PromptHandler.acceptPrompt(); + MissingToolHandler noToolHandler = new MissingToolHandler(); + + manager.compare(local, remote, Optional.of(customToolName), + BooleanTriState.TRUE, false, BooleanTriState.TRUE, + promptHandler, noToolHandler); + + assertEchoCommandHasCorrectOutput(); + + List<String> actualToolPrompts = promptHandler.toolPrompts; + List<String> expectedToolPrompts = Arrays.asList("customTool"); + assertEquals("Expected a user prompt for custom tool call", + expectedToolPrompts, actualToolPrompts); + + assertEquals("Expected to no informing about missing tools", + Collections.EMPTY_LIST, noToolHandler.missingTools); + } @Test - public void testToolNames() { + public void testUserDefinedToolWithCancelledPrompt() throws Exception { + String command = getEchoCommand(); + + FileBasedConfig config = db.getConfig(); + String customToolName = "customTool"; + config.setString(CONFIG_DIFFTOOL_SECTION, customToolName, + CONFIG_KEY_CMD, command); + DiffTools manager = new DiffTools(db); - Set<String> actualToolNames = manager.getToolNames(); - Set<String> expectedToolNames = Collections.emptySet(); - assertEquals("Incorrect set of external diff tool names", - expectedToolNames, actualToolNames); + + PromptHandler promptHandler = PromptHandler.cancelPrompt(); + MissingToolHandler noToolHandler = new MissingToolHandler(); + + Optional<ExecutionResult> result = manager.compare(local, remote, + Optional.of(customToolName), BooleanTriState.TRUE, false, + BooleanTriState.TRUE, promptHandler, noToolHandler); + assertFalse("Expected no result if user cancels the operation", + result.isPresent()); } @Test public void testAllTools() { + FileBasedConfig config = db.getConfig(); + String customToolName = "customTool"; + config.setString(CONFIG_DIFFTOOL_SECTION, customToolName, + CONFIG_KEY_CMD, "echo"); + DiffTools manager = new DiffTools(db); - Set<String> actualToolNames = manager.getAvailableTools().keySet(); + Set<String> actualToolNames = manager.getAllToolNames(); Set<String> expectedToolNames = new LinkedHashSet<>(); + expectedToolNames.add(customToolName); CommandLineDiffTool[] defaultTools = CommandLineDiffTool.values(); for (CommandLineDiffTool defaultTool : defaultTools) { String toolName = defaultTool.name(); @@ -86,11 +200,11 @@ public class ExternalDiffToolTest extends ExternalToolTest { config.setString(CONFIG_DIFFTOOL_SECTION, customToolname, CONFIG_KEY_PATH, "/usr/bin/echo"); config.setString(CONFIG_DIFFTOOL_SECTION, customToolname, - CONFIG_KEY_PROMPT, "--no-prompt"); + CONFIG_KEY_PROMPT, String.valueOf(false)); config.setString(CONFIG_DIFFTOOL_SECTION, customToolname, - CONFIG_KEY_GUITOOL, "--no-gui"); + CONFIG_KEY_GUITOOL, String.valueOf(false)); config.setString(CONFIG_DIFFTOOL_SECTION, customToolname, - CONFIG_KEY_TRUST_EXIT_CODE, "--no-trust-exit-code"); + CONFIG_KEY_TRUST_EXIT_CODE, String.valueOf(false)); DiffTools manager = new DiffTools(db); Set<String> actualToolNames = manager.getUserDefinedTools().keySet(); Set<String> expectedToolNames = new LinkedHashSet<>(); @@ -100,59 +214,240 @@ public class ExternalDiffToolTest extends ExternalToolTest { } @Test - public void testNotAvailableTools() { - DiffTools manager = new DiffTools(db); - Set<String> actualToolNames = manager.getNotAvailableTools().keySet(); - Set<String> expectedToolNames = Collections.emptySet(); - assertEquals("Incorrect set of not available external diff tools", - expectedToolNames, actualToolNames); - } + public void testCompare() throws ToolException { + String toolName = "customTool"; - @Test - public void testCompare() { - DiffTools manager = new DiffTools(db); + FileBasedConfig config = db.getConfig(); + // the default diff tool is configured without a subsection + String subsection = null; + config.setString(CONFIG_DIFF_SECTION, subsection, CONFIG_KEY_TOOL, + toolName); - String newPath = ""; - String oldPath = ""; - String newId = ""; - String oldId = ""; - String toolName = ""; - BooleanTriState prompt = BooleanTriState.UNSET; - BooleanTriState gui = BooleanTriState.UNSET; - BooleanTriState trustExitCode = BooleanTriState.UNSET; + String command = getEchoCommand(); + config.setString(CONFIG_DIFFTOOL_SECTION, toolName, CONFIG_KEY_CMD, + command); + Optional<ExecutionResult> result = invokeCompare(toolName); + assertTrue("Expected external diff tool result to be available", + result.isPresent()); int expectedCompareResult = 0; - int compareResult = manager.compare(newPath, oldPath, newId, oldId, - toolName, prompt, gui, trustExitCode); assertEquals("Incorrect compare result for external diff tool", - expectedCompareResult, compareResult); + expectedCompareResult, result.get().getRc()); } @Test public void testDefaultTool() throws Exception { + String toolName = "customTool"; + String guiToolName = "customGuiTool"; + FileBasedConfig config = db.getConfig(); // the default diff tool is configured without a subsection String subsection = null; - config.setString("diff", subsection, "tool", "customTool"); + config.setString(CONFIG_DIFF_SECTION, subsection, CONFIG_KEY_TOOL, + toolName); DiffTools manager = new DiffTools(db); - BooleanTriState gui = BooleanTriState.UNSET; + boolean gui = false; String defaultToolName = manager.getDefaultToolName(gui); assertEquals( "Expected configured difftool to be the default external diff tool", - "my_default_toolname", defaultToolName); + toolName, defaultToolName); - gui = BooleanTriState.TRUE; + gui = true; String defaultGuiToolName = manager.getDefaultToolName(gui); assertEquals( - "Expected configured difftool to be the default external diff tool", - "my_gui_tool", defaultGuiToolName); + "Expected default gui difftool to be the default tool if no gui tool is set", + toolName, defaultGuiToolName); - config.setString("diff", subsection, "guitool", "customGuiTool"); + config.setString(CONFIG_DIFF_SECTION, subsection, CONFIG_KEY_GUITOOL, + guiToolName); manager = new DiffTools(db); defaultGuiToolName = manager.getDefaultToolName(gui); assertEquals( "Expected configured difftool to be the default external diff guitool", - "my_gui_tool", defaultGuiToolName); + guiToolName, defaultGuiToolName); + } + + @Test + public void testOverridePreDefinedToolPath() { + String newToolPath = "/tmp/path/"; + + CommandLineDiffTool[] defaultTools = CommandLineDiffTool.values(); + assertTrue("Expected to find pre-defined external diff tools", + defaultTools.length > 0); + + CommandLineDiffTool overridenTool = defaultTools[0]; + String overridenToolName = overridenTool.name(); + String overridenToolPath = newToolPath + overridenToolName; + FileBasedConfig config = db.getConfig(); + config.setString(CONFIG_DIFFTOOL_SECTION, overridenToolName, + CONFIG_KEY_PATH, overridenToolPath); + + DiffTools manager = new DiffTools(db); + Map<String, ExternalDiffTool> availableTools = manager + .getPredefinedTools(true); + ExternalDiffTool externalDiffTool = availableTools + .get(overridenToolName); + String actualDiffToolPath = externalDiffTool.getPath(); + assertEquals( + "Expected pre-defined external diff tool to have overriden path", + overridenToolPath, actualDiffToolPath); + String expectedDiffToolCommand = overridenToolPath + " " + + overridenTool.getParameters(); + String actualDiffToolCommand = externalDiffTool.getCommand(); + assertEquals( + "Expected pre-defined external diff tool to have overriden command", + expectedDiffToolCommand, actualDiffToolCommand); + } + + @Test(expected = ToolException.class) + public void testUndefinedTool() throws Exception { + String toolName = "undefined"; + invokeCompare(toolName); + fail("Expected exception to be thrown due to not defined external diff tool"); + } + + @Test + public void testDefaultToolExecutionWithPrompt() throws Exception { + FileBasedConfig config = db.getConfig(); + // the default diff tool is configured without a subsection + String subsection = null; + config.setString("diff", subsection, "tool", "customTool"); + + String command = getEchoCommand(); + + config.setString("difftool", "customTool", "cmd", command); + + DiffTools manager = new DiffTools(db); + + PromptHandler promptHandler = PromptHandler.acceptPrompt(); + MissingToolHandler noToolHandler = new MissingToolHandler(); + + manager.compare(local, remote, Optional.empty(), BooleanTriState.TRUE, + false, BooleanTriState.TRUE, promptHandler, noToolHandler); + + assertEchoCommandHasCorrectOutput(); + } + + @Test + public void testNoDefaultToolName() { + DiffTools manager = new DiffTools(db); + boolean gui = false; + String defaultToolName = manager.getDefaultToolName(gui); + assertNull("Expected no default tool when none is configured", + defaultToolName); + + gui = true; + defaultToolName = manager.getDefaultToolName(gui); + assertNull("Expected no default tool when none is configured", + defaultToolName); + } + + @Test + public void testExternalToolInGitAttributes() throws Exception { + String content = "attributes:\n*.txt difftool=customTool"; + File gitattributes = writeTrashFile(".gitattributes", content); + gitattributes.deleteOnExit(); + try (TestRepository<Repository> testRepository = new TestRepository<>( + db)) { + FileBasedConfig config = db.getConfig(); + config.setString("difftool", "customTool", "cmd", "echo"); + testRepository.git().add().addFilepattern(localFile.getName()) + .call(); + + testRepository.git().add().addFilepattern(".gitattributes").call(); + + testRepository.branch("master").commit().message("first commit") + .create(); + + DiffTools manager = new DiffTools(db); + Optional<String> tool = manager + .getExternalToolFromAttributes(localFile.getName()); + assertTrue("Failed to find user defined tool", tool.isPresent()); + assertEquals("Failed to find user defined tool", "customTool", + tool.get()); + } finally { + Files.delete(gitattributes.toPath()); + } + } + + @Test + public void testNotExternalToolInGitAttributes() throws Exception { + String content = ""; + File gitattributes = writeTrashFile(".gitattributes", content); + gitattributes.deleteOnExit(); + try (TestRepository<Repository> testRepository = new TestRepository<>( + db)) { + FileBasedConfig config = db.getConfig(); + config.setString("difftool", "customTool", "cmd", "echo"); + testRepository.git().add().addFilepattern(localFile.getName()) + .call(); + + testRepository.git().add().addFilepattern(".gitattributes").call(); + + testRepository.branch("master").commit().message("first commit") + .create(); + + DiffTools manager = new DiffTools(db); + Optional<String> tool = manager + .getExternalToolFromAttributes(localFile.getName()); + assertFalse( + "Expected no external tool if no default tool is specified in .gitattributes", + tool.isPresent()); + } finally { + Files.delete(gitattributes.toPath()); + } + } + + @Test(expected = ToolException.class) + public void testNullTool() throws Exception { + DiffTools manager = new DiffTools(db); + + boolean trustExitCode = true; + ExternalDiffTool tool = null; + manager.compare(local, remote, tool, trustExitCode); + } + + @Test(expected = ToolException.class) + public void testNullToolWithPrompt() throws Exception { + DiffTools manager = new DiffTools(db); + + PromptHandler promptHandler = PromptHandler.cancelPrompt(); + MissingToolHandler noToolHandler = new MissingToolHandler(); + + Optional<String> tool = null; + manager.compare(local, remote, tool, BooleanTriState.TRUE, false, + BooleanTriState.TRUE, promptHandler, noToolHandler); + } + + private Optional<ExecutionResult> invokeCompare(String toolName) + throws ToolException { + DiffTools manager = new DiffTools(db); + + BooleanTriState prompt = BooleanTriState.UNSET; + boolean gui = false; + BooleanTriState trustExitCode = BooleanTriState.TRUE; + PromptHandler promptHandler = PromptHandler.acceptPrompt(); + MissingToolHandler noToolHandler = new MissingToolHandler(); + + Optional<ExecutionResult> result = manager.compare(local, remote, + Optional.of(toolName), prompt, gui, trustExitCode, + promptHandler, noToolHandler); + return result; + } + + private String getEchoCommand() { + return "(echo \"$LOCAL\" \"$REMOTE\") > " + + commandResult.getAbsolutePath(); + } + + private void assertEchoCommandHasCorrectOutput() throws IOException { + List<String> actualLines = Files.readAllLines(commandResult.toPath()); + String actualContent = String.join(System.lineSeparator(), actualLines); + actualLines = Arrays.asList(actualContent.split(" ")); + List<String> expectedLines = Arrays.asList(localFile.getAbsolutePath(), + remoteFile.getAbsolutePath()); + assertEquals("Dummy test tool called with unexpected arguments", + expectedLines, actualLines); } } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/diffmergetool/ExternalMergeToolTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/diffmergetool/ExternalMergeToolTest.java new file mode 100644 index 0000000000..94b67b374b --- /dev/null +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/diffmergetool/ExternalMergeToolTest.java @@ -0,0 +1,433 @@ +/* + * Copyright (C) 2020-2022, Simeon Andreev <simeon.danailov.andreev@gmail.com> and others. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Distribution License v. 1.0 which is available at + * https://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: BSD-3-Clause + */ +package org.eclipse.jgit.internal.diffmergetool; + +import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_CMD; +import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_GUITOOL; +import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_PATH; +import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_PROMPT; +import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_TOOL; +import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_TRUST_EXIT_CODE; +import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_MERGETOOL_SECTION; +import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_MERGE_SECTION; +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.assertTrue; +import static org.junit.Assert.fail; +import static org.junit.Assume.assumeTrue; + +import java.io.IOException; +import java.nio.file.Files; +import java.util.Arrays; +import java.util.Collections; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; + +import org.eclipse.jgit.lib.internal.BooleanTriState; +import org.eclipse.jgit.storage.file.FileBasedConfig; +import org.eclipse.jgit.util.FS.ExecutionResult; +import org.junit.Test; + +/** + * Testing external merge tools. + */ +public class ExternalMergeToolTest extends ExternalToolTestCase { + + @Test(expected = ToolException.class) + public void testUserToolWithError() throws Exception { + String toolName = "customTool"; + + int errorReturnCode = 1; + String command = "exit " + errorReturnCode; + + FileBasedConfig config = db.getConfig(); + config.setString(CONFIG_MERGETOOL_SECTION, toolName, CONFIG_KEY_CMD, + command); + config.setString(CONFIG_MERGETOOL_SECTION, toolName, + CONFIG_KEY_TRUST_EXIT_CODE, String.valueOf(Boolean.TRUE)); + + invokeMerge(toolName); + + fail("Expected exception to be thrown due to external tool exiting with error code: " + + errorReturnCode); + } + + @Test(expected = ToolException.class) + public void testUserToolWithCommandNotFoundError() throws Exception { + String toolName = "customTool"; + + int errorReturnCode = 127; // command not found + String command = "exit " + errorReturnCode; + + FileBasedConfig config = db.getConfig(); + config.setString(CONFIG_MERGETOOL_SECTION, toolName, CONFIG_KEY_CMD, + command); + + invokeMerge(toolName); + + fail("Expected exception to be thrown due to external tool exiting with error code: " + + errorReturnCode); + } + + @Test + public void testKdiff3() throws Exception { + assumePosixPlatform(); + + CommandLineMergeTool autoMergingTool = CommandLineMergeTool.kdiff3; + assumeMergeToolIsAvailable(autoMergingTool); + + CommandLineMergeTool tool = autoMergingTool; + PreDefinedMergeTool externalTool = new PreDefinedMergeTool(tool.name(), + tool.getPath(), tool.getParameters(true), + tool.getParameters(false), + tool.isExitCodeTrustable() ? BooleanTriState.TRUE + : BooleanTriState.FALSE); + + MergeTools manager = new MergeTools(db); + ExecutionResult result = manager.merge(local, remote, merged, null, + null, externalTool); + assertEquals("Expected merge tool to succeed", 0, result.getRc()); + + List<String> actualLines = Files.readAllLines(mergedFile.toPath()); + String actualMergeResult = String.join(System.lineSeparator(), + actualLines); + String expectedMergeResult = DEFAULT_CONTENT; + assertEquals( + "Failed to merge equal local and remote versions with pre-defined tool: " + + tool.getPath(), + expectedMergeResult, actualMergeResult); + } + + @Test + public void testUserDefinedTool() throws Exception { + String customToolName = "customTool"; + String command = getEchoCommand(); + + FileBasedConfig config = db.getConfig(); + config.setString(CONFIG_MERGETOOL_SECTION, customToolName, + CONFIG_KEY_CMD, command); + + MergeTools manager = new MergeTools(db); + Map<String, ExternalMergeTool> tools = manager.getUserDefinedTools(); + ExternalMergeTool externalTool = tools.get(customToolName); + manager.merge(local, remote, merged, base, null, externalTool); + + assertEchoCommandHasCorrectOutput(); + } + + @Test + public void testUserDefinedToolWithPrompt() throws Exception { + String customToolName = "customTool"; + String command = getEchoCommand(); + + FileBasedConfig config = db.getConfig(); + config.setString(CONFIG_MERGETOOL_SECTION, customToolName, + CONFIG_KEY_CMD, command); + + MergeTools manager = new MergeTools(db); + + PromptHandler promptHandler = PromptHandler.acceptPrompt(); + MissingToolHandler noToolHandler = new MissingToolHandler(); + + manager.merge(local, remote, merged, base, null, + Optional.of(customToolName), BooleanTriState.TRUE, false, + promptHandler, noToolHandler); + + assertEchoCommandHasCorrectOutput(); + + List<String> actualToolPrompts = promptHandler.toolPrompts; + List<String> expectedToolPrompts = Arrays.asList("customTool"); + assertEquals("Expected a user prompt for custom tool call", + expectedToolPrompts, actualToolPrompts); + + assertEquals("Expected to no informing about missing tools", + Collections.EMPTY_LIST, noToolHandler.missingTools); + } + + @Test + public void testUserDefinedToolWithCancelledPrompt() throws Exception { + MergeTools manager = new MergeTools(db); + + PromptHandler promptHandler = PromptHandler.cancelPrompt(); + MissingToolHandler noToolHandler = new MissingToolHandler(); + + Optional<ExecutionResult> result = manager.merge(local, remote, merged, + base, null, Optional.empty(), BooleanTriState.TRUE, false, + promptHandler, noToolHandler); + assertFalse("Expected no result if user cancels the operation", + result.isPresent()); + } + + @Test + public void testAllTools() { + FileBasedConfig config = db.getConfig(); + String customToolName = "customTool"; + config.setString(CONFIG_MERGETOOL_SECTION, customToolName, + CONFIG_KEY_CMD, "echo"); + + MergeTools manager = new MergeTools(db); + Set<String> actualToolNames = manager.getAllToolNames(); + Set<String> expectedToolNames = new LinkedHashSet<>(); + expectedToolNames.add(customToolName); + CommandLineMergeTool[] defaultTools = CommandLineMergeTool.values(); + for (CommandLineMergeTool defaultTool : defaultTools) { + String toolName = defaultTool.name(); + expectedToolNames.add(toolName); + } + assertEquals("Incorrect set of external merge tools", expectedToolNames, + actualToolNames); + } + + @Test + public void testOverridePredefinedToolPath() { + String toolName = CommandLineMergeTool.guiffy.name(); + String customToolPath = "/usr/bin/echo"; + + FileBasedConfig config = db.getConfig(); + config.setString(CONFIG_MERGETOOL_SECTION, toolName, CONFIG_KEY_CMD, + "echo"); + config.setString(CONFIG_MERGETOOL_SECTION, toolName, CONFIG_KEY_PATH, + customToolPath); + + MergeTools manager = new MergeTools(db); + Map<String, ExternalMergeTool> tools = manager.getUserDefinedTools(); + ExternalMergeTool mergeTool = tools.get(toolName); + assertNotNull("Expected tool \"" + toolName + "\" to be user defined", + mergeTool); + + String toolPath = mergeTool.getPath(); + assertEquals("Expected external merge tool to have an overriden path", + customToolPath, toolPath); + } + + @Test + public void testUserDefinedTools() { + FileBasedConfig config = db.getConfig(); + String customToolname = "customTool"; + config.setString(CONFIG_MERGETOOL_SECTION, customToolname, + CONFIG_KEY_CMD, "echo"); + config.setString(CONFIG_MERGETOOL_SECTION, customToolname, + CONFIG_KEY_PATH, "/usr/bin/echo"); + config.setString(CONFIG_MERGETOOL_SECTION, customToolname, + CONFIG_KEY_PROMPT, String.valueOf(false)); + config.setString(CONFIG_MERGETOOL_SECTION, customToolname, + CONFIG_KEY_GUITOOL, String.valueOf(false)); + config.setString(CONFIG_MERGETOOL_SECTION, customToolname, + CONFIG_KEY_TRUST_EXIT_CODE, String.valueOf(false)); + MergeTools manager = new MergeTools(db); + Set<String> actualToolNames = manager.getUserDefinedTools().keySet(); + Set<String> expectedToolNames = new LinkedHashSet<>(); + expectedToolNames.add(customToolname); + assertEquals("Incorrect set of external merge tools", expectedToolNames, + actualToolNames); + } + + @Test + public void testCompare() throws ToolException { + String toolName = "customTool"; + + FileBasedConfig config = db.getConfig(); + // the default merge tool is configured without a subsection + String subsection = null; + config.setString(CONFIG_MERGE_SECTION, subsection, CONFIG_KEY_TOOL, + toolName); + + String command = getEchoCommand(); + + config.setString(CONFIG_MERGETOOL_SECTION, toolName, CONFIG_KEY_CMD, + command); + + Optional<ExecutionResult> result = invokeMerge(toolName); + assertTrue("Expected external merge tool result to be available", + result.isPresent()); + int expectedCompareResult = 0; + assertEquals("Incorrect compare result for external merge tool", + expectedCompareResult, result.get().getRc()); + } + + @Test + public void testDefaultTool() throws Exception { + String toolName = "customTool"; + String guiToolName = "customGuiTool"; + + FileBasedConfig config = db.getConfig(); + // the default merge tool is configured without a subsection + String subsection = null; + config.setString(CONFIG_MERGE_SECTION, subsection, CONFIG_KEY_TOOL, + toolName); + + MergeTools manager = new MergeTools(db); + boolean gui = false; + String defaultToolName = manager.getDefaultToolName(gui); + assertEquals( + "Expected configured mergetool to be the default external merge tool", + toolName, defaultToolName); + + gui = true; + String defaultGuiToolName = manager.getDefaultToolName(gui); + assertNull("Expected default mergetool to not be set", + defaultGuiToolName); + + config.setString(CONFIG_MERGE_SECTION, subsection, CONFIG_KEY_GUITOOL, + guiToolName); + manager = new MergeTools(db); + defaultGuiToolName = manager.getDefaultToolName(gui); + assertEquals( + "Expected configured mergetool to be the default external merge guitool", + guiToolName, defaultGuiToolName); + } + + @Test + public void testOverridePreDefinedToolPath() { + String newToolPath = "/tmp/path/"; + + CommandLineMergeTool[] defaultTools = CommandLineMergeTool.values(); + assertTrue("Expected to find pre-defined external merge tools", + defaultTools.length > 0); + + CommandLineMergeTool overridenTool = defaultTools[0]; + String overridenToolName = overridenTool.name(); + String overridenToolPath = newToolPath + overridenToolName; + FileBasedConfig config = db.getConfig(); + config.setString(CONFIG_MERGETOOL_SECTION, overridenToolName, + CONFIG_KEY_PATH, overridenToolPath); + + MergeTools manager = new MergeTools(db); + Map<String, ExternalMergeTool> availableTools = manager + .getPredefinedTools(true); + ExternalMergeTool externalMergeTool = availableTools + .get(overridenToolName); + String actualMergeToolPath = externalMergeTool.getPath(); + assertEquals( + "Expected pre-defined external merge tool to have overriden path", + overridenToolPath, actualMergeToolPath); + boolean withBase = true; + String expectedMergeToolCommand = overridenToolPath + " " + + overridenTool.getParameters(withBase); + String actualMergeToolCommand = externalMergeTool.getCommand(); + assertEquals( + "Expected pre-defined external merge tool to have overriden command", + expectedMergeToolCommand, actualMergeToolCommand); + } + + @Test(expected = ToolException.class) + public void testUndefinedTool() throws Exception { + String toolName = "undefined"; + invokeMerge(toolName); + fail("Expected exception to be thrown due to not defined external merge tool"); + } + + @Test + public void testDefaultToolExecutionWithPrompt() throws Exception { + FileBasedConfig config = db.getConfig(); + // the default diff tool is configured without a subsection + String subsection = null; + config.setString("merge", subsection, "tool", "customTool"); + + String command = getEchoCommand(); + + config.setString("mergetool", "customTool", "cmd", command); + + MergeTools manager = new MergeTools(db); + + PromptHandler promptHandler = PromptHandler.acceptPrompt(); + MissingToolHandler noToolHandler = new MissingToolHandler(); + + manager.merge(local, remote, merged, base, null, Optional.empty(), + BooleanTriState.TRUE, false, promptHandler, noToolHandler); + + assertEchoCommandHasCorrectOutput(); + } + + @Test + public void testNoDefaultToolName() { + MergeTools manager = new MergeTools(db); + boolean gui = false; + String defaultToolName = manager.getDefaultToolName(gui); + assertNull("Expected no default tool when none is configured", + defaultToolName); + + gui = true; + defaultToolName = manager.getDefaultToolName(gui); + assertNull("Expected no default tool when none is configured", + defaultToolName); + } + + @Test(expected = ToolException.class) + public void testNullTool() throws Exception { + MergeTools manager = new MergeTools(db); + + PromptHandler promptHandler = null; + MissingToolHandler noToolHandler = null; + + Optional<String> tool = null; + + manager.merge(local, remote, merged, base, null, tool, + BooleanTriState.TRUE, false, promptHandler, noToolHandler); + } + + @Test(expected = ToolException.class) + public void testNullToolWithPrompt() throws Exception { + MergeTools manager = new MergeTools(db); + + PromptHandler promptHandler = PromptHandler.cancelPrompt(); + MissingToolHandler noToolHandler = new MissingToolHandler(); + + Optional<String> tool = null; + + manager.merge(local, remote, merged, base, null, tool, + BooleanTriState.TRUE, false, promptHandler, noToolHandler); + } + + private Optional<ExecutionResult> invokeMerge(String toolName) + throws ToolException { + BooleanTriState prompt = BooleanTriState.UNSET; + boolean gui = false; + + MergeTools manager = new MergeTools(db); + + PromptHandler promptHandler = PromptHandler.acceptPrompt(); + MissingToolHandler noToolHandler = new MissingToolHandler(); + + Optional<ExecutionResult> result = manager.merge(local, remote, merged, + base, null, Optional.of(toolName), prompt, gui, promptHandler, + noToolHandler); + return result; + } + + private void assumeMergeToolIsAvailable( + CommandLineMergeTool autoMergingTool) { + boolean isAvailable = ExternalToolUtils.isToolAvailable(db.getFS(), + db.getDirectory(), db.getWorkTree(), autoMergingTool.getPath()); + assumeTrue("Assuming external tool is available: " + + autoMergingTool.name(), isAvailable); + } + + private String getEchoCommand() { + return "(echo $LOCAL $REMOTE $MERGED $BASE) > " + + commandResult.getAbsolutePath(); + } + + private void assertEchoCommandHasCorrectOutput() throws IOException { + List<String> actualLines = Files.readAllLines(commandResult.toPath()); + String actualContent = String.join(System.lineSeparator(), actualLines); + actualLines = Arrays.asList(actualContent.split(" ")); + List<String> expectedLines = Arrays.asList(localFile.getAbsolutePath(), + remoteFile.getAbsolutePath(), mergedFile.getAbsolutePath(), + baseFile.getAbsolutePath()); + assertEquals("Dummy test tool called with unexpected arguments", + expectedLines, actualLines); + } +} diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/diffmergetool/ExternalToolTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/diffmergetool/ExternalToolTestCase.java index c7c8eca714..7a6ff46578 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/diffmergetool/ExternalToolTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/diffmergetool/ExternalToolTestCase.java @@ -11,6 +11,8 @@ package org.eclipse.jgit.internal.diffmergetool; import java.io.File; import java.nio.file.Files; +import java.util.ArrayList; +import java.util.List; import org.eclipse.jgit.junit.RepositoryTestCase; import org.eclipse.jgit.util.FS; @@ -22,7 +24,7 @@ import org.junit.Before; /** * Base test case for external merge and diff tool tests. */ -public abstract class ExternalToolTest extends RepositoryTestCase { +public abstract class ExternalToolTestCase extends RepositoryTestCase { protected static final String DEFAULT_CONTENT = "line1"; @@ -36,6 +38,14 @@ public abstract class ExternalToolTest extends RepositoryTestCase { protected File commandResult; + protected FileElement local; + + protected FileElement remote; + + protected FileElement merged; + + protected FileElement base; + @Before @Override public void setUp() throws Exception { @@ -51,6 +61,15 @@ public abstract class ExternalToolTest extends RepositoryTestCase { baseFile.deleteOnExit(); commandResult = writeTrashFile("commandResult.txt", ""); commandResult.deleteOnExit(); + + local = new FileElement(localFile.getAbsolutePath(), + FileElement.Type.LOCAL); + remote = new FileElement(remoteFile.getAbsolutePath(), + FileElement.Type.REMOTE); + merged = new FileElement(mergedFile.getAbsolutePath(), + FileElement.Type.MERGED); + base = new FileElement(baseFile.getAbsolutePath(), + FileElement.Type.BASE); } @After @@ -71,4 +90,39 @@ public abstract class ExternalToolTest extends RepositoryTestCase { "This test can run only in Linux tests", FS.DETECTED instanceof FS_POSIX); } + + protected static class PromptHandler implements PromptContinueHandler { + + private final boolean promptResult; + + final List<String> toolPrompts = new ArrayList<>(); + + private PromptHandler(boolean promptResult) { + this.promptResult = promptResult; + } + + static PromptHandler acceptPrompt() { + return new PromptHandler(true); + } + + static PromptHandler cancelPrompt() { + return new PromptHandler(false); + } + + @Override + public boolean prompt(String toolName) { + toolPrompts.add(toolName); + return promptResult; + } + } + + protected static class MissingToolHandler implements InformNoToolHandler { + + final List<String> missingTools = new ArrayList<>(); + + @Override + public void inform(List<String> toolNames) { + missingTools.addAll(toolNames); + } + } } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsBlockCacheTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsBlockCacheTest.java index 070d666ee5..ab588cb71e 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsBlockCacheTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsBlockCacheTest.java @@ -15,16 +15,19 @@ import static org.eclipse.jgit.lib.Constants.OBJ_BLOB; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +import java.time.Duration; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.LongStream; import java.util.concurrent.Callable; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import org.eclipse.jgit.internal.storage.dfs.DfsBlockCacheConfig.IndexEventConsumer; import org.eclipse.jgit.internal.storage.pack.PackExt; import org.eclipse.jgit.junit.TestRepository; import org.eclipse.jgit.junit.TestRng; @@ -154,6 +157,119 @@ public class DfsBlockCacheTest { @SuppressWarnings("resource") @Test + public void hasIndexEventConsumerOnlyLoaded() throws Exception { + AtomicInteger loaded = new AtomicInteger(); + IndexEventConsumer indexEventConsumer = new IndexEventConsumer() { + @Override + public void acceptRequestedEvent(int packExtPos, boolean cacheHit, + long loadMicros, long bytes, + Duration lastEvictionDuration) { + assertEquals(PackExt.INDEX.getPosition(), packExtPos); + assertTrue(cacheHit); + assertTrue(lastEvictionDuration.isZero()); + loaded.incrementAndGet(); + } + }; + + DfsBlockCache.reconfigure(new DfsBlockCacheConfig().setBlockSize(512) + .setBlockLimit(512 * 4) + .setIndexEventConsumer(indexEventConsumer)); + cache = DfsBlockCache.getInstance(); + + DfsRepositoryDescription repo = new DfsRepositoryDescription("test"); + InMemoryRepository r1 = new InMemoryRepository(repo); + byte[] content = rng.nextBytes(424242); + ObjectId id; + try (ObjectInserter ins = r1.newObjectInserter()) { + id = ins.insert(OBJ_BLOB, content); + ins.flush(); + } + + try (ObjectReader rdr = r1.newObjectReader()) { + byte[] actual = rdr.open(id, OBJ_BLOB).getBytes(); + assertTrue(Arrays.equals(content, actual)); + } + // All cache entries are hot and cache is at capacity. + assertTrue(LongStream.of(cache.getHitCount()).sum() > 0); + assertEquals(99, cache.getFillPercentage()); + + InMemoryRepository r2 = new InMemoryRepository(repo); + content = rng.nextBytes(424242); + try (ObjectInserter ins = r2.newObjectInserter()) { + ins.insert(OBJ_BLOB, content); + ins.flush(); + } + assertTrue(cache.getEvictions()[PackExt.PACK.getPosition()] > 0); + assertEquals(1, cache.getEvictions()[PackExt.INDEX.getPosition()]); + assertEquals(1, loaded.get()); + } + + @SuppressWarnings("resource") + @Test + public void hasIndexEventConsumerLoadedAndEvicted() throws Exception { + AtomicInteger loaded = new AtomicInteger(); + AtomicInteger evicted = new AtomicInteger(); + IndexEventConsumer indexEventConsumer = new IndexEventConsumer() { + @Override + public void acceptRequestedEvent(int packExtPos, boolean cacheHit, + long loadMicros, long bytes, + Duration lastEvictionDuration) { + assertEquals(PackExt.INDEX.getPosition(), packExtPos); + assertTrue(cacheHit); + assertTrue(lastEvictionDuration.isZero()); + loaded.incrementAndGet(); + } + + @Override + public void acceptEvictedEvent(int packExtPos, long bytes, + int totalCacheHitCount, Duration lastEvictionDuration) { + assertEquals(PackExt.INDEX.getPosition(), packExtPos); + assertTrue(totalCacheHitCount > 0); + assertTrue(lastEvictionDuration.isZero()); + evicted.incrementAndGet(); + } + + @Override + public boolean shouldReportEvictedEvent() { + return true; + } + }; + + DfsBlockCache.reconfigure(new DfsBlockCacheConfig().setBlockSize(512) + .setBlockLimit(512 * 4) + .setIndexEventConsumer(indexEventConsumer)); + cache = DfsBlockCache.getInstance(); + + DfsRepositoryDescription repo = new DfsRepositoryDescription("test"); + InMemoryRepository r1 = new InMemoryRepository(repo); + byte[] content = rng.nextBytes(424242); + ObjectId id; + try (ObjectInserter ins = r1.newObjectInserter()) { + id = ins.insert(OBJ_BLOB, content); + ins.flush(); + } + + try (ObjectReader rdr = r1.newObjectReader()) { + byte[] actual = rdr.open(id, OBJ_BLOB).getBytes(); + assertTrue(Arrays.equals(content, actual)); + } + // All cache entries are hot and cache is at capacity. + assertTrue(LongStream.of(cache.getHitCount()).sum() > 0); + assertEquals(99, cache.getFillPercentage()); + + InMemoryRepository r2 = new InMemoryRepository(repo); + content = rng.nextBytes(424242); + try (ObjectInserter ins = r2.newObjectInserter()) { + ins.insert(OBJ_BLOB, content); + ins.flush(); + } + assertTrue(cache.getEvictions()[PackExt.PACK.getPosition()] > 0); + assertEquals(1, cache.getEvictions()[PackExt.INDEX.getPosition()]); + assertEquals(1, loaded.get()); + assertEquals(1, evicted.get()); + } + + @Test public void noConcurrencySerializedReads_oneRepo() throws Exception { InMemoryRepository r1 = createRepoWithBitmap("test"); // Reset cache with concurrency Level at 1 i.e. no concurrency. @@ -267,7 +383,6 @@ public class DfsBlockCacheTest { assertEquals(2, cache.getMissCount()[0]); } - @SuppressWarnings("resource") @Test public void highConcurrencyParallelReads_oneRepo() throws Exception { InMemoryRepository r1 = createRepoWithBitmap("test"); @@ -290,7 +405,6 @@ public class DfsBlockCacheTest { assertEquals(1, cache.getMissCount()[0]); } - @SuppressWarnings("resource") @Test public void highConcurrencyParallelReads_oneRepoParallelReverseIndex() throws Exception { diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/BatchRefUpdateTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/BatchRefUpdateTest.java index 6357a0b9a8..daf4382719 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/BatchRefUpdateTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/BatchRefUpdateTest.java @@ -42,6 +42,8 @@ import java.util.List; import java.util.Map; import java.util.concurrent.locks.ReentrantLock; import java.util.function.Predicate; +import java.util.function.Function; +import java.util.stream.Collectors; import org.eclipse.jgit.events.ListenerHandle; import org.eclipse.jgit.events.RefsChangedListener; @@ -127,6 +129,7 @@ public class BatchRefUpdateTest extends LocalDiskRepositoryTestCase { } diskRepo = fileRepo; + addRepoToClose(diskRepo); setLogAllRefUpdates(true); if (!useReftable) { @@ -1190,7 +1193,8 @@ public class BatchRefUpdateTest extends LocalDiskRepositoryTestCase { } Map<String, Ref> refs = diskRepo.getRefDatabase() - .getRefs(RefDatabase.ALL); + .getRefsByPrefix(RefDatabase.ALL).stream() + .collect(Collectors.toMap(Ref::getName, Function.identity())); Ref actualHead = refs.remove(Constants.HEAD); if (actualHead != null) { String actualLeafName = actualHead.getLeaf().getName(); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileReftableStackTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileReftableStackTest.java index 6c74f0079a..6c7992716c 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileReftableStackTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileReftableStackTest.java @@ -14,6 +14,7 @@ import static org.eclipse.jgit.lib.Ref.Storage.PACKED; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; +import static org.junit.Assume.assumeFalse; import java.io.File; import java.io.FileNotFoundException; @@ -32,10 +33,12 @@ import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectIdRef; import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.util.FileUtils; +import org.eclipse.jgit.util.SystemReader; import org.junit.After; import org.junit.Before; import org.junit.Test; + public class FileReftableStackTest { private static Ref newRef(String name, ObjectId id) { @@ -115,9 +118,12 @@ public class FileReftableStackTest { testCompaction(1024); } - @SuppressWarnings({ "resource", "unused" }) + @SuppressWarnings("resource") @Test public void missingReftable() throws Exception { + // Can't delete in-use files on Windows. + assumeFalse(SystemReader.getInstance().isWindows()); + try (FileReftableStack stack = new FileReftableStack( new File(reftableDir, "refs"), reftableDir, null, () -> new Config())) { diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcTestCase.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcTestCase.java index bfb233f77f..48f6e06385 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcTestCase.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcTestCase.java @@ -42,6 +42,7 @@ public abstract class GcTestCase extends LocalDiskRepositoryTestCase { @Override @After public void tearDown() throws Exception { + tr.close(); super.tearDown(); } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/LockFileTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/LockFileTest.java index 509935dfb9..7eab1dcb09 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/LockFileTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/LockFileTest.java @@ -200,4 +200,16 @@ public class LockFileTest extends RepositoryTestCase { assertFalse(lock.isLocked()); checkFile(f, "contentother"); } + + @Test + public void testUnlockNoop() throws Exception { + File f = writeTrashFile("somefile", "content"); + try { + LockFile lock = new LockFile(f); + lock.unlock(); + lock.unlock(); + } catch (Throwable e) { + fail("unlock should be noop if not locked at all."); + } + } } 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 1ff2264f67..3fe8f52fba 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 @@ -722,6 +722,7 @@ public class PackWriterTest extends SampleDataRepositoryTestCase { */ private FileRepository setUpRepoWithMultiplePackfiles() throws Exception { FileRepository fileRepository = createWorkRepository(); + addRepoToClose(fileRepository); try (Git git = new Git(fileRepository)) { // Creates 2 objects (C1 = commit, T1 = tree) git.commit().setMessage("First commit").call(); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/io/CancellableDigestOutputStreamTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/io/CancellableDigestOutputStreamTest.java new file mode 100644 index 0000000000..09a7c0b28a --- /dev/null +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/io/CancellableDigestOutputStreamTest.java @@ -0,0 +1,105 @@ +/* + * Copyright (C) 2022, Tencent. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Distribution License v. 1.0 which is available at + * https://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +package org.eclipse.jgit.internal.storage.io; + +import static org.eclipse.jgit.internal.storage.io.CancellableDigestOutputStream.BYTES_TO_WRITE_BEFORE_CANCEL_CHECK; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThrows; +import static org.junit.Assert.assertTrue; + +import java.io.InterruptedIOException; + +import org.eclipse.jgit.lib.ProgressMonitor; +import org.eclipse.jgit.util.io.NullOutputStream; +import org.junit.Test; + +public class CancellableDigestOutputStreamTest { + private static class CancelledTestMonitor implements ProgressMonitor { + + private boolean cancelled = false; + + public void setCancelled(boolean cancelled) { + this.cancelled = cancelled; + } + + @Override + public void start(int totalTasks) { + // not implemented + } + + @Override + public void beginTask(String title, int totalWork) { + // not implemented + } + + @Override + public void update(int completed) { + // not implemented + } + + @Override + public void endTask() { + // not implemented + } + + @Override + public boolean isCancelled() { + return cancelled; + } + } + + @Test + public void testCancelInProcess() throws Exception { + CancelledTestMonitor m = new CancelledTestMonitor(); + try (CancellableDigestOutputStream out = new CancellableDigestOutputStream( + m, NullOutputStream.INSTANCE)) { + byte[] KB = new byte[1024]; + int triggerCancelWriteCnt = BYTES_TO_WRITE_BEFORE_CANCEL_CHECK + / KB.length; + for (int i = 0; i < triggerCancelWriteCnt + 1; i++) { + out.write(KB); + } + assertTrue(out.length() > BYTES_TO_WRITE_BEFORE_CANCEL_CHECK); + m.setCancelled(true); + + for (int i = 0; i < triggerCancelWriteCnt - 1; i++) { + out.write(KB); + } + + long lastLength = out.length(); + assertThrows(InterruptedIOException.class, () -> { + out.write(1); + }); + assertEquals(lastLength, out.length()); + + assertThrows(InterruptedIOException.class, () -> { + out.write(new byte[1]); + }); + assertEquals(lastLength, out.length()); + } + } + + @Test + public void testTriggerCheckAfterSingleBytes() throws Exception { + CancelledTestMonitor m = new CancelledTestMonitor(); + try (CancellableDigestOutputStream out = new CancellableDigestOutputStream( + m, NullOutputStream.INSTANCE)) { + + byte[] bytes = new byte[BYTES_TO_WRITE_BEFORE_CANCEL_CHECK + 1]; + m.setCancelled(true); + + assertThrows(InterruptedIOException.class, () -> { + out.write(bytes); + }); + assertEquals(BYTES_TO_WRITE_BEFORE_CANCEL_CHECK, out.length()); + } + } +} diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/transport/ssh/OpenSshConfigFileTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/transport/ssh/OpenSshConfigFileTest.java index 11741b41aa..d065280778 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/transport/ssh/OpenSshConfigFileTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/transport/ssh/OpenSshConfigFileTest.java @@ -369,20 +369,21 @@ public class OpenSshConfigFileTest extends RepositoryTestCase { @Test public void testListValueSingle() throws Exception { - config("Host orcz\nUserKnownHostsFile /foo/bar\n"); + config("Host orcz\nUserKnownHostsFile ~/foo/bar\n"); final HostConfig c = lookup("orcz"); assertNotNull(c); - assertEquals("/foo/bar", c.getValue("UserKnownHostsFile")); + assertEquals(new File(home, "foo/bar").getPath(), + c.getValue("UserKnownHostsFile")); } @Test public void testListValueMultiple() throws Exception { // Tilde expansion occurs within the parser - config("Host orcz\nUserKnownHostsFile \"~/foo/ba z\" /foo/bar \n"); + config("Host orcz\nUserKnownHostsFile \"~/foo/ba z\" ~/foo/bar \n"); final HostConfig c = lookup("orcz"); assertNotNull(c); assertArrayEquals(new Object[] { new File(home, "foo/ba z").getPath(), - "/foo/bar" }, + new File(home, "foo/bar").getPath() }, c.getValues("UserKnownHostsFile").toArray()); } @@ -403,22 +404,23 @@ public class OpenSshConfigFileTest extends RepositoryTestCase { @Test public void testIdentityFile() throws Exception { - config("Host orcz\nIdentityFile \"~/foo/ba z\"\nIdentityFile /foo/bar"); + config("Host orcz\nIdentityFile \"~/foo/ba z\"\nIdentityFile ~/foo/bar"); final HostConfig h = lookup("orcz"); assertNotNull(h); // Does tilde replacement assertArrayEquals(new Object[] { new File(home, "foo/ba z").getPath(), - "/foo/bar" }, + new File(home, "foo/bar").getPath() }, h.getValues(SshConstants.IDENTITY_FILE).toArray()); } @Test public void testMultiIdentityFile() throws Exception { - config("IdentityFile \"~/foo/ba z\"\nHost orcz\nIdentityFile /foo/bar\nHOST *\nIdentityFile /foo/baz"); + config("IdentityFile \"~/foo/ba z\"\nHost orcz\nIdentityFile ~/foo/bar\nHOST *\nIdentityFile ~/foo/baz"); final HostConfig h = lookup("orcz"); assertNotNull(h); assertArrayEquals(new Object[] { new File(home, "foo/ba z").getPath(), - "/foo/bar", "/foo/baz" }, + new File(home, "foo/bar").getPath(), + new File(home, "foo/baz").getPath() }, h.getValues(SshConstants.IDENTITY_FILE).toArray()); } @@ -434,23 +436,23 @@ public class OpenSshConfigFileTest extends RepositoryTestCase { @Test public void testPattern() throws Exception { - config("Host repo.or.cz\nIdentityFile ~/foo/bar\nHOST *.or.cz\nIdentityFile /foo/baz"); + config("Host repo.or.cz\nIdentityFile ~/foo/bar\nHOST *.or.cz\nIdentityFile ~/foo/baz"); final HostConfig h = lookup("repo.or.cz"); assertNotNull(h); assertIdentity(new File(home, "foo/bar"), h); assertArrayEquals(new Object[] { new File(home, "foo/bar").getPath(), - "/foo/baz" }, + new File(home, "foo/baz").getPath() }, h.getValues(SshConstants.IDENTITY_FILE).toArray()); } @Test public void testMultiHost() throws Exception { - config("Host orcz *.or.cz\nIdentityFile ~/foo/bar\nHOST *.or.cz\nIdentityFile /foo/baz"); + config("Host orcz *.or.cz\nIdentityFile ~/foo/bar\nHOST *.or.cz\nIdentityFile ~/foo/baz"); final HostConfig h1 = lookup("repo.or.cz"); assertNotNull(h1); assertIdentity(new File(home, "foo/bar"), h1); assertArrayEquals(new Object[] { new File(home, "foo/bar").getPath(), - "/foo/baz" }, + new File(home, "foo/baz").getPath() }, h1.getValues(SshConstants.IDENTITY_FILE).toArray()); final HostConfig h2 = lookup("orcz"); assertNotNull(h2); @@ -547,18 +549,36 @@ public class OpenSshConfigFileTest extends RepositoryTestCase { @Test public void testEnVarSubstitution() throws Exception { - config("Host orcz\nIdentityFile /tmp/${TST_VAR}\n" - + "CertificateFile /tmp/${}/foo\nUser ${TST_VAR}\nIdentityAgent /tmp/${TST_VAR/bar"); + config("Host orcz\nIdentityFile ~/tmp/${TST_VAR}\n" + + "CertificateFile ~/tmp/${}/foo\nUser ${TST_VAR}\nIdentityAgent ~/tmp/${TST_VAR/bar"); HostConfig h = lookup("orcz"); assertNotNull(h); - assertEquals("/tmp/TEST", + File tmp = new File(home, "tmp"); + assertEquals(new File(tmp, "TEST").getPath(), h.getValue(SshConstants.IDENTITY_FILE)); // No variable name - assertEquals("/tmp/${}/foo", h.getValue(SshConstants.CERTIFICATE_FILE)); + assertEquals(new File(new File(tmp, "${}"), "foo").getPath(), + h.getValue(SshConstants.CERTIFICATE_FILE)); // User doesn't get env var substitution: assertUser("${TST_VAR}", h); // Unterminated: - assertEquals("/tmp/${TST_VAR/bar", + assertEquals(new File(new File(tmp, "${TST_VAR"), "bar").getPath(), + h.getValue(SshConstants.IDENTITY_AGENT)); + } + + @Test + public void testIdentityAgentNone() throws Exception { + config("Host orcz\nIdentityAgent none\n"); + HostConfig h = lookup("orcz"); + assertEquals(SshConstants.NONE, + h.getValue(SshConstants.IDENTITY_AGENT)); + } + + @Test + public void testIdentityAgentSshAuthSock() throws Exception { + config("Host orcz\nIdentityAgent SSH_AUTH_SOCK\n"); + HostConfig h = lookup("orcz"); + assertEquals(SshConstants.ENV_SSH_AUTH_SOCKET, h.getValue(SshConstants.IDENTITY_AGENT)); } @@ -607,13 +627,16 @@ public class OpenSshConfigFileTest extends RepositoryTestCase { @Test public void testMultipleMatch() throws Exception { - config("Host foo.bar\nPort 29418\nIdentityFile /foo\n\n" - + "Host *.bar\nPort 22\nIdentityFile /bar\n" - + "Host foo.bar\nPort 47\nIdentityFile /baz\n"); + config("Host foo.bar\nPort 29418\nIdentityFile ~/foo\n\n" + + "Host *.bar\nPort 22\nIdentityFile ~/bar\n" + + "Host foo.bar\nPort 47\nIdentityFile ~/baz\n"); HostConfig h = lookup("foo.bar"); assertNotNull(h); assertPort(29418, h); - assertArrayEquals(new Object[] { "/foo", "/bar", "/baz" }, + assertArrayEquals( + new Object[] { new File(home, "foo").getPath(), + new File(home, "bar").getPath(), + new File(home, "baz").getPath() }, h.getValues(SshConstants.IDENTITY_FILE).toArray()); } @@ -633,4 +656,61 @@ public class OpenSshConfigFileTest extends RepositoryTestCase { assertNotNull(h); assertPort(22, h); } + + @Test + public void testTimeSpec() throws Exception { + assertEquals(-1, OpenSshConfigFile.timeSpec(null)); + assertEquals(-1, OpenSshConfigFile.timeSpec("")); + assertEquals(-1, OpenSshConfigFile.timeSpec(" ")); + assertEquals(-1, OpenSshConfigFile.timeSpec("s")); + assertEquals(-1, OpenSshConfigFile.timeSpec(" s")); + assertEquals(-1, OpenSshConfigFile.timeSpec(" +s")); + assertEquals(-1, OpenSshConfigFile.timeSpec(" -s")); + assertEquals(-1, OpenSshConfigFile.timeSpec("1ms")); + assertEquals(600, OpenSshConfigFile.timeSpec("600")); + assertEquals(600, OpenSshConfigFile.timeSpec("600s")); + assertEquals(600, OpenSshConfigFile.timeSpec(" 600s")); + assertEquals(600, OpenSshConfigFile.timeSpec(" 600s ")); + assertEquals(600, OpenSshConfigFile.timeSpec("\t600s")); + assertEquals(600, OpenSshConfigFile.timeSpec(" \t600 ")); + assertEquals(-1, OpenSshConfigFile.timeSpec(" 600 s ")); + assertEquals(-1, OpenSshConfigFile.timeSpec("600 s")); + assertEquals(600, OpenSshConfigFile.timeSpec("10m")); + assertEquals(5400, OpenSshConfigFile.timeSpec("1h30m")); + assertEquals(5400, OpenSshConfigFile.timeSpec("1h 30m")); + assertEquals(5400, OpenSshConfigFile.timeSpec("1h \t30m")); + assertEquals(5400, OpenSshConfigFile.timeSpec("1h+30m")); + assertEquals(5400, OpenSshConfigFile.timeSpec("1h +30m")); + assertEquals(-1, OpenSshConfigFile.timeSpec("1h + 30m")); + assertEquals(-1, OpenSshConfigFile.timeSpec("1h -30m")); + assertEquals(3630, OpenSshConfigFile.timeSpec("1h30s")); + assertEquals(5400, OpenSshConfigFile.timeSpec("30m 1h")); + assertEquals(3600, OpenSshConfigFile.timeSpec("30m 30m")); + assertEquals(60, OpenSshConfigFile.timeSpec("30 30")); + assertEquals(0, OpenSshConfigFile.timeSpec("0")); + assertEquals(1, OpenSshConfigFile.timeSpec("1")); + assertEquals(1, OpenSshConfigFile.timeSpec("1S")); + assertEquals(1, OpenSshConfigFile.timeSpec("1s")); + assertEquals(60, OpenSshConfigFile.timeSpec("1M")); + assertEquals(60, OpenSshConfigFile.timeSpec("1m")); + assertEquals(3600, OpenSshConfigFile.timeSpec("1H")); + assertEquals(3600, OpenSshConfigFile.timeSpec("1h")); + assertEquals(86400, OpenSshConfigFile.timeSpec("1D")); + assertEquals(86400, OpenSshConfigFile.timeSpec("1d")); + assertEquals(604800, OpenSshConfigFile.timeSpec("1W")); + assertEquals(604800, OpenSshConfigFile.timeSpec("1w")); + assertEquals(172800, OpenSshConfigFile.timeSpec("2d")); + assertEquals(604800, OpenSshConfigFile.timeSpec("1w")); + assertEquals(604800 + 172800 + 3 * 3600 + 30 * 60 + 10, + OpenSshConfigFile.timeSpec("1w2d3h30m10s")); + assertEquals(-1, OpenSshConfigFile.timeSpec("-7")); + assertEquals(-1, OpenSshConfigFile.timeSpec("-9d")); + assertEquals(Integer.MAX_VALUE, OpenSshConfigFile + .timeSpec(Integer.toString(Integer.MAX_VALUE))); + assertEquals(-1, OpenSshConfigFile + .timeSpec(Long.toString(Integer.MAX_VALUE + 1L))); + assertEquals(-1, OpenSshConfigFile + .timeSpec(Integer.toString(Integer.MAX_VALUE / 60 + 1) + 'M')); + assertEquals(-1, OpenSshConfigFile.timeSpec("1000000000000000000000w")); + } } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/AbbrevConfigTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/AbbrevConfigTest.java new file mode 100644 index 0000000000..96ace08dd1 --- /dev/null +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/AbbrevConfigTest.java @@ -0,0 +1,128 @@ +/* + * Copyright (C) 2022, Matthias Sohn <matthias.sohn@sap.com> and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Distribution License v. 1.0 which is available at + * https://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: BSD-3-Clause + */ +package org.eclipse.jgit.lib; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThrows; + +import java.io.IOException; + +import org.eclipse.jgit.api.errors.InvalidConfigurationException; +import org.eclipse.jgit.junit.RepositoryTestCase; +import org.eclipse.jgit.storage.file.FileBasedConfig; +import org.junit.Test; + +public class AbbrevConfigTest extends RepositoryTestCase { + + @Test + public void testDefault() throws Exception { + assertEquals(7, testCoreAbbrev(null)); + } + + @Test + public void testAuto() throws Exception { + assertEquals(7, testCoreAbbrev("auto")); + } + + @Test + public void testNo() throws Exception { + assertEquals(40, testCoreAbbrev("no")); + } + + @Test + public void testValidMin() throws Exception { + assertEquals(4, testCoreAbbrev("4")); + } + + @Test + public void testValid() throws Exception { + assertEquals(22, testCoreAbbrev("22")); + } + + @Test + public void testValidMax() throws Exception { + assertEquals(40, testCoreAbbrev("40")); + } + + @Test + public void testInvalid() { + assertThrows(InvalidConfigurationException.class, + () -> testCoreAbbrev("foo")); + } + + @Test + public void testInvalid2() { + assertThrows(InvalidConfigurationException.class, + () -> testCoreAbbrev("2k")); + } + + @Test + public void testInvalidNegative() { + assertThrows(InvalidConfigurationException.class, + () -> testCoreAbbrev("-1000")); + } + + @Test + public void testInvalidBelowRange() { + assertThrows(InvalidConfigurationException.class, + () -> testCoreAbbrev("3")); + } + + @Test + public void testInvalidBelowRange2() { + assertThrows(InvalidConfigurationException.class, + () -> testCoreAbbrev("-1")); + } + + @Test + public void testInvalidAboveRange() { + assertThrows(InvalidConfigurationException.class, + () -> testCoreAbbrev("41")); + } + + @Test + public void testInvalidAboveRange2() { + assertThrows(InvalidConfigurationException.class, + () -> testCoreAbbrev("100000")); + } + + @Test + public void testToStringNo() + throws InvalidConfigurationException, IOException { + assertEquals("40", setCoreAbbrev("no").toString()); + } + + @Test + public void testToString() + throws InvalidConfigurationException, IOException { + assertEquals("7", setCoreAbbrev("auto").toString()); + } + + @Test + public void testToString12() + throws InvalidConfigurationException, IOException { + assertEquals("12", setCoreAbbrev("12").toString()); + } + + private int testCoreAbbrev(String value) + throws InvalidConfigurationException, IOException { + return setCoreAbbrev(value).get(); + } + + private AbbrevConfig setCoreAbbrev(String value) + throws IOException, InvalidConfigurationException { + FileBasedConfig config = db.getConfig(); + config.setString(ConfigConstants.CONFIG_CORE_SECTION, null, + ConfigConstants.CONFIG_KEY_ABBREV, value); + config.save(); + return AbbrevConfig.parseFromConfig(db); + } + +} diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/CommitConfigTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/CommitConfigTest.java new file mode 100644 index 0000000000..7066f9d422 --- /dev/null +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/CommitConfigTest.java @@ -0,0 +1,258 @@ +/* + * Copyright (C) 2022, Thomas Wolf <thomas.wolf@paranor.ch> and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Distribution License v. 1.0 which is available at + * https://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +package org.eclipse.jgit.lib; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertThrows; +import static org.junit.Assert.assertTrue; + +import org.eclipse.jgit.errors.ConfigInvalidException; +import org.eclipse.jgit.lib.CommitConfig.CleanupMode; +import org.junit.Test; + +public class CommitConfigTest { + + @Test + public void testDefaults() throws Exception { + CommitConfig cfg = parse(""); + assertEquals("Unexpected clean-up mode", CleanupMode.DEFAULT, |