send-pack: don't update tracking refs on error
Previously, we updated the tracking refs (which match refs we are pushing) while generating the list of refs to send. However, at that point we don't know whether the refs were accepted. Instead, we now wait until we get a response code from the server. If an error was indicated, we don't update any local tracking refs. Technically some refs could have been updated on the remote, but since the local ref update is just an optimization to avoid an extra fetch, we are better off erring on the side of correctness. The user-visible message is now generated much later in the program, and has been tweaked to make more sense. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
This commit is contained in:
parent
de61e42b53
commit
334f4831e5
50
send-pack.c
50
send-pack.c
@ -178,6 +178,35 @@ static int receive_status(int in)
|
|||||||
return ret;
|
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)
|
static int send_pack(int in, int out, struct remote *remote, int nr_refspec, char **refspec)
|
||||||
{
|
{
|
||||||
struct ref *ref;
|
struct ref *ref;
|
||||||
@ -306,22 +335,6 @@ static int send_pack(int in, int out, struct remote *remote, int nr_refspec, cha
|
|||||||
fprintf(stderr, "\n from %s\n to %s\n",
|
fprintf(stderr, "\n from %s\n to %s\n",
|
||||||
old_hex, new_hex);
|
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);
|
packet_flush(out);
|
||||||
@ -334,6 +347,11 @@ static int send_pack(int in, int out, struct remote *remote, int nr_refspec, cha
|
|||||||
ret = -4;
|
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)
|
if (!new_refs && ret == 0)
|
||||||
fprintf(stderr, "Everything up-to-date\n");
|
fprintf(stderr, "Everything up-to-date\n");
|
||||||
return ret;
|
return ret;
|
||||||
|
Loading…
Reference in New Issue
Block a user