changeset 605:6da65b534370

merge
author Augie Fackler <raf@durin42.com>
date Wed, 28 Aug 2013 13:49:01 -0400
parents f1bac7f37a05 (diff) ca86479dd2d9 (current diff)
children bd5467169d3c
files hggit/git_handler.py
diffstat 9 files changed, 118 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/hggit/git_handler.py
+++ b/hggit/git_handler.py
@@ -4,7 +4,7 @@
 from dulwich.errors import HangupException, GitProtocolError, UpdateRefsError
 from dulwich.objects import Blob, Commit, Tag, Tree, parse_timezone, S_IFGITLINK
 from dulwich.pack import create_delta, apply_delta
-from dulwich.repo import Repo
+from dulwich.repo import Repo, check_ref_format
 from dulwich import client
 from dulwich import config as dul_config
 
@@ -1039,12 +1039,18 @@
                 tag = tag.replace(' ', '_')
                 target = self.map_git_get(hex(sha))
                 if target is not None:
-                    self.git.refs['refs/tags/' + tag] = target
-                    self.tags[tag] = hex(sha)
+                    tag_refname = 'refs/tags/' + tag
+                    if(check_ref_format(tag_refname)):
+                      self.git.refs[tag_refname] = target
+                      self.tags[tag] = hex(sha)
+                    else:
+                      self.repo.ui.warn(
+                        'Skipping export of tag %s because it '
+                        'has invalid name as a git refname.\n' % tag)
                 else:
                     self.repo.ui.warn(
                         'Skipping export of tag %s because it '
-                        'has no matching git revision.' % tag)
+                        'has no matching git revision.\n' % tag)
 
     def _filter_for_bookmarks(self, bms):
         if not self.branch_bookmark_suffix:
--- a/tests/test-git-tags.t
+++ b/tests/test-git-tags.t
@@ -42,7 +42,7 @@
   pushing to $TESTTMP/gitrepo
   searching for changes
   adding objects
-  added 1 commits with 1 trees and 1 blobs
+  added 1 commits with 1 trees and 2 blobs
   updating reference refs/heads/master
 
   $ cd ..
--- a/tests/test-hg-author.t
+++ b/tests/test-hg-author.t
@@ -25,7 +25,7 @@
   pushing to $TESTTMP/gitrepo
   searching for changes
   adding objects
-  added 1 commits with 1 trees and 1 blobs
+  added 1 commits with 1 trees and 2 blobs
   updating reference refs/heads/master
 
   $ echo gamma >> beta
@@ -34,7 +34,7 @@
   pushing to $TESTTMP/gitrepo
   searching for changes
   adding objects
-  added 1 commits with 1 trees and 1 blobs
+  added 1 commits with 1 trees and 2 blobs
   updating reference refs/heads/master
 
   $ echo gamma > gamma
@@ -44,7 +44,7 @@
   pushing to $TESTTMP/gitrepo
   searching for changes
   adding objects
-  added 1 commits with 1 trees and 1 blobs
+  added 1 commits with 1 trees and 3 blobs
   updating reference refs/heads/master
 
   $ echo delta > delta
@@ -54,7 +54,7 @@
   pushing to $TESTTMP/gitrepo
   searching for changes
   adding objects
-  added 1 commits with 1 trees and 1 blobs
+  added 1 commits with 1 trees and 4 blobs
   updating reference refs/heads/master
 
   $ echo epsilon > epsilon
@@ -64,7 +64,7 @@
   pushing to $TESTTMP/gitrepo
   searching for changes
   adding objects
-  added 1 commits with 1 trees and 1 blobs
+  added 1 commits with 1 trees and 5 blobs
   updating reference refs/heads/master
 
   $ echo zeta > zeta
@@ -74,7 +74,7 @@
   pushing to $TESTTMP/gitrepo
   searching for changes
   adding objects
-  added 1 commits with 1 trees and 1 blobs
+  added 1 commits with 1 trees and 6 blobs
   updating reference refs/heads/master
 
   $ echo eta > eta
@@ -84,7 +84,7 @@
   pushing to $TESTTMP/gitrepo
   searching for changes
   adding objects
-  added 1 commits with 1 trees and 1 blobs
+  added 1 commits with 1 trees and 7 blobs
   updating reference refs/heads/master
 
   $ echo theta > theta
@@ -94,7 +94,7 @@
   pushing to $TESTTMP/gitrepo
   searching for changes
   adding objects
-  added 1 commits with 1 trees and 1 blobs
+  added 1 commits with 1 trees and 8 blobs
   updating reference refs/heads/master
 
   $ hg log --graph | egrep -v ': *(not-master|master)'
--- a/tests/test-hg-branch.t
+++ b/tests/test-hg-branch.t
@@ -24,7 +24,7 @@
   pushing to $TESTTMP/gitrepo
   searching for changes
   adding objects
-  added 1 commits with 1 trees and 0 blobs
+  added 1 commits with 1 trees and 1 blobs
   updating reference refs/heads/master
 
   $ hg branch gamma | grep -v 'permanent and global'
@@ -34,7 +34,7 @@
   pushing to $TESTTMP/gitrepo
   searching for changes
   adding objects
-  added 1 commits with 1 trees and 0 blobs
+  added 1 commits with 1 trees and 1 blobs
   updating reference refs/heads/master
 
   $ hg log --graph | egrep -v ': *(not-master|master)'
new file mode 100644
--- /dev/null
+++ b/tests/test-hg-tags-invalid.t
@@ -0,0 +1,89 @@
+Load commonly used test logic
+  $ . "$TESTDIR/testutil"
+
+  $ git init gitrepo
+  Initialized empty Git repository in $TESTTMP/gitrepo/.git/
+  $ cd gitrepo
+  $ echo alpha > alpha
+  $ git add alpha
+  $ fn_git_commit -m "add alpha"
+  $ git checkout -b not-master
+  Switched to a new branch 'not-master'
+
+  $ cd ..
+  $ hg clone gitrepo hgrepo | grep -v '^updating'
+  importing git objects into hg
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+  $ cd hgrepo
+  $ hg co master
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ fn_hg_tag alph#a
+  $ fn_hg_tag bet*a
+  $ hg push
+  pushing to $TESTTMP/gitrepo
+  Skipping export of tag bet*a because it has invalid name as a git refname.
+  searching for changes
+  adding objects
+  added 2 commits with 2 trees and 3 blobs
+  adding reference refs/tags/alph#a
+  updating reference refs/heads/master
+
+  $ hg log --graph | egrep -v ': *(not-master|master)'
+  @  changeset:   2:e72bdd9ef5c0
+  |  tag:         default/master
+  |  tag:         tip
+  |  user:        test
+  |  date:        Mon Jan 01 00:00:12 2007 +0000
+  |  summary:     Added tag bet*a for changeset 432ce25d86bc
+  |
+  o  changeset:   1:432ce25d86bc
+  |  tag:         bet*a
+  |  user:        test
+  |  date:        Mon Jan 01 00:00:11 2007 +0000
+  |  summary:     Added tag alph#a for changeset 3442585be8a6
+  |
+  o  changeset:   0:3442585be8a6
+     tag:         alph#a
+     tag:         default/not-master
+     user:        test <test@example.org>
+     date:        Mon Jan 01 00:00:10 2007 +0000
+     summary:     add alpha
+  
+
+  $ cd ..
+  $ cd gitrepo
+git should have only the valid tag alph#a but have full commit log including the missing invalid bet*a tag commit
+  $ git tag -l
+  alph#a
+
+  $ cd ..
+  $ hg clone gitrepo hgrepo2 | grep -v '^updating'
+  importing git objects into hg
+  2 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ hg -R hgrepo2 log --graph | egrep -v ': *(not-master|master)'
+  @  changeset:   2:e72bdd9ef5c0
+  |  tag:         default/master
+  |  tag:         tip
+  |  user:        test
+  |  date:        Mon Jan 01 00:00:12 2007 +0000
+  |  summary:     Added tag bet*a for changeset 432ce25d86bc
+  |
+  o  changeset:   1:432ce25d86bc
+  |  tag:         bet*a
+  |  user:        test
+  |  date:        Mon Jan 01 00:00:11 2007 +0000
+  |  summary:     Added tag alph#a for changeset 3442585be8a6
+  |
+  o  changeset:   0:3442585be8a6
+     tag:         alph#a
+     tag:         default/not-master
+     user:        test <test@example.org>
+     date:        Mon Jan 01 00:00:10 2007 +0000
+     summary:     add alpha
+  
+
+the tag should be in .hgtags
+  $ cat hgrepo2/.hgtags
+  3442585be8a60c6cd476bbc4e45755339f2a23ef alph#a
+  432ce25d86bc4281747aa42e27b473b992e2b0b9 bet*a
--- a/tests/test-hg-tags.t
+++ b/tests/test-hg-tags.t
@@ -23,7 +23,7 @@
   pushing to $TESTTMP/gitrepo
   searching for changes
   adding objects
-  added 1 commits with 1 trees and 1 blobs
+  added 1 commits with 1 trees and 2 blobs
   adding reference refs/tags/alpha
   updating reference refs/heads/master
 
--- a/tests/test-push.t
+++ b/tests/test-push.t
@@ -30,7 +30,7 @@
   pushing to $TESTTMP/gitrepo
   searching for changes
   adding objects
-  added 1 commits with 1 trees and 1 blobs
+  added 1 commits with 1 trees and 2 blobs
   adding reference refs/heads/beta
 
   $ cd ..
@@ -104,7 +104,7 @@
   pushing to $TESTTMP/gitrepo
   searching for changes
   adding objects
-  added 1 commits with 1 trees and 1 blobs
+  added 1 commits with 1 trees and 3 blobs
   updating reference refs/heads/master
 
 this should fail, no changes to push
--- a/tests/test-subrepos.t
+++ b/tests/test-subrepos.t
@@ -39,8 +39,8 @@
 1. Ensure gitlinks are transformed to .hgsubstate on hg <- git pull
 .hgsub shall list two [git] subrepos
   $ cat .hgsub
+  xyz/subrepo2 = [git]../gitsubrepo
   subrepo1 = [git]../gitsubrepo
-  xyz/subrepo2 = [git]../gitsubrepo
 .hgsubstate shall list two idenitcal revisions
   $ cat .hgsubstate
   56f0304c5250308f14cfbafdc27bd12d40154d17 subrepo1
@@ -73,7 +73,7 @@
   pushing to $TESTTMP/gitrepo1
   searching for changes
   adding objects
-  added 1 commits with 2 trees and 1 blobs
+  added 1 commits with 2 trees and 2 blobs
   updating reference refs/heads/master
   $ cd ..
   $ cd gitrepo1
@@ -103,14 +103,15 @@
   importing git objects into hg
   (run 'hg update' to get a working copy)
   $ hg checkout -C
+  updating to active bookmark master
   cloning subrepo hgsub from $TESTTMP/hgsub
   2 files updated, 0 files merged, 0 files removed, 0 files unresolved
   $ cd ..
 pull shall bring .hgsub entry which was added to the git repo
   $ cat hgrepo/.hgsub
   hgsub = $TESTTMP/hgsub
+  xyz/subrepo2 = [git]../gitsubrepo
   subrepo1 = [git]../gitsubrepo
-  xyz/subrepo2 = [git]../gitsubrepo
 .hgsubstate shall list revision of the subrepo added through git repo
   $ cat hgrepo/.hgsubstate
   481ec30d580f333ae3a77f94c973ce37b69d5bda hgsub
--- a/tests/test-tree-decomposition.t
+++ b/tests/test-tree-decomposition.t
@@ -16,7 +16,7 @@
 
   $ rm -r d1
   $ echo c > d1
-  $ git add d1
+  $ git add --all d1
   $ fn_git_commit -m 'replace a dir with a file'