# HG changeset patch
# User David M. Carr  <david@carrclan.us>
# Date 1348799521 14400
# Node ID ebf4ea20ade5ffe67bd6c49b6914bb19e8134362
# Parent  5a688ad69449d26e1ced2ef2a10b798e4e1d7cd2
outgoing: don't delete remote refs

There was a bug introduced in 8c1f2b07c04b such that calling hg outgoing on
a Git repository would result in all refs being deleted from the remote
repository (with the possible exception of the currently checked out branch).
It wasn't noticed before because the existing test for outgoing didn't actually
verify the refs on the remote.  This changeset fixes the bug, as well as adding
test coverage to allow verifying that the fix works.

diff --git a/hggit/git_handler.py b/hggit/git_handler.py
--- a/hggit/git_handler.py
+++ b/hggit/git_handler.py
@@ -240,14 +240,10 @@
             old_refs.update(refs)
             to_push = set(self.local_heads().values() + self.tags.values())
             new_refs.update(self.get_changed_refs(refs, to_push, True))
-            # don't push anything
-            return {}
+            return refs # always return the same refs to make the send a no-op
 
         try:
-            try:
-                client.send_pack(path, changed, lambda have, want: [])
-            except UpdateRefsError:
-                pass # dulwich throws an error when send_pack doesn't upload
+            client.send_pack(path, changed, lambda have, want: [])
 
             changed_refs = [ref for ref, sha in new_refs.iteritems()
                             if sha != old_refs.get(ref)]
diff --git a/tests/test-outgoing.t b/tests/test-outgoing.t
--- a/tests/test-outgoing.t
+++ b/tests/test-outgoing.t
@@ -35,6 +35,10 @@
   $ echo alpha > alpha
   $ git add alpha
   $ commit -m "add alpha"
+  $ git branch alpha
+  $ git show-ref
+  7eeab2ea75ec1ac0ff3d500b5b6f8a3447dd7c03 refs/heads/alpha
+  7eeab2ea75ec1ac0ff3d500b5b6f8a3447dd7c03 refs/heads/master
 
   $ cd ..
   $ hg clone gitrepo hgrepo | grep -v '^updating'
@@ -42,6 +46,7 @@
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
 
   $ cd hgrepo
+  $ hg update -q master
   $ echo beta > beta
   $ hg add beta
   $ hgcommit -m 'add beta'
@@ -99,6 +104,11 @@
   % some more work on master from git
   $ cd gitrepo
 
+Check state of refs after outgoing
+  $ git show-ref
+  7eeab2ea75ec1ac0ff3d500b5b6f8a3447dd7c03 refs/heads/alpha
+  7eeab2ea75ec1ac0ff3d500b5b6f8a3447dd7c03 refs/heads/master
+
   $ git checkout master 2>&1 | sed s/\'/\"/g
   Already on "master"
   $ echo delta > delta