changeset 207:b20a6c149021

fetch: Fix a bogus case where no files in the root level of trunk caused breakage in the branch detection.
author Augie Fackler <durin42@gmail.com>
date Mon, 09 Mar 2009 12:01:40 -0500
parents c2e51d6a2d7b
children de3807ceea5c
files hg_delta_editor.py tests/fixtures/file_not_in_trunk_root.sh tests/fixtures/file_not_in_trunk_root.svndump tests/test_fetch_command.py
diffstat 4 files changed, 181 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/hg_delta_editor.py
+++ b/hg_delta_editor.py
@@ -220,6 +220,9 @@ class HgChangeReceiver(delta.Editor):
                     filepaths = [p for p in filepaths if not '/'.join(p).startswith(parentdir)]
                     branchpath = self._normalize_path(parentdir)
                     branchname = self._localname(branchpath)
+                    if branchpath.startswith('trunk/'):
+                        branches[self._localname('trunk')] = 'trunk'
+                        continue
                     branches[branchname] = branchpath
 
         return branches
@@ -268,8 +271,12 @@ class HgChangeReceiver(delta.Editor):
             return path[len(test)+1:], self._localname(test), test
         if existing:
             return None, None, None
-        path = test.split('/')[-1]
-        test = '/'.join(test.split('/')[:-1])
+        if path.startswith('trunk/'):
+            path = test.split('/')[1:]
+            test = 'trunk'
+        else:
+            path = test.split('/')[-1]
+            test = '/'.join(test.split('/')[:-1])
         return path, self._localname(test), test
 
     def set_current_rev(self, rev):
new file mode 100755
--- /dev/null
+++ b/tests/fixtures/file_not_in_trunk_root.sh
@@ -0,0 +1,25 @@
+#!/bin/sh
+mkdir temp
+cd temp
+svnadmin create repo
+svn co file://`pwd`/repo wc
+cd wc
+mkdir branches trunk tags
+svn add *
+svn ci -m 'btt'
+cd trunk
+mkdir narf
+cd narf
+for a in alpha beta gamma delta ; do
+    echo $a > $a
+done
+cd ..
+svn add narf
+svn ci -m 'Add files.'
+cd ../../..
+svnadmin dump temp/repo > file_not_in_trunk_root.svndump
+echo
+echo 'Complete.'
+echo 'You probably want to clean up temp now.'
+echo 'Dump in file_not_in_trunk_root.svndump'
+exit 0
new file mode 100644
--- /dev/null
+++ b/tests/fixtures/file_not_in_trunk_root.svndump
@@ -0,0 +1,138 @@
+SVN-fs-dump-format-version: 2
+
+UUID: 8904f924-d410-4c11-97ad-f853c35ee419
+
+Revision-number: 0
+Prop-content-length: 56
+Content-length: 56
+
+K 8
+svn:date
+V 27
+2009-03-09T16:36:52.319733Z
+PROPS-END
+
+Revision-number: 1
+Prop-content-length: 102
+Content-length: 102
+
+K 7
+svn:log
+V 3
+btt
+K 10
+svn:author
+V 5
+Augie
+K 8
+svn:date
+V 27
+2009-03-09T16:36:53.075933Z
+PROPS-END
+
+Node-path: branches
+Node-kind: dir
+Node-action: add
+Prop-content-length: 10
+Content-length: 10
+
+PROPS-END
+
+
+Node-path: tags
+Node-kind: dir
+Node-action: add
+Prop-content-length: 10
+Content-length: 10
+
+PROPS-END
+
+
+Node-path: trunk
+Node-kind: dir
+Node-action: add
+Prop-content-length: 10
+Content-length: 10
+
+PROPS-END
+
+
+Revision-number: 2
+Prop-content-length: 110
+Content-length: 110
+
+K 7
+svn:log
+V 10
+Add files.
+K 10
+svn:author
+V 5
+Augie
+K 8
+svn:date
+V 27
+2009-03-09T16:36:54.163467Z
+PROPS-END
+
+Node-path: trunk/narf
+Node-kind: dir
+Node-action: add
+Prop-content-length: 10
+Content-length: 10
+
+PROPS-END
+
+
+Node-path: trunk/narf/alpha
+Node-kind: file
+Node-action: add
+Prop-content-length: 10
+Text-content-length: 6
+Text-content-md5: 9f9f90dbe3e5ee1218c86b8839db1995
+Text-content-sha1: d046cd9b7ffb7661e449683313d41f6fc33e3130
+Content-length: 16
+
+PROPS-END
+alpha
+
+
+Node-path: trunk/narf/beta
+Node-kind: file
+Node-action: add
+Prop-content-length: 10
+Text-content-length: 5
+Text-content-md5: f0cf2a92516045024a0c99147b28f05b
+Text-content-sha1: 6c007a14875d53d9bf0ef5a6fc0257c817f0fb83
+Content-length: 15
+
+PROPS-END
+beta
+
+
+Node-path: trunk/narf/delta
+Node-kind: file
+Node-action: add
+Prop-content-length: 10
+Text-content-length: 6
+Text-content-md5: d2840cc81bc032bd1141b56687d0f93c
+Text-content-sha1: 4bd6315d6d7824c4e376847ca7d116738ad2f29a
+Content-length: 16
+
+PROPS-END
+delta
+
+
+Node-path: trunk/narf/gamma
+Node-kind: file
+Node-action: add
+Prop-content-length: 10
+Text-content-length: 6
+Text-content-md5: 303febb9068384eca46b5b6516843b35
+Text-content-sha1: 37f385b028bf2f93a4b497ca9ff44eea63945b7f
+Content-length: 16
+
+PROPS-END
+gamma
+
+
--- a/tests/test_fetch_command.py
+++ b/tests/test_fetch_command.py
@@ -139,6 +139,15 @@ class TestBasicRepoLayout(test_util.Test
     def test_entry_deletion_stupid(self):
         self.test_entry_deletion(stupid=True)
 
+    def test_fetch_when_trunk_has_no_files(self, stupid=False):
+        repo = self._load_fixture_and_fetch('file_not_in_trunk_root.svndump', stupid=stupid)
+        print repo['tip'].branch()
+        print repo['tip']
+        print repo['tip'].files()
+        self.assertEqual(repo['tip'].branch(), 'default')
+
+    def test_fetch_when_trunk_has_no_files_stupid(self):
+        self.test_fetch_when_trunk_has_no_files(stupid=True)
 
 class TestStupidPull(test_util.TestBase):
     def test_stupid(self):