# [PATCH] remote-hg: fix hg sharedpath when git clone is moved

4 messages from 2013-11-23 to 2013-11-23. Participants: Antoine Pelisse, Felipe Contreras.
Thread: https://gitlist.dev/t/35394

## Antoine Pelisse, 2013-11-23 12:38

Subject: [PATCH] remote-hg: fix hg sharedpath when git clone is moved
Message-ID: <1385210302-25518-1-git-send-email-apelisse@gmail.com>
URL: https://gitlist.dev/e/1385210302-25518-1-git-send-email-apelisse%40gmail.com

```
remote-hg is using a mercurial shared clone to store all remotes objects
in one place. Unfortunately, the sharedpath is stored as an absolute
path by mercurial, creating a dependency on the location of the git
repository. Whenever the git repository is moved, the sharedpath must
be updated to reflect the new absolute path.

Check mercurial sharedpath file when getting the local hg repository,
and update it manually with the new path if necessary.

Signed-off-by: Antoine Pelisse <apelisse@gmail.com>
---
 contrib/remote-helpers/git-remote-hg |  4 ++++
 contrib/remote-helpers/test-hg.sh    | 11 +++++++++++
 2 files changed, 15 insertions(+)

diff --git a/contrib/remote-helpers/git-remote-hg b/contrib/remote-helpers/git-remote-hg
index c6026b9..576f094 100755
--- a/contrib/remote-helpers/git-remote-hg
+++ b/contrib/remote-helpers/git-remote-hg
@@ -416,6 +416,10 @@ def get_repo(url, alias):
         local_path = os.path.join(dirname, 'clone')
         if not os.path.exists(local_path):
             hg.share(myui, shared_path, local_path, update=False)
+        else:
+            sharedpath_file = os.path.join(local_path, '.hg', 'sharedpath')
+            if hg_path != open(sharedpath_file, 'r').read():
+                open(sharedpath_file, 'w').write(hg_path)
 
         repo = hg.repository(myui, local_path)
         try:
diff --git a/contrib/remote-helpers/test-hg.sh b/contrib/remote-helpers/test-hg.sh
index 72f745d..2477540 100755
--- a/contrib/remote-helpers/test-hg.sh
+++ b/contrib/remote-helpers/test-hg.sh
@@ -335,6 +335,17 @@ test_expect_success 'remote cloning' '
 	check gitrepo HEAD zero
 '
 
+test_expect_success 'moving remote clone' '
+	test_when_finished "rm -rf gitrepo*" &&
+
+	(
+	git clone "hg::hgrepo" gitrepo &&
+	mv gitrepo gitrepo2 &&
+	cd gitrepo2 &&
+	git fetch
+	)
+'
+
 test_expect_success 'remote update bookmark' '
 	test_when_finished "rm -rf gitrepo*" &&
 
-- 
1.8.5.rc1.30.g02973b8.dirty

```

## Antoine Pelisse, 2013-11-23 12:46

Subject: Re: [PATCH] remote-hg: fix hg sharedpath when git clone is moved
Message-ID: <CALWbr2zkiBS3zvcu8skrtn5tK8XMyQy8Nv1r1h+zowkgpWKYKw@mail.gmail.com>
URL: https://gitlist.dev/e/CALWbr2zkiBS3zvcu8skrtn5tK8XMyQy8Nv1r1h%2BzowkgpWKYKw%40mail.gmail.com
In-Reply-To: <1385210302-25518-1-git-send-email-apelisse@gmail.com>

```
On Sat, Nov 23, 2013 at 1:38 PM, Antoine Pelisse <apelisse@gmail.com> wrote:
> remote-hg is using a mercurial shared clone to store all remotes objects
> in one place. Unfortunately, the sharedpath is stored as an absolute
> path by mercurial, creating a dependency on the location of the git
> repository. Whenever the git repository is moved, the sharedpath must
> be updated to reflect the new absolute path.
>
> Check mercurial sharedpath file when getting the local hg repository,
> and update it manually with the new path if necessary.
>
> Signed-off-by: Antoine Pelisse <apelisse@gmail.com>
> ---

By the way, this is the only link [1] I found about both relative path
and updating the file. So it looks like there is no other way to
update the path but to write the file manually.

[1]: http://bz.selenic.com/show_bug.cgi?id=2006

```

## Felipe Contreras, 2013-11-23 16:32

Subject: Re: [PATCH] remote-hg: fix hg sharedpath when git clone is moved
Message-ID: <CAMP44s2=b+7cFbRK-NFPU-myT8JtaSsrKut4AbvjOAQe0OCxDg@mail.gmail.com>
URL: https://gitlist.dev/e/CAMP44s2%3Db%2B7cFbRK-NFPU-myT8JtaSsrKut4AbvjOAQe0OCxDg%40mail.gmail.com
In-Reply-To: <1385210302-25518-1-git-send-email-apelisse@gmail.com>

```
On Sat, Nov 23, 2013 at 6:38 AM, Antoine Pelisse <apelisse@gmail.com> wrote:
> remote-hg is using a mercurial shared clone to store all remotes objects
> in one place. Unfortunately, the sharedpath is stored as an absolute
> path by mercurial, creating a dependency on the location of the git
> repository. Whenever the git repository is moved, the sharedpath must
> be updated to reflect the new absolute path.
>
> Check mercurial sharedpath file when getting the local hg repository,
> and update it manually with the new path if necessary.
>
> Signed-off-by: Antoine Pelisse <apelisse@gmail.com>

https://github.com/felipec/git/commit/270e7ff91a4a34e8bc27edb6bd7d7473b886f568

-- 
Felipe Contreras

```

## Antoine Pelisse, 2013-11-23 16:35

Subject: Re: [PATCH] remote-hg: fix hg sharedpath when git clone is moved
Message-ID: <CALWbr2wE=6yR70tdBqf6dcdSv6mXE9vaPxg32OEGtL89+Kc_fA@mail.gmail.com>
URL: https://gitlist.dev/e/CALWbr2wE%3D6yR70tdBqf6dcdSv6mXE9vaPxg32OEGtL89%2BKc_fA%40mail.gmail.com
In-Reply-To: <CAMP44s2=b+7cFbRK-NFPU-myT8JtaSsrKut4AbvjOAQe0OCxDg@mail.gmail.com>

```
On Sat, Nov 23, 2013 at 5:32 PM, Felipe Contreras
<felipe.contreras@gmail.com> wrote:
> On Sat, Nov 23, 2013 at 6:38 AM, Antoine Pelisse <apelisse@gmail.com> wrote:
>> remote-hg is using a mercurial shared clone to store all remotes objects
>> in one place. Unfortunately, the sharedpath is stored as an absolute
>> path by mercurial, creating a dependency on the location of the git
>> repository. Whenever the git repository is moved, the sharedpath must
>> be updated to reflect the new absolute path.
>>
>> Check mercurial sharedpath file when getting the local hg repository,
>> and update it manually with the new path if necessary.
>>
>> Signed-off-by: Antoine Pelisse <apelisse@gmail.com>
>
> https://github.com/felipec/git/commit/270e7ff91a4a34e8bc27edb6bd7d7473b886f568

Or that, indeed :-)

```
