changeset 461:613c883e360e

Do not walk into nested repositories at all, ignore not only .hg but whole nested repo
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Wed, 20 Jun 2012 16:51:18 +0200
parents 5311e041d2dd
children ad0322a4af20
files src/org/tmatesoft/hg/util/FileWalker.java test-data/test-repos.jar test/org/tmatesoft/hg/test/TestStatus.java
diffstat 3 files changed, 22 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/util/FileWalker.java	Wed Jun 20 16:49:43 2012 +0200
+++ b/src/org/tmatesoft/hg/util/FileWalker.java	Wed Jun 20 16:51:18 2012 +0200
@@ -130,7 +130,11 @@
 						continue;
 					}
 					if (isDir) {
-						if (!".hg/".equals(path.toString())) {
+						// do not dive into <repo>/.hg and
+						// if there's .hg/ under f/, it's a nested repository, which shall not be walked into
+						if (".hg".equals(f.getName()) || new File(f, ".hg").isDirectory()) {
+							continue;
+						} else {
 							dirQueue.addLast(f);
 						}
 					} else {
Binary file test-data/test-repos.jar has changed
--- a/test/org/tmatesoft/hg/test/TestStatus.java	Wed Jun 20 16:49:43 2012 +0200
+++ b/test/org/tmatesoft/hg/test/TestStatus.java	Wed Jun 20 16:51:18 2012 +0200
@@ -641,6 +641,23 @@
 		}
 		assertTrue(sc.getErrors().isEmpty());
 	}
+	
+	@Test
+	public void testNestedRepositoriesAreNotWalkedIn() throws Exception {
+		repo = Configuration.get().find("status-nested-repo");
+		File s2 = new File(repo.getWorkingDir(), "skip/s2/.hg/");
+		File s1 = new File(repo.getWorkingDir(), "s1/.hg/");
+		File s1b = new File(repo.getWorkingDir(), "s1/b");
+		assertTrue("[sanity]", s1.exists() && s1.isDirectory());
+		assertTrue("[sanity]", s1b.exists() && s1b.isFile());
+		assertTrue("[sanity]", s2.exists() && s2.isDirectory());
+		StatusCollector sc = new StatusCollector();
+		new HgStatusCommand(repo).all().execute(sc);
+		List<Path> ignored = sc.get(Ignored);
+		assertEquals(1, ignored.size());
+		assertEquals(Path.create("skip/a"), ignored.get(0));
+		assertTrue(sc.get(Path.create("s1/b")).isEmpty());
+	}
 
 	/*
 	 * With warm-up of previous tests, 10 runs, time in milliseconds