# [PATCH JGIT] Ensure created test repositories use canonical paths

4 messages from 2009-08-19 to 2009-08-22. Participants: Jonas Fonseca, Robin Rosenberg.
Thread: https://gitlist.dev/t/20663

## Jonas Fonseca, 2009-08-19 13:18

Subject: [PATCH JGIT] Ensure created test repositories use canonical paths
Message-ID: <1250687891-17916-1-git-send-email-fonseca@diku.dk>
URL: https://gitlist.dev/e/1250687891-17916-1-git-send-email-fonseca%40diku.dk

```
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();
-- 
1.6.4.rc3.195.g2b05f

```

## Robin Rosenberg, 2009-08-20 22:35

Subject: Re: [PATCH JGIT] Ensure created test repositories use canonical paths
Message-ID: <200908210035.10825.robin.rosenberg.lists@dewire.com>
URL: https://gitlist.dev/e/200908210035.10825.robin.rosenberg.lists%40dewire.com
In-Reply-To: <1250687891-17916-1-git-send-email-fonseca@diku.dk>

```
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
> 
> 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, 2009-08-22 03:32

Subject: Re: [PATCH JGIT] Ensure created test repositories use canonical paths
Message-ID: <2c6b72b30908212032t39a4896x3308148c44692a80@mail.gmail.com>
URL: https://gitlist.dev/e/2c6b72b30908212032t39a4896x3308148c44692a80%40mail.gmail.com
In-Reply-To: <200908210035.10825.robin.rosenberg.lists@dewire.com>

```
[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.

--
Jonas Fonseca

```

## Robin Rosenberg, 2009-08-22 10:15

Subject: Re: [PATCH JGIT] Ensure created test repositories use canonical paths
Message-ID: <200908221215.17681.robin.rosenberg.lists@dewire.com>
URL: https://gitlist.dev/e/200908221215.17681.robin.rosenberg.lists%40dewire.com
In-Reply-To: <2c6b72b30908212032t39a4896x3308148c44692a80@mail.gmail.com>

```
lördag 22 augusti 2009 05:32:59 skrev Jonas Fonseca <fonseca@diku.dk>:
> [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

```
