# HG changeset patch # User Patrick Mezard # Date 1188139766 -7200 # Node ID 7d3dcdd92a1a1870ac1d25d9674ef0569451950d # Parent a1efa71f3ece0b36da598ecf4180a3eae23babf0# Parent ceb6f242fb818460dd9d8e74c20d49dfb4b924bd Merge with crew-stable diff --git a/hgext/convert/git.py b/hgext/convert/git.py --- a/hgext/convert/git.py +++ b/hgext/convert/git.py @@ -5,8 +5,23 @@ import os from common import NoRepo, commit, converter_source class convert_git(converter_source): - def gitcmd(self, s): - return os.popen('GIT_DIR=%s %s' % (self.path, s)) + # Windows does not support GIT_DIR= construct while other systems + # cannot remove environment variable. Just assume none have + # both issues. + if hasattr(os, 'unsetenv'): + def gitcmd(self, s): + prevgitdir = os.environ.get('GIT_DIR') + os.environ['GIT_DIR'] = self.path + try: + return os.popen(s) + finally: + if prevgitdir is None: + del os.environ['GIT_DIR'] + else: + os.environ['GIT_DIR'] = prevgitdir + else: + def gitcmd(self, s): + return os.popen('GIT_DIR=%s %s' % (self.path, s)) def __init__(self, ui, path, rev=None): super(convert_git, self).__init__(ui, path, rev=rev) diff --git a/tests/hghave b/tests/hghave --- a/tests/hghave +++ b/tests/hghave @@ -51,9 +51,16 @@ def has_lsprof(): except ImportError: return False +def has_git(): + fh = os.popen('git --version 2>&1') + s = fh.read() + ret = fh.close() + return ret is None and s.startswith('git version') + checks = { "eol-in-paths": (has_eol_in_paths, "end-of-lines in paths"), "execbit": (has_executablebit, "executable bit"), + "git": (has_git, "git command line client"), "fifo": (has_fifo, "named pipes"), "hotshot": (has_hotshot, "python hotshot module"), "lsprof": (has_lsprof, "python lsprof module"), diff --git a/tests/test-convert-git b/tests/test-convert-git new file mode 100755 --- /dev/null +++ b/tests/test-convert-git @@ -0,0 +1,19 @@ +#!/bin/sh + +"$TESTDIR/hghave" git || exit 80 + +echo "[extensions]" >> $HGRCPATH +echo "convert=" >> $HGRCPATH + +mkdir git-repo +cd git-repo +git init +echo a > a +git add a +git commit -m t1 > /dev/null || echo "git commit error" +echo b >> a +git commit -a -m t2 > /dev/null || echo "git commit error" +cd .. + +hg convert git-repo + diff --git a/tests/test-convert-git.out b/tests/test-convert-git.out new file mode 100644 --- /dev/null +++ b/tests/test-convert-git.out @@ -0,0 +1,8 @@ +Initialized empty Git repository in .git/ +assuming destination git-repo-hg +initializing destination git-repo-hg repository +scanning source... +sorting... +converting... +1 t1 +0 t2