changeset 711:623cb724c3d0

hg2git: in _init_dirs, store keys without leading '/' (issue103) Previously, whenever a tree that wasn't the root ('') was stored, we'd prepend a '/' to it. Then, when we'd try retrieving the entry, we'd do so without the leading '/'. This caused data loss because existing tree entries were dropped on the floor. Fix that by only adding '/' if we're adding to a non-empty initial path. This wasn't detected in tests because most of them deal only with files in the root and not ones in subdirectories.
author Siddharth Agarwal <sid0@fb.com>
date Tue, 25 Mar 2014 11:11:04 -0700
parents 5c7943ca051f
children 51b3b3b4927e
files hggit/hg2git.py tests/test-push.t
diffstat 2 files changed, 53 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/hggit/hg2git.py
+++ b/hggit/hg2git.py
@@ -91,7 +91,11 @@
             self._dirs[path] = tree
             for entry in tree.iteritems():
                 if entry.mode == dirkind:
-                    todo.append((path + '/' + entry.path, store[entry.sha]))
+                    if path == '':
+                        newpath = entry.path
+                    else:
+                        newpath = path + '/' + entry.path
+                    todo.append((newpath, store[entry.sha]))
 
     @property
     def root_tree_sha(self):
--- a/tests/test-push.t
+++ b/tests/test-push.t
@@ -116,8 +116,56 @@
   no changes found
   [1]
 
+hg-git issue103 -- directories can lose information at hg-git export time
+
+  $ hg up master
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ mkdir dir1
+  $ echo alpha > dir1/alpha
+  $ hg add dir1/alpha
+  $ fn_hg_commit -m 'add dir1/alpha'
+  $ hg push -r master
+  pushing to $TESTTMP/gitrepo
+  searching for changes
+  adding objects
+  added 1 commits with 2 trees and 0 blobs
+  updating reference refs/heads/master
+
+  $ echo beta > dir1/beta
+  $ hg add dir1/beta
+  $ fn_hg_commit -m 'add dir1/beta'
+  $ hg push -r master
+  pushing to $TESTTMP/gitrepo
+  searching for changes
+  adding objects
+  added 1 commits with 2 trees and 0 blobs
+  updating reference refs/heads/master
+  $ hg log -r master
+  changeset:   5:fff64abfde07
+  bookmark:    master
+  tag:         default/master
+  tag:         tip
+  user:        test
+  date:        Mon Jan 01 00:00:15 2007 +0000
+  summary:     add dir1/beta
+  
+
   $ cd ..
 
+  $ hg clone gitrepo hgrepo-test
+  importing git objects into hg
+  updating to branch default
+  5 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ hg -R hgrepo-test log -r master
+  changeset:   4:fff64abfde07
+  bookmark:    master
+  tag:         default/master
+  tag:         tip
+  user:        test
+  date:        Mon Jan 01 00:00:15 2007 +0000
+  summary:     add dir1/beta
+  
+
 Push empty Hg repo to empty Git repo (issue #58)
 Since there aren't any changes, exit code 1 is expected in modern Mercurial.
 However, since it varies between supported Mercurial versions, we need to