summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/server/RootLocaleTest.java60
-rw-r--r--org.eclipse.jgit.packaging/org.eclipse.jgit.repository/assembly.xml14
-rw-r--r--org.eclipse.jgit.packaging/org.eclipse.jgit.repository/pom.xml28
-rw-r--r--org.eclipse.jgit.packaging/org.eclipse.jgit.repository/site.xml (renamed from org.eclipse.jgit.packaging/org.eclipse.jgit.repository/category.xml)0
-rw-r--r--org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ConfigTest.java70
-rw-r--r--org.eclipse.jgit.pgm/META-INF/services/org.eclipse.jgit.pgm.TextBuiltin1
-rw-r--r--org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/CLIText.properties1
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Config.java121
-rw-r--r--org.eclipse.jgit.test/META-INF/MANIFEST.MF1
-rw-r--r--org.eclipse.jgit.test/pom.xml6
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ResetCommandTest.java20
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/nls/RootLocaleTest.java6
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorTest.java22
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/ResetCommand.java2
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCache.java45
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheEntry.java7
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/storage/file/LockFile.java10
17 files changed, 381 insertions, 33 deletions
diff --git a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/server/RootLocaleTest.java b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/server/RootLocaleTest.java
new file mode 100644
index 0000000000..a24c86d971
--- /dev/null
+++ b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/server/RootLocaleTest.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2010, Sasa Zivkov <sasa.zivkov@sap.com>
+ * and other copyright owners as documented in the project's IP log.
+ *
+ * This program and the accompanying materials are made available
+ * under the terms of the Eclipse Distribution License v1.0 which
+ * accompanies this distribution, is reproduced below, and is
+ * available at http://www.eclipse.org/org/documents/edl-v10.php
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * - Neither the name of the Eclipse Foundation, Inc. nor the
+ * names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package org.eclipse.jgit.http.server;
+
+import org.eclipse.jgit.nls.NLS;
+import org.junit.Before;
+import org.junit.Test;
+
+public class RootLocaleTest {
+ @Before
+ public void setUp() {
+ NLS.setLocale(NLS.ROOT_LOCALE);
+ }
+
+ @Test
+ public void testHttpServerText() {
+ NLS.getBundleFor(HttpServerText.class);
+ }
+}
diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.repository/assembly.xml b/org.eclipse.jgit.packaging/org.eclipse.jgit.repository/assembly.xml
new file mode 100644
index 0000000000..5bcf746028
--- /dev/null
+++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.repository/assembly.xml
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<assembly>
+ <id>site</id>
+ <formats>
+ <format>zip</format>
+ </formats>
+ <includeBaseDirectory>false</includeBaseDirectory>
+ <fileSets>
+ <fileSet>
+ <directory>${project.build.directory}/site</directory>
+ <outputDirectory>/</outputDirectory>
+ </fileSet>
+ </fileSets>
+</assembly> \ No newline at end of file
diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.repository/pom.xml b/org.eclipse.jgit.packaging/org.eclipse.jgit.repository/pom.xml
index 0cf09dd652..f088af1953 100644
--- a/org.eclipse.jgit.packaging/org.eclipse.jgit.repository/pom.xml
+++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.repository/pom.xml
@@ -54,7 +54,9 @@
</parent>
<artifactId>org.eclipse.jgit.repository</artifactId>
- <packaging>eclipse-repository</packaging>
+ <!-- TODO as soon as Tycho bug 368596 is fixed we should use packaging type
+ eclipse-repository -->
+ <packaging>eclipse-update-site</packaging>
<name>JGit P2 Repository</name>
@@ -80,4 +82,28 @@
<version>2.0.0-SNAPSHOT</version>
</dependency>
</dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <version>2.3</version>
+ <configuration>
+ <descriptors>
+ <descriptor>assembly.xml</descriptor>
+ </descriptors>
+ </configuration>
+ <executions>
+ <execution>
+ <id>make-assembly</id>
+ <phase>package</phase>
+ <goals>
+ <goal>single</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
</project>
diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.repository/category.xml b/org.eclipse.jgit.packaging/org.eclipse.jgit.repository/site.xml
index dd20b56a7a..dd20b56a7a 100644
--- a/org.eclipse.jgit.packaging/org.eclipse.jgit.repository/category.xml
+++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.repository/site.xml
diff --git a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ConfigTest.java b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ConfigTest.java
new file mode 100644
index 0000000000..23dd2600b9
--- /dev/null
+++ b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ConfigTest.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2012, Matthias Sohn <matthias.sohn@sap.com>
+ * and other copyright owners as documented in the project's IP log.
+ *
+ * This program and the accompanying materials are made available
+ * under the terms of the Eclipse Distribution License v1.0 which
+ * accompanies this distribution, is reproduced below, and is
+ * available at http://www.eclipse.org/org/documents/edl-v10.php
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * - Neither the name of the Eclipse Foundation, Inc. nor the
+ * names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.eclipse.jgit.pgm;
+
+import static org.junit.Assert.assertArrayEquals;
+
+import org.eclipse.jgit.api.Git;
+import org.eclipse.jgit.lib.CLIRepositoryTestCase;
+import org.junit.Before;
+import org.junit.Test;
+
+public class ConfigTest extends CLIRepositoryTestCase {
+ @Override
+ @Before
+ public void setUp() throws Exception {
+ super.setUp();
+ new Git(db).commit().setMessage("initial commit").call();
+ }
+
+ @Test
+ public void testListConfig() throws Exception {
+ String[] output = execute("git config --list");
+ assertArrayEquals("expected default configuration", //
+ new String[] { "core.autocrlf=false", //
+ "core.filemode=true", //
+ "core.logallrefupdates=true", //
+ "core.repositoryformatversion=0", //
+ "" /* ends with LF (last line empty) */}, output);
+ }
+}
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 6562423f89..e304e1efaa 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
@@ -5,6 +5,7 @@ org.eclipse.jgit.pgm.Branch
org.eclipse.jgit.pgm.Checkout
org.eclipse.jgit.pgm.Clone
org.eclipse.jgit.pgm.Commit
+org.eclipse.jgit.pgm.Config
org.eclipse.jgit.pgm.Daemon
org.eclipse.jgit.pgm.Diff
org.eclipse.jgit.pgm.DiffTree
diff --git a/org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/CLIText.properties b/org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/CLIText.properties
index 5b244eb8bc..f0ab55f696 100644
--- a/org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/CLIText.properties
+++ b/org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/CLIText.properties
@@ -206,6 +206,7 @@ usage_forEachRefOutput=for-each-ref output
usage_forceCheckout=when switching branches, proceed even if the index or the working tree differs from HEAD
usage_forceCreateBranchEvenExists=force create branch even exists
usage_forceReplacingAnExistingTag=force replacing an existing tag
+usage_getAndSetOptions=Get and set repository or global options
usage_hostnameOrIpToListenOn=hostname (or ip) to listen on
usage_indexFileFormatToCreate=index file format to create
usage_ignoreWhitespace=ignore all whitespace
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Config.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Config.java
new file mode 100644
index 0000000000..f2cd920580
--- /dev/null
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Config.java
@@ -0,0 +1,121 @@
+/*
+ * Copyright (C) 2012, Tomasz Zarna <Tomasz.Zarna@pl.ibm.com> and
+ * other copyright owners as documented in the project's IP log.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Distribution License v1.0 which accompanies this
+ * distribution, is reproduced below, and is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * - Neither the name of the Eclipse Foundation, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.eclipse.jgit.pgm;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Set;
+
+import org.eclipse.jgit.errors.ConfigInvalidException;
+import org.eclipse.jgit.errors.NotSupportedException;
+import org.eclipse.jgit.lib.Constants;
+import org.eclipse.jgit.lib.StoredConfig;
+import org.eclipse.jgit.storage.file.FileBasedConfig;
+import org.eclipse.jgit.util.FS;
+import org.eclipse.jgit.util.SystemReader;
+import org.kohsuke.args4j.Option;
+
+@Command(common = true, usage = "usage_getAndSetOptions")
+class Config extends TextBuiltin {
+ @Option(name = "--system")
+ private boolean system;
+
+ @Option(name = "--global")
+ private boolean global;
+
+ @Option(name = "--local")
+ private boolean local;
+
+ @Option(name = "--list", aliases = { "-l" })
+ private boolean list;
+
+ @Option(name = "--file", aliases = { "-f" })
+ private File configFile;
+
+ @Override
+ protected void run() throws Exception {
+ if (list)
+ list();
+ else
+ throw new NotSupportedException(
+ "only --list option is currently supported");
+ }
+
+ private void list() throws IOException, ConfigInvalidException {
+ final FS fs = getRepository().getFS();
+ if (configFile != null) {
+ list(new FileBasedConfig(configFile, fs));
+ return;
+ }
+ if (system || isListAll())
+ list(SystemReader.getInstance().openSystemConfig(null, fs));
+ if (global || isListAll())
+ list(SystemReader.getInstance().openUserConfig(null, fs));
+ if (local || isListAll())
+ list(new FileBasedConfig(fs.resolve(getRepository().getDirectory(),
+ Constants.CONFIG), fs));
+ }
+
+ private boolean isListAll() {
+ return !system && !global && !local && configFile == null;
+ }
+
+ private void list(StoredConfig config) throws IOException,
+ ConfigInvalidException {
+ config.load();
+ Set<String> sections = config.getSections();
+ for (String section : sections) {
+ Set<String> names = config.getNames(section);
+ for (String name : names) {
+ for (String value : config.getStringList(section, null, name))
+ out.println(section + "." + name + "=" + value);
+ }
+ if (names.isEmpty()) {
+ for (String subsection : config.getSubsections(section)) {
+ names = config.getNames(section, subsection);
+ for (String name : names) {
+ for (String value : config.getStringList(section,
+ subsection, name))
+ out.println(section + "." + subsection + "."
+ + name + "=" + value);
+ }
+ }
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.jgit.test/META-INF/MANIFEST.MF b/org.eclipse.jgit.test/META-INF/MANIFEST.MF
index 5db483b1fa..a7a3e1161d 100644
--- a/org.eclipse.jgit.test/META-INF/MANIFEST.MF
+++ b/org.eclipse.jgit.test/META-INF/MANIFEST.MF
@@ -17,7 +17,6 @@ Import-Package: org.eclipse.jgit.api;version="[2.0.0,2.1.0)",
org.eclipse.jgit.errors;version="[2.0.0,2.1.0)",
org.eclipse.jgit.events;version="[2.0.0,2.1.0)",
org.eclipse.jgit.fnmatch;version="[2.0.0,2.1.0)",
- org.eclipse.jgit.http.server;version="[2.0.0,2.1.0)",
org.eclipse.jgit.ignore;version="[2.0.0,2.1.0)",
org.eclipse.jgit.internal;version="[2.0.0,2.1.0)",
org.eclipse.jgit.iplog;version="[2.0.0,2.1.0)",
diff --git a/org.eclipse.jgit.test/pom.xml b/org.eclipse.jgit.test/pom.xml
index 969e205b0b..7eee851b3e 100644
--- a/org.eclipse.jgit.test/pom.xml
+++ b/org.eclipse.jgit.test/pom.xml
@@ -102,12 +102,6 @@
<dependency>
<groupId>org.eclipse.jgit</groupId>
- <artifactId>org.eclipse.jgit.http.server</artifactId>
- <version>${project.version}</version>
- </dependency>
-
- <dependency>
- <groupId>org.eclipse.jgit</groupId>
<artifactId>org.eclipse.jgit.iplog</artifactId>
<version>${project.version}</version>
</dependency>
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ResetCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ResetCommandTest.java
index f10aaf52e1..27c3549be3 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ResetCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ResetCommandTest.java
@@ -42,6 +42,7 @@
*/
package org.eclipse.jgit.api;
+import static org.eclipse.jgit.api.ResetCommand.ResetType.HARD;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@@ -305,6 +306,25 @@ public class ResetCommandTest extends RepositoryTestCase {
assertFalse(inIndex(untrackedFile.getName()));
}
+ @Test
+ public void testHardResetOnTag() throws Exception {
+ setupRepository();
+ String tagName = "initialtag";
+ git.tag().setName(tagName).setObjectId(secondCommit)
+ .setMessage("message").call();
+
+ DirCacheEntry preReset = DirCache.read(db.getIndexFile(), db.getFS())
+ .getEntry(indexFile.getName());
+ assertNotNull(preReset);
+
+ git.add().addFilepattern(untrackedFile.getName()).call();
+
+ git.reset().setRef(tagName).setMode(HARD).call();
+
+ ObjectId head = db.resolve(Constants.HEAD);
+ assertTrue(head.equals(secondCommit));
+ }
+
private void assertReflog(ObjectId prevHead, ObjectId head)
throws IOException {
// Check the reflog for HEAD
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/nls/RootLocaleTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/nls/RootLocaleTest.java
index 04d95f4e53..4e694b6f4b 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/nls/RootLocaleTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/nls/RootLocaleTest.java
@@ -45,7 +45,6 @@ package org.eclipse.jgit.nls;
import org.eclipse.jgit.awtui.UIText;
import org.eclipse.jgit.console.ConsoleText;
-import org.eclipse.jgit.http.server.HttpServerText;
import org.eclipse.jgit.internal.JGitText;
import org.eclipse.jgit.iplog.IpLogText;
import org.eclipse.jgit.pgm.CLIText;
@@ -64,11 +63,6 @@ public class RootLocaleTest {
}
@Test
- public void testHttpServerText() {
- NLS.getBundleFor(HttpServerText.class);
- }
-
- @Test
public void testConsoleText() {
NLS.getBundleFor(ConsoleText.class);
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorTest.java
index 064100839e..b335f2d43a 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorTest.java
@@ -64,6 +64,7 @@ import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectReader;
import org.eclipse.jgit.lib.RepositoryTestCase;
import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.jgit.treewalk.WorkingTreeIterator.MetadataDiff;
import org.eclipse.jgit.treewalk.filter.PathFilter;
import org.eclipse.jgit.util.FileUtils;
import org.eclipse.jgit.util.RawParseUtils;
@@ -216,6 +217,27 @@ public class FileTreeIteratorTest extends RepositoryTestCase {
}
@Test
+ public void testIsModifiedFileSmudged() throws Exception {
+ File f = writeTrashFile("file", "content");
+ Git git = new Git(db);
+ // The idea of this test is to check the smudged handling
+ // Hopefully fsTick will make sure our entry gets smudged
+ fsTick(f);
+ writeTrashFile("file", "content");
+ git.add().addFilepattern("file").call();
+ writeTrashFile("file", "conten2");
+ DirCacheEntry dce = db.readDirCache().getEntry("file");
+ FileTreeIterator fti = new FileTreeIterator(trash, db.getFS(), db
+ .getConfig().get(WorkingTreeOptions.KEY));
+ while (!fti.getEntryPathString().equals("file"))
+ fti.next(1);
+ // If the fsTick trick does not work we could skip the compareMetaData
+ // test and hope that we are usually testing the intended code path.
+ assertEquals(MetadataDiff.SMUDGED, fti.compareMetadata(dce));
+ assertTrue(fti.isModified(dce, false));
+ }
+
+ @Test
public void submoduleHeadMatchesIndex() throws Exception {
Git git = new Git(db);
writeTrashFile("file.txt", "content");
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/ResetCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/ResetCommand.java
index 60776f903c..422056bd6d 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/ResetCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/ResetCommand.java
@@ -150,7 +150,7 @@ public class ResetCommand extends GitCommand<Ref> {
// resolve the ref to a commit
final ObjectId commitId;
try {
- commitId = repo.resolve(ref);
+ commitId = repo.resolve(ref + "^{commit}");
if (commitId == null) {
// @TODO throw an InvalidRefNameException. We can't do that
// now because this would break the API
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCache.java b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCache.java
index f139b0f7f8..0d5952df24 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCache.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCache.java
@@ -60,8 +60,8 @@ import java.text.MessageFormat;
import java.util.Arrays;
import java.util.Comparator;
-import org.eclipse.jgit.errors.LockFailedException;
import org.eclipse.jgit.errors.CorruptObjectException;
+import org.eclipse.jgit.errors.LockFailedException;
import org.eclipse.jgit.errors.UnmergedPathException;
import org.eclipse.jgit.events.IndexChangedEvent;
import org.eclipse.jgit.events.IndexChangedListener;
@@ -404,6 +404,10 @@ public class DirCache {
if (entryCnt < 0)
throw new CorruptObjectException(JGitText.get().DIRCHasTooManyEntries);
+ snapshot = FileSnapshot.save(liveFile);
+ int smudge_s = (int) (snapshot.lastModified() / 1000);
+ int smudge_ns = ((int) (snapshot.lastModified() % 1000)) * 1000000;
+
// Load the individual file entries.
//
final int infoLength = DirCacheEntry.getMaximumInfoLength(extended);
@@ -412,8 +416,7 @@ public class DirCache {
final MutableInteger infoAt = new MutableInteger();
for (int i = 0; i < entryCnt; i++)
- sortedEntries[i] = new DirCacheEntry(infos, infoAt, in, md);
- snapshot = FileSnapshot.save(liveFile);
+ sortedEntries[i] = new DirCacheEntry(infos, infoAt, in, md, smudge_s, smudge_ns);
// After the file entries are index extensions, and then a footer.
//
@@ -570,21 +573,29 @@ public class DirCache {
dos.write(tmp, 0, 12);
// Write the individual file entries.
- //
- if (snapshot == null) {
- // Write a new index, as no entries require smudging.
- //
- for (int i = 0; i < entryCnt; i++)
- sortedEntries[i].write(dos);
+
+ final int smudge_s;
+ final int smudge_ns;
+ if (myLock != null) {
+ // For new files we need to smudge the index entry
+ // if they have been modified "now". Ideally we'd
+ // want the timestamp when we're done writing the index,
+ // so we use the current timestamp as a approximation.
+ myLock.createCommitSnapshot();
+ snapshot = myLock.getCommitSnapshot();
+ smudge_s = (int) (snapshot.lastModified() / 1000);
+ smudge_ns = ((int) (snapshot.lastModified() % 1000)) * 1000000;
} else {
- final int smudge_s = (int) (snapshot.lastModified() / 1000);
- final int smudge_ns = ((int) (snapshot.lastModified() % 1000)) * 1000000;
- for (int i = 0; i < entryCnt; i++) {
- final DirCacheEntry e = sortedEntries[i];
- if (e.mightBeRacilyClean(smudge_s, smudge_ns))
- e.smudgeRacilyClean();
- e.write(dos);
- }
+ // Used in unit tests only
+ smudge_ns = 0;
+ smudge_s = 0;
+ }
+
+ for (int i = 0; i < entryCnt; i++) {
+ final DirCacheEntry e = sortedEntries[i];
+ if (e.mightBeRacilyClean(smudge_s, smudge_ns))
+ e.smudgeRacilyClean();
+ e.write(dos);
}
if (tree != null) {
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheEntry.java b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheEntry.java
index 9f5aa8cfa1..aec12e3169 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheEntry.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheEntry.java
@@ -141,7 +141,8 @@ public class DirCacheEntry {
private byte inCoreFlags;
DirCacheEntry(final byte[] sharedInfo, final MutableInteger infoAt,
- final InputStream in, final MessageDigest md) throws IOException {
+ final InputStream in, final MessageDigest md, final int smudge_s,
+ final int smudge_ns) throws IOException {
info = sharedInfo;
infoOffset = infoAt.value;
@@ -199,6 +200,10 @@ public class DirCacheEntry {
IO.skipFully(in, padLen);
md.update(nullpad, 0, padLen);
}
+
+ if (mightBeRacilyClean(smudge_s, smudge_ns))
+ smudgeRacilyClean();
+
}
/**
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/LockFile.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/LockFile.java
index f3b533c133..9218121917 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/LockFile.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/LockFile.java
@@ -504,6 +504,16 @@ public class LockFile {
}
/**
+ * Update the commit snapshot {@link #getCommitSnapshot()} before commit.
+ * <p>
+ * This may be necessary if you need time stamp before commit occurs, e.g
+ * while writing the index.
+ */
+ public void createCommitSnapshot() {
+ saveStatInformation();
+ }
+
+ /**
* Unlock this file and abort this change.
* <p>
* The temporary file (if created) is deleted before returning.