Skip to content

Commit 664059f

Browse files
felipecgitster
authored andcommitted
transport-helper: update remote helper namespace
When pushing, the remote namespace is updated correctly (e.g. refs/origin/master), but not the remote helper's (e.g. refs/testgit/origin/master), which currently is only updated while fetching. Since the remote namespace is used to tell fast-export which commits to avoid (because they were already imported/exported), it makes sense to have them in sync so they don't get generated twice. If the remote helper was implemented properly, they would be ignored, if not, they probably would end up repeated. Signed-off-by: Felipe Contreras <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9c51558 commit 664059f

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

t/t5801-remote-helpers.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,18 @@ test_expect_success 'push ref with existing object' '
153153
compare_refs local dup server dup
154154
'
155155

156+
test_expect_success 'push update refs' '
157+
(cd local &&
158+
git checkout -b update master &&
159+
echo update >>file &&
160+
git commit -a -m update &&
161+
git push origin update
162+
git rev-parse --verify remotes/origin/update >expect &&
163+
git rev-parse --verify testgit/origin/heads/update >actual &&
164+
test_cmp expect actual
165+
)
166+
'
167+
156168
test_expect_success 'proper failure checks for fetching' '
157169
(GIT_REMOTE_TESTGIT_FAILURE=1 &&
158170
export GIT_REMOTE_TESTGIT_FAILURE &&

transport-helper.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "thread-utils.h"
1212
#include "sigchain.h"
1313
#include "argv-array.h"
14+
#include "refs.h"
1415

1516
static int debug;
1617

@@ -620,7 +621,7 @@ static int fetch(struct transport *transport,
620621
return -1;
621622
}
622623

623-
static void push_update_ref_status(struct strbuf *buf,
624+
static int push_update_ref_status(struct strbuf *buf,
624625
struct ref **ref,
625626
struct ref *remote_refs)
626627
{
@@ -686,7 +687,7 @@ static void push_update_ref_status(struct strbuf *buf,
686687
*ref = find_ref_by_name(remote_refs, refname);
687688
if (!*ref) {
688689
warning("helper reported unexpected status of %s", refname);
689-
return;
690+
return 1;
690691
}
691692

692693
if ((*ref)->status != REF_STATUS_NONE) {
@@ -695,11 +696,12 @@ static void push_update_ref_status(struct strbuf *buf,
695696
* status reported by the remote helper if the latter is 'no match'.
696697
*/
697698
if (status == REF_STATUS_NONE)
698-
return;
699+
return 1;
699700
}
700701

701702
(*ref)->status = status;
702703
(*ref)->remote_status = msg;
704+
return 0;
703705
}
704706

705707
static void push_update_refs_status(struct helper_data *data,
@@ -708,11 +710,24 @@ static void push_update_refs_status(struct helper_data *data,
708710
struct strbuf buf = STRBUF_INIT;
709711
struct ref *ref = remote_refs;
710712
for (;;) {
713+
char *private;
714+
711715
recvline(data, &buf);
712716
if (!buf.len)
713717
break;
714718

715-
push_update_ref_status(&buf, &ref, remote_refs);
719+
if (push_update_ref_status(&buf, &ref, remote_refs))
720+
continue;
721+
722+
if (!data->refspecs)
723+
continue;
724+
725+
/* propagate back the update to the remote namespace */
726+
private = apply_refspecs(data->refspecs, data->refspec_nr, ref->name);
727+
if (!private)
728+
continue;
729+
update_ref("update by helper", private, ref->new_sha1, NULL, 0, 0);
730+
free(private);
716731
}
717732
strbuf_release(&buf);
718733
}

0 commit comments

Comments
 (0)