]> source.dussan.org Git - jgit.git/commitdiff
Allow commit when submodule changes are present 94/4194/4
authorRobin Rosenberg <robin.rosenberg@dewire.com>
Sun, 4 Sep 2011 14:34:15 +0000 (16:34 +0200)
committerRobin Rosenberg <robin.rosenberg@dewire.com>
Thu, 8 Sep 2011 14:46:20 +0000 (16:46 +0200)
We do not yet check or validate submodules, but can accept that
someone staged a change in a submodule with other tools.

Change-Id: I642ede382314bfbd1892dd509a2222885cc5350a
Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
org.eclipse.jgit/src/org/eclipse/jgit/api/CommitCommand.java

index 2412e2c6c0b51617ad02537251eb45a9326d6a9d..d794c797b466cf111410c55d01779107cbc0274b 100644 (file)
@@ -66,6 +66,7 @@ import org.eclipse.jgit.dircache.DirCacheIterator;
 import org.eclipse.jgit.errors.UnmergedPathException;
 import org.eclipse.jgit.lib.CommitBuilder;
 import org.eclipse.jgit.lib.Constants;
+import org.eclipse.jgit.lib.FileMode;
 import org.eclipse.jgit.lib.ObjectId;
 import org.eclipse.jgit.lib.ObjectInserter;
 import org.eclipse.jgit.lib.PersonIdent;
@@ -341,17 +342,24 @@ public class CommitCommand extends GitCommand<RevCommit> {
                                        if (objectExists) {
                                                dcEntry.setObjectId(fTree.getEntryObjectId());
                                        } else {
-                                               // insert object
-                                               if (inserter == null)
-                                                       inserter = repo.newObjectInserter();
-
-                                               InputStream inputStream = fTree.openEntryStream();
-                                               try {
-                                                       dcEntry.setObjectId(inserter.insert(
-                                                                       Constants.OBJ_BLOB, entryLength,
-                                                                       inputStream));
-                                               } finally {
-                                                       inputStream.close();
+                                               if (FileMode.GITLINK.equals(dcEntry.getFileMode())) {
+                                                       // Do not check the content of submodule entries
+                                                       // Use the old entry information instead.
+                                                       dcEntry.copyMetaData(index.getEntry(dcEntry
+                                                                       .getPathString()));
+                                               } else {
+                                                       // insert object
+                                                       if (inserter == null)
+                                                               inserter = repo.newObjectInserter();
+
+                                                       InputStream inputStream = fTree.openEntryStream();
+                                                       try {
+                                                               dcEntry.setObjectId(inserter.insert(
+                                                                               Constants.OBJ_BLOB, entryLength,
+                                                                               inputStream));
+                                                       } finally {
+                                                               inputStream.close();
+                                                       }
                                                }
                                        }