Merge branch 'jk/send-pack' into HEAD
authorJunio C Hamano <gitster@pobox.com>
Wed, 31 Oct 2007 04:38:04 +0000 (21:38 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 31 Oct 2007 04:38:04 +0000 (21:38 -0700)
* jk/send-pack:
t5516: test update of local refs on push
send-pack: don't update tracking refs on error

1  2 
send-pack.c
diff --combined send-pack.c
index e9b9a39f411b6cfff1c0a4bc3f7e31274c8d2782,1a7397f3a65864524ef735d094d171bca6a0d067..25053d2c2f7daa9aa392693a892db7e80c8b6469
@@@ -178,6 -178,35 +178,35 @@@ static int receive_status(int in
        return ret;
  }
  
+ static void update_tracking_ref(struct remote *remote, struct ref *ref)
+ {
+       struct refspec rs;
+       int will_delete_ref;
+       rs.src = ref->name;
+       rs.dst = NULL;
+       if (!ref->peer_ref)
+               return;
+       will_delete_ref = is_null_sha1(ref->peer_ref->new_sha1);
+       if (!will_delete_ref &&
+                       !hashcmp(ref->old_sha1, ref->peer_ref->new_sha1))
+               return;
+       if (!remote_find_tracking(remote, &rs)) {
+               fprintf(stderr, "updating local tracking ref '%s'\n", rs.dst);
+               if (is_null_sha1(ref->peer_ref->new_sha1)) {
+                       if (delete_ref(rs.dst, NULL))
+                               error("Failed to delete");
+               } else
+                       update_ref("update by push", rs.dst,
+                                       ref->new_sha1, NULL, 0, 0);
+               free(rs.dst);
+       }
+ }
  static int send_pack(int in, int out, struct remote *remote, int nr_refspec, char **refspec)
  {
        struct ref *ref;
                        fprintf(stderr, "\n  from %s\n  to   %s\n",
                                old_hex, new_hex);
                }
-               if (remote && !dry_run) {
-                       struct refspec rs;
-                       rs.src = ref->name;
-                       rs.dst = NULL;
-                       if (!remote_find_tracking(remote, &rs)) {
-                               fprintf(stderr, " Also local %s\n", rs.dst);
-                               if (will_delete_ref) {
-                                       if (delete_ref(rs.dst, NULL)) {
-                                               error("Failed to delete");
-                                       }
-                               } else
-                                       update_ref("update by push", rs.dst,
-                                               ref->new_sha1, NULL, 0, 0);
-                               free(rs.dst);
-                       }
-               }
        }
  
        packet_flush(out);
                        ret = -4;
        }
  
+       if (!dry_run && remote && ret == 0) {
+               for (ref = remote_refs; ref; ref = ref->next)
+                       update_tracking_ref(remote, ref);
+       }
        if (!new_refs && ret == 0)
                fprintf(stderr, "Everything up-to-date\n");
        return ret;
@@@ -428,7 -446,7 +446,7 @@@ int main(int argc, char **argv
  
        if (remote_name) {
                remote = remote_get(remote_name);
 -              if (!remote_has_uri(remote, dest)) {
 +              if (!remote_has_url(remote, dest)) {
                        die("Destination %s is not a uri for %s",
                            dest, remote_name);
                }