Browse Source

Add testCleanDirsWithSubmodule test to CleanCommandTest

This commit adds some test coverage to cleaning a repository with a
submodule, which did not previously exist.

Bug: 498367
Change-Id: Ia5c4e4cc53488800dd486f8556dc57656783f1c4
Signed-off-by: Matthaus Owens <matthaus@puppetlabs.com>
tags/v4.5.0.201609210915-r
Matthaus Owens 7 years ago
parent
commit
0ee89f01be
1 changed files with 28 additions and 0 deletions
  1. 28
    0
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CleanCommandTest.java

+ 28
- 0
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CleanCommandTest.java View File

@@ -45,6 +45,7 @@ package org.eclipse.jgit.api;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.eclipse.jgit.lib.Constants.DOT_GIT_MODULES;

import java.util.Set;
import java.util.TreeSet;
@@ -52,6 +53,7 @@ import java.util.TreeSet;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.errors.NoWorkTreeException;
import org.eclipse.jgit.junit.RepositoryTestCase;
import org.eclipse.jgit.lib.Repository;
import org.junit.Before;
import org.junit.Test;

@@ -227,4 +229,30 @@ public class CleanCommandTest extends RepositoryTestCase {
assertTrue(cleanedFiles.contains("ignored-dir/"));
}

@Test
public void testCleanDirsWithSubmodule() throws Exception {
SubmoduleAddCommand command = new SubmoduleAddCommand(db);
String path = "sub";
command.setPath(path);
String uri = db.getDirectory().toURI().toString();
command.setURI(uri);
Repository repo = command.call();
repo.close();

Status beforeCleanStatus = git.status().call();
assertTrue(beforeCleanStatus.getAdded().contains(DOT_GIT_MODULES));
assertTrue(beforeCleanStatus.getAdded().contains(path));

Set<String> cleanedFiles = git.clean().setCleanDirectories(true).call();

// The submodule should not be cleaned.
assertTrue(!cleanedFiles.contains(path + "/"));

assertTrue(cleanedFiles.contains("File2.txt"));
assertTrue(cleanedFiles.contains("File3.txt"));
assertTrue(!cleanedFiles.contains("sub-noclean/File1.txt"));
assertTrue(cleanedFiles.contains("sub-noclean/File2.txt"));
assertTrue(cleanedFiles.contains("sub-clean/"));
assertTrue(cleanedFiles.size() == 4);
}
}

Loading…
Cancel
Save