/*******************************************************************************
 * Copyright (C) 2007, Robin Rosenberg <robin.rosenberg@dewire.com>
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *******************************************************************************/
package org.eclipse.egit.core.test;

import java.io.File;
import java.io.IOException;

import junit.framework.TestCase;

public abstract class GitTestCase extends TestCase {

	protected TestProject project;

	protected File gitDir;

	protected void setUp() throws Exception {
		super.setUp();
		project = new TestProject();
		gitDir = new File(project.getProject().getWorkspace().getRoot()
				.getRawLocation().toFile(), ".git");
		rmrf(gitDir);
	}

	protected void tearDown() throws Exception {
		super.tearDown();
		project.dispose();
		rmrf(gitDir);
	}

	private void rmrf(File d) throws IOException {
		if (!d.exists())
			return;

		File[] files = d.listFiles();
		if (files != null) {
			for (int i = 0; i < files.length; ++i) {
				if (files[i].isDirectory())
					rmrf(files[i]);
				else if (!files[i].delete())
					throw new IOException(files[i] + " in use or undeletable");
			}
		}
		if (!d.delete())
			throw new IOException(d + " in use or undeletable");
		assert !d.exists();
	}

}

@@ -558,16 +558,204 @@
 ception;
+%0Aimport java.util.Collection;%0A%0Aimport org.eclipse.core.runtime.CoreException;%0Aimport org.eclipse.egit.core.project.RepositoryFinder;%0Aimport org.eclipse.egit.core.project.RepositoryMapping;
 %0A%0Aimport
@@ -985,16 +985,36 @@
 ject();%0A
+%09%09checkNotNested();%0A
 %09%09gitDir
@@ -1652,16 +1652,16 @@
 able%22);%0A
-
 %09%09assert
@@ -1678,10 +1678,313 @@
 ();%0A%09%7D%0A%0A
+%09protected void checkNotNested() throws CoreException %7B%0A%09%09final Collection%3CRepositoryMapping%3E parentRepositories = new RepositoryFinder(%0A%09%09%09%09project.getProject()).find(null);%0A%09%09final int numOfRepositories = parentRepositories.size();%0A%09%09assertTrue(%22parent repository found%22, numOfRepositories == 0);%0A%09%7D%0A%0A
 %7D%0A

Assert there are no other git repositories in a parent directories