1 |
# HG changeset patch |
2 |
# User Durham Goode <durham@fb.com> |
3 |
# Date 1438201263 25200 |
4 |
# Wed Jul 29 13:21:03 2015 -0700 |
5 |
# Node ID 80149d0b6842713b8fdebf34404fc3520306c7a2 |
6 |
# Parent fbaa2de13cf62c454d8a939c7e691857d9b814aa |
7 |
convert: fix git convert using servers branches |
8 |
|
9 |
The conversion from git to hg was reading the remote branch list directly from |
10 |
the origin server. If the origin's branch had moved forward since the last git |
11 |
fetch, it would return a git hash which didn't exist locally, and therefore the |
12 |
branch was not converted. |
13 |
|
14 |
This changes it to rely on the local repo's refs/remotes list of branches |
15 |
instead, so it's completely cut off from the server. |
16 |
|
17 |
--- |
18 |
hgext/convert/git.py | 39 +++++++++++++++++++++------------------ |
19 |
tests/test-convert-git.t | 22 ++++++++++++++++++++++ |
20 |
2 files changed, 43 insertions(+), 18 deletions(-) |
21 |
|
22 |
--- a/hgext/convert/git.py |
23 |
+++ b/hgext/convert/git.py |
24 |
@@ -313,28 +313,31 @@ class convert_git(converter_source): |
25 |
def getbookmarks(self): |
26 |
bookmarks = {} |
27 |
|
28 |
- # Interesting references in git are prefixed |
29 |
- prefix = 'refs/heads/' |
30 |
- prefixlen = len(prefix) |
31 |
- |
32 |
- # factor two commands |
33 |
+ # Handle local and remote branches |
34 |
remoteprefix = self.ui.config('convert', 'git.remoteprefix', 'remote') |
35 |
- gitcmd = { remoteprefix + '/': 'git ls-remote --heads origin', |
36 |
- '': 'git show-ref'} |
37 |
+ reftypes = [ |
38 |
+ # (git prefix, hg prefix) |
39 |
+ ('refs/remotes/origin/', remoteprefix + '/'), |
40 |
+ ('refs/heads/', '') |
41 |
+ ] |
42 |
+ |
43 |
+ exclude = set([ |
44 |
+ 'refs/remotes/origin/HEAD', |
45 |
+ ]) |
46 |
|
47 |
- # Origin heads |
48 |
- for reftype in gitcmd: |
49 |
- try: |
50 |
- fh = self.gitopen(gitcmd[reftype], err=subprocess.PIPE) |
51 |
- for line in fh: |
52 |
- line = line.strip() |
53 |
- rev, name = line.split(None, 1) |
54 |
- if not name.startswith(prefix): |
55 |
+ try: |
56 |
+ fh = self.gitopen('git show-ref', err=subprocess.PIPE) |
57 |
+ for line in fh: |
58 |
+ line = line.strip() |
59 |
+ rev, name = line.split(None, 1) |
60 |
+ # Process each type of branch |
61 |
+ for gitprefix, hgprefix in reftypes: |
62 |
+ if not name.startswith(gitprefix) or name in exclude: |
63 |
continue |
64 |
- name = '%s%s' % (reftype, name[prefixlen:]) |
65 |
+ name = '%s%s' % (hgprefix, name[len(gitprefix):]) |
66 |
bookmarks[name] = rev |
67 |
- except Exception: |
68 |
- pass |
69 |
+ except Exception: |
70 |
+ pass |
71 |
|
72 |
return bookmarks |
73 |
|
74 |
--- a/tests/test-convert-git.t |
75 |
+++ b/tests/test-convert-git.t |
76 |
@@ -404,6 +404,28 @@ convert using a different remote prefix |
77 |
master 0:03bf38caa4c6 |
78 |
origin/master 0:03bf38caa4c6 |
79 |
|
80 |
+Run convert when the remote branches have changed |
81 |
+(there was an old bug where the local convert read branches from the server) |
82 |
+ |
83 |
+ $ cd git-repo7 |
84 |
+ $ echo a >> a |
85 |
+ $ git commit -am "move master forward" |
86 |
+ [master 0c81947] move master forward |
87 |
+ Author: nottest <test@example.org> |
88 |
+ 1 file changed, 1 insertion(+) |
89 |
+ $ cd .. |
90 |
+ $ rm -rf hg-repo7 |
91 |
+ $ hg convert --config convert.git.remoteprefix=origin git-repo7-client hg-repo7 |
92 |
+ initializing destination hg-repo7 repository |
93 |
+ scanning source... |
94 |
+ sorting... |
95 |
+ converting... |
96 |
+ 0 commit a |
97 |
+ updating bookmarks |
98 |
+ $ hg -R hg-repo7 bookmarks |
99 |
+ master 0:03bf38caa4c6 |
100 |
+ origin/master 0:03bf38caa4c6 |
101 |
+ |
102 |
damaged git repository tests: |
103 |
In case the hard-coded hashes change, the following commands can be used to |
104 |
list the hashes and their corresponding types in the repository: |
105 |
|