aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test/exttst
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2021-05-07 10:51:59 +0200
committerMatthias Sohn <matthias.sohn@sap.com>2021-05-09 22:49:19 +0200
commite6192c56af76189c27096ad81b38a4b64b250a26 (patch)
tree0e94032e028eb93357e5340bd265cb679761c3a1 /org.eclipse.jgit.test/exttst
parentcc07a471dcd83740d4a8efc4a5323d83eb60d2fb (diff)
downloadjgit-e6192c56af76189c27096ad81b38a4b64b250a26.tar.gz
jgit-e6192c56af76189c27096ad81b38a4b64b250a26.zip
Add a cgit interoperability test for LockFile
Change-Id: I30cacd1f50f8f4ff4dd91ad291bf279980e3c4b5 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit.test/exttst')
-rw-r--r--org.eclipse.jgit.test/exttst/org/eclipse/jgit/internal/storage/file/CGitLockFileTest.java57
1 files changed, 57 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/exttst/org/eclipse/jgit/internal/storage/file/CGitLockFileTest.java b/org.eclipse.jgit.test/exttst/org/eclipse/jgit/internal/storage/file/CGitLockFileTest.java
new file mode 100644
index 0000000000..4c194752b4
--- /dev/null
+++ b/org.eclipse.jgit.test/exttst/org/eclipse/jgit/internal/storage/file/CGitLockFileTest.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2021 SAP SE 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.storage.file;
+
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import org.eclipse.jgit.api.Git;
+import org.eclipse.jgit.junit.RepositoryTestCase;
+import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.jgit.util.FS;
+import org.eclipse.jgit.util.FS.ExecutionResult;
+import org.junit.Test;
+
+/**
+ * Unit tests of {@link LockFile} testing interoperability with C git
+ */
+public class CGitLockFileTest extends RepositoryTestCase {
+
+ @Test
+ public void testLockedTwiceFails() throws Exception {
+ try (Git git = new Git(db)) {
+ writeTrashFile("file.txt", "content");
+ git.add().addFilepattern("file.txt").call();
+ RevCommit commit1 = git.commit().setMessage("create file").call();
+
+ assertNotNull(commit1);
+ writeTrashFile("file.txt", "content2");
+ git.add().addFilepattern("file.txt").call();
+ assertNotNull(git.commit().setMessage("edit file").call());
+
+ LockFile lf = new LockFile(db.getIndexFile());
+ assertTrue(lf.lock());
+ try {
+ String[] command = new String[] { "git", "checkout",
+ commit1.name() };
+ ProcessBuilder pb = new ProcessBuilder(command);
+ pb.directory(db.getWorkTree());
+ ExecutionResult result = FS.DETECTED.execute(pb, null);
+ assertNotEquals(0, result.getRc());
+ String err = result.getStderr().toString().split("\\R")[0];
+ assertTrue(err.matches(
+ "fatal: Unable to create .*/\\.git/index\\.lock': File exists\\."));
+ } finally {
+ lf.unlock();
+ }
+ }
+ }
+}