Browse Source

Allow for filepattern "." in AddCommand

Enable adding on repository root level.

Change-Id: I415b10dc74cc9435578424d9f106c972fd703055
Signed-off-by: Stefan Lay <stefan.lay@sap.com>
stable-0.9
Stefan Lay 15 years ago
parent
commit
88957f6c5a
  1. 20
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/AddCommandTest.java
  2. 6
      org.eclipse.jgit/src/org/eclipse/jgit/api/AddCommand.java

20
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/AddCommandTest.java

@ -338,6 +338,26 @@ public class AddCommandTest extends RepositoryTestCase {
assertEquals(0, dc.getEntry("sub/a.txt").getStage());
}
public void testAddWholeRepo() throws Exception {
new File(db.getWorkDir(), "sub").mkdir();
File file = new File(db.getWorkDir(), "sub/a.txt");
file.createNewFile();
PrintWriter writer = new PrintWriter(file);
writer.print("content");
writer.close();
File file2 = new File(db.getWorkDir(), "sub/b.txt");
file2.createNewFile();
writer = new PrintWriter(file2);
writer.print("content b");
writer.close();
Git git = new Git(db);
DirCache dc = git.add().addFilepattern(".").call();
assertEquals("sub/a.txt", dc.getEntry("sub/a.txt").getPathString());
assertEquals("sub/b.txt", dc.getEntry("sub/b.txt").getPathString());
}
private DirCacheEntry addEntryToBuilder(String path, File file,
ObjectWriter ow, DirCacheBuilder builder, int stage)
throws IOException {

6
org.eclipse.jgit/src/org/eclipse/jgit/api/AddCommand.java

@ -109,6 +109,9 @@ public class AddCommand extends GitCommand<DirCache> {
throw new NoFilepatternException(JGitText.get().atLeastOnePatternIsRequired);
checkCallable();
DirCache dc = null;
boolean addAll = false;
if (filepatterns.contains("."))
addAll = true;
try {
dc = DirCache.lock(repo);
@ -122,7 +125,8 @@ public class AddCommand extends GitCommand<DirCache> {
FileTreeIterator fileTreeIterator = new FileTreeIterator(repo);
tw.addTree(fileTreeIterator);
tw.setRecursive(true);
tw.setFilter(PathFilterGroup.createFromStrings(filepatterns));
if (!addAll)
tw.setFilter(PathFilterGroup.createFromStrings(filepatterns));
String lastAddedFile = null;

Loading…
Cancel
Save