threads / patch / 20663

patchEnsure created test repositories use canonical paths

Subject: [PATCH JGIT] Ensure created test repositories use canonical paths

## tl;dr

4 messages between Aug 19, 2009 and Aug 22, 2009. Diffs are folded; open one to read it.

replies: 3people: 2as markdown or json

Jonas Fonseca· Aug 19, 2009, 13:18 UTC · lore
Fixes breakage in the RepositoryCacheTest when running tests using:
	mvn -f ./jgit-maven/jgit/pom.xml test
which in turn will lead to test repositories using paths, such as:
	/path/to/jgit/./jgit-maven/jgit/trash/trash1250647279819.186/.git
Signed-off-by: Jonas Fonseca <fonseca@diku.dk>
---
 .../org/spearce/jgit/lib/RepositoryTestCase.java   |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
Show changes to org.spearce.jgit.test/tst/org/spearce/jgit/lib/RepositoryTestCase.java +2 −2
diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RepositoryTestCase.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RepositoryTestCase.java
index b1adde9..d1aef78 100644
--- a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RepositoryTestCase.java
+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RepositoryTestCase.java
@@ -217,7 +217,7 @@ public void setUp() throws Exception {
 		final String name = getClass().getName() + "." + getName();
 		recursiveDelete(trashParent, true, name, false); // Cleanup old failed stuff
 		trash = new File(trashParent,"trash"+System.currentTimeMillis()+"."+(testcount++));
-		trash_git = new File(trash, ".git");
+		trash_git = new File(trash, ".git").getCanonicalFile();
 		if (shutdownhook == null) {
 			shutdownhook = new Thread() {
 				@Override
@@ -307,7 +307,7 @@ protected Repository createNewEmptyRepo() throws IOException {
 	protected Repository createNewEmptyRepo(boolean bare) throws IOException {
 		final File newTestRepo = new File(trashParent, "new"
 				+ System.currentTimeMillis() + "." + (testcount++)
-				+ (bare ? "" : "/") + ".git");
+				+ (bare ? "" : "/") + ".git").getCanonicalFile();
 		assertFalse(newTestRepo.exists());
 		final Repository newRepo = new Repository(newTestRepo);
 		newRepo.create();
-- 
1.6.4.rc3.195.g2b05f
Robin Rosenberg· Aug 20, 2009, 22:35 UTC · re: Jonas Fonseca · lore

Re: [PATCH JGIT] Ensure created test repositories use canonical paths

onsdag 19 augusti 2009 15:18:11 skrev Jonas Fonseca <fonseca@diku.dk>:
Show 35 quoted lines
> Fixes breakage in the RepositoryCacheTest when running tests using:
> 
> 	mvn -f ./jgit-maven/jgit/pom.xml test
> 
> which in turn will lead to test repositories using paths, such as:
> 
> 	/path/to/jgit/./jgit-maven/jgit/trash/trash1250647279819.186/.git
> 
> Signed-off-by: Jonas Fonseca <fonseca@diku.dk>
> ---
>  .../org/spearce/jgit/lib/RepositoryTestCase.java   |    4 ++--
>  1 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RepositoryTestCase.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RepositoryTestCase.java
> index b1adde9..d1aef78 100644
> --- a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RepositoryTestCase.java
> +++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RepositoryTestCase.java
> @@ -217,7 +217,7 @@ public void setUp() throws Exception {
>  		final String name = getClass().getName() + "." + getName();
>  		recursiveDelete(trashParent, true, name, false); // Cleanup old failed stuff
>  		trash = new File(trashParent,"trash"+System.currentTimeMillis()+"."+(testcount++));
> -		trash_git = new File(trash, ".git");
> +		trash_git = new File(trash, ".git").getCanonicalFile();
>  		if (shutdownhook == null) {
>  			shutdownhook = new Thread() {
>  				@Override
> @@ -307,7 +307,7 @@ protected Repository createNewEmptyRepo() throws IOException {
>  	protected Repository createNewEmptyRepo(boolean bare) throws IOException {
>  		final File newTestRepo = new File(trashParent, "new"
>  				+ System.currentTimeMillis() + "." + (testcount++)
> -				+ (bare ? "" : "/") + ".git");
> +				+ (bare ? "" : "/") + ".git").getCanonicalFile();
>  		assertFalse(newTestRepo.exists());
>  		final Repository newRepo = new Repository(newTestRepo);
>  		newRepo.create();

We use getCanonicalFile here and Repository.gitDir is initialized with getAbsoluteDir. Does this work on all platforms? Seems linux normalized things when you do things like, but I'm not sure that happens everywhere.

ln -s JGIT x;cd x;pwd;jev 'System.out.println(System.getProperty("user.dir"));' /home/me/SW/x /home/me/SW/JGIT

-- robin
Jonas Fonseca· Aug 22, 2009, 03:32 UTC · re: Robin Rosenberg · lore

Re: [PATCH JGIT] Ensure created test repositories use canonical paths

[With correct CC list. Sorry for the resend Robin]

On Thu, Aug 20, 2009 at 18:35, Robin Rosenberg<robin.rosenberg.lists@dewire.com> wrote:

Show 17 quoted lines
> onsdag 19 augusti 2009 15:18:11 skrev Jonas Fonseca <fonseca@diku.dk>:
>> Fixes breakage in the RepositoryCacheTest when running tests using:
>>
>>       mvn -f ./jgit-maven/jgit/pom.xml test
>> [...]
>> @@ -217,7 +217,7 @@ public void setUp() throws Exception {
>>               trash = new File(trashParent,"trash"+System.currentTimeMillis()+"."+(testcount++));
>> -             trash_git = new File(trash, ".git");
>> +             trash_git = new File(trash, ".git").getCanonicalFile();
>> @@ -307,7 +307,7 @@ protected Repository createNewEmptyRepo() throws IOException {
>>       protected Repository createNewEmptyRepo(boolean bare) throws IOException {
>>               final File newTestRepo = new File(trashParent, "new"
>>                               + System.currentTimeMillis() + "." + (testcount++)
>> -                             + (bare ? "" : "/") + ".git");
>> +                             + (bare ? "" : "/") + ".git").getCanonicalFile();
>
> We use getCanonicalFile here and Repository.gitDir  is initialized with getAbsoluteDir.

BTW, a simpler fix would be to initialize trashParent to a canonical path, which might be less intrusive.

> Does this work on all platforms?
I have only tested on Linux.
> Seems linux normalized things when you do things like, but I'm not sure that happens everywhere.

If you think it is a problem, let's drop the patch. It just seemed like a simple way to increase robustness.

-- Jonas Fonseca

Robin Rosenberg· Aug 22, 2009, 10:15 UTC · re: Jonas Fonseca · lore

Re: [PATCH JGIT] Ensure created test repositories use canonical paths

lördag 22 augusti 2009 05:32:59 skrev Jonas Fonseca <fonseca@diku.dk>:
Show 33 quoted lines
> [With correct CC list. Sorry for the resend Robin]
> 
> On Thu, Aug 20, 2009 at 18:35, Robin
> Rosenberg<robin.rosenberg.lists@dewire.com> wrote:
> > onsdag 19 augusti 2009 15:18:11 skrev Jonas Fonseca <fonseca@diku.dk>:
> >> Fixes breakage in the RepositoryCacheTest when running tests using:
> >>
> >>       mvn -f ./jgit-maven/jgit/pom.xml test
> >> [...]
> >> @@ -217,7 +217,7 @@ public void setUp() throws Exception {
> >>               trash = new File(trashParent,"trash"+System.currentTimeMillis()+"."+(testcount++));
> >> -             trash_git = new File(trash, ".git");
> >> +             trash_git = new File(trash, ".git").getCanonicalFile();
> >> @@ -307,7 +307,7 @@ protected Repository createNewEmptyRepo() throws IOException {
> >>       protected Repository createNewEmptyRepo(boolean bare) throws IOException {
> >>               final File newTestRepo = new File(trashParent, "new"
> >>                               + System.currentTimeMillis() + "." + (testcount++)
> >> -                             + (bare ? "" : "/") + ".git");
> >> +                             + (bare ? "" : "/") + ".git").getCanonicalFile();
> >
> > We use getCanonicalFile here and Repository.gitDir  is initialized with getAbsoluteDir.
> 
> BTW, a simpler fix would be to initialize trashParent to a canonical
> path, which might be less intrusive.
> 
> > Does this work on all platforms?
> 
> I have only tested on Linux.
> 
> > Seems linux normalized things when you do things like, but I'm not sure that happens everywhere.
> 
> If you think it is a problem, let's drop the patch. It just seemed
> like a simple way to increase robustness.
Just a hunch, can't prove it so I'll accept the patch.
-- robin

← back to recent threads