changeset 25787:d9133e89d39d

convert: allow customizing git remote prefix Previously all git remotes were created as "remote/foo". This patch adds a configuration option for deciding what the prefix should be. This is useful if you want the bookmarks to be "origin/foo" like they are in git, or if you're integrating with the remotenames extension and don't want the local remote/foo bookmarks to overlap with the remote foo bookmarks.
author Durham Goode <durham@fb.com>
date Mon, 13 Jul 2015 21:37:46 -0700
parents 35fa7c77c754
children a36fd0993522
files hgext/convert/__init__.py hgext/convert/git.py tests/test-convert-git.t tests/test-convert.t
diffstat 4 files changed, 35 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/convert/__init__.py	Sun Jul 12 17:59:25 2015 +0900
+++ b/hgext/convert/__init__.py	Mon Jul 13 21:37:46 2015 -0700
@@ -309,6 +309,10 @@
         is very expensive for large projects, and is only effective when
         ``convert.git.similarity`` is greater than 0. The default is False.
 
+    :convert.git.remoteprefix: remote refs are converted as bookmarks with
+        ``convert.git.remoteprefix`` as a prefix followed by a /. The default
+        is 'remote'.
+
     Perforce Source
     ###############
 
--- a/hgext/convert/git.py	Sun Jul 12 17:59:25 2015 +0900
+++ b/hgext/convert/git.py	Mon Jul 13 21:37:46 2015 -0700
@@ -376,8 +376,9 @@
         prefixlen = len(prefix)
 
         # factor two commands
-        gitcmd = { 'remote/': 'git ls-remote --heads origin',
-                          '': 'git show-ref'}
+        remoteprefix = self.ui.config('convert', 'git.remoteprefix', 'remote')
+        gitcmd = { remoteprefix + '/': 'git ls-remote --heads origin',
+                                   '': 'git show-ref'}
 
         # Origin heads
         for reftype in gitcmd:
--- a/tests/test-convert-git.t	Sun Jul 12 17:59:25 2015 +0900
+++ b/tests/test-convert-git.t	Mon Jul 13 21:37:46 2015 -0700
@@ -642,6 +642,30 @@
   $ hg -R git-repo6-hg tip -T "{file_dels}\n"
   .hgsub .hgsubstate
 
+convert using a different remote prefix
+  $ git init git-repo7
+  Initialized empty Git repository in $TESTTMP/git-repo7/.git/
+  $ cd git-repo7
+  $ touch a && git add a && git commit -am "commit a"
+  [master (root-commit) 8ae5f69] commit a
+   Author: nottest <test@example.org>
+   1 file changed, 0 insertions(+), 0 deletions(-)
+   create mode 100644 a
+  $ cd ..
+  $ git clone git-repo7 git-repo7-client
+  Cloning into 'git-repo7-client'...
+  done.
+  $ hg convert --config convert.git.remoteprefix=origin git-repo7-client hg-repo7
+  initializing destination hg-repo7 repository
+  scanning source...
+  sorting...
+  converting...
+  0 commit a
+  updating bookmarks
+  $ hg -R hg-repo7 bookmarks
+     master                    0:03bf38caa4c6
+     origin/master             0:03bf38caa4c6
+
 damaged git repository tests:
 In case the hard-coded hashes change, the following commands can be used to
 list the hashes and their corresponding types in the repository:
--- a/tests/test-convert.t	Sun Jul 12 17:59:25 2015 +0900
+++ b/tests/test-convert.t	Mon Jul 13 21:37:46 2015 -0700
@@ -259,6 +259,10 @@
                     for large projects, and is only effective when
                     "convert.git.similarity" is greater than 0. The default is
                     False.
+      convert.git.remoteprefix
+                    remote refs are converted as bookmarks with
+                    "convert.git.remoteprefix" as a prefix followed by a /. The
+                    default is 'remote'.
   
       Perforce Source
       ###############