Skip to content

Commit

Permalink
Create all test data in trash folder
Browse files Browse the repository at this point in the history
This ensures that all test data is separated from project sources and
cleaned up after the test. Previously the cloned bare test repository
was created in org.eclipse.jgit.test/ and not deleted after the test
run.

Change-Id: I55110442e365fc8fe610f1c372f72a71ee6e1412
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
  • Loading branch information
msohn committed Apr 9, 2011
1 parent 5dbef3f commit ea0f2f9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -293,17 +293,31 @@ protected FileRepository createWorkRepository() throws IOException {
* the repository could not be created in the temporary area
*/
private FileRepository createRepository(boolean bare) throws IOException {
String uniqueId = System.currentTimeMillis() + "_" + (testCount++);
String gitdirName = "test" + uniqueId + (bare ? "" : "/") + Constants.DOT_GIT;
File gitdir = new File(trash, gitdirName).getCanonicalFile();
File gitdir = createUniqueTestGitDir(bare);
FileRepository db = new FileRepository(gitdir);

assertFalse(gitdir.exists());
db.create();
toClose.add(db);
return db;
}

/**
* Creates a new unique directory for a test repository
*
* @param bare
* true for a bare repository; false for a repository with a
* working directory
* @return a unique directory for a test repository
* @throws IOException
*/
protected File createUniqueTestGitDir(boolean bare) throws IOException {
String uniqueId = System.currentTimeMillis() + "_" + (testCount++);
String gitdirName = "test" + uniqueId + (bare ? "" : "/")
+ Constants.DOT_GIT;
File gitdir = new File(trash, gitdirName).getCanonicalFile();
return gitdir;
}

/**
* Run a hook script in the repository, returning the exit status.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ public void setUp() throws Exception {
git.commit().setMessage("Initial commit").call();

bareRepo = Git.cloneRepository().setBare(true)
.setURI(db.getDirectory().toURI().toString()).call()
.setURI(db.getDirectory().toURI().toString())
.setDirectory(createUniqueTestGitDir(true)).call()
.getRepository();
}

Expand Down

0 comments on commit ea0f2f9

Please sign in to comment.