@matheusbsbs / matheus-bagliano / commits / 9ad7c5ae8a
Fork 0

git-fetch: do not fail when remote branch disappears

When the branch named with branch.$name.merge is not covered by the fetch configuration for the remote repository named with branch.$name.remote, we automatically add that branch to the set of branches to be fetched. However, if the remote repository does not have that branch (e.g. it used to exist, but got removed), this is not a reason to fail the git-fetch itself. The situation however will be noticed if git-fetch was called by git-pull, as the resulting FETCH_HEAD would not have any entry that is marked for merging. Acked-By: Daniel Barkalow <barkalow@iabervon.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Oct 26, 2007 at 23:09 UTC 9ad7c5ae8ae4625bfe32d910b0b480cfea9819e0
3 files changed +33 -18
builtin-fetch.c
+16 -8
@@ -48,15 +48,21 @@ static void add_merge_config(struct ref **head,
48 if (rm)
49 continue;
50
51 - /* Not fetched to a tracking branch? We need to fetch
51 + /*
52 + * Not fetched to a tracking branch? We need to fetch
53 * it anyway to allow this branch's "branch.$name.merge"
53 - * to be honored by git-pull.
54 + * to be honored by git-pull, but we do not have to
55 + * fail if branch.$name.merge is misconfigured to point
56 + * at a nonexisting branch. If we were indeed called by
57 + * git-pull, it will notice the misconfiguration because
58 + * there is no entry in the resulting FETCH_HEAD marked
59 + * for merging.
60 */
61 refspec.src = branch->merge[i]->src;
62 refspec.dst = NULL;
63 refspec.pattern = 0;
64 refspec.force = 0;
59 - get_fetch_map(remote_refs, &refspec, tail);
65 + get_fetch_map(remote_refs, &refspec, tail, 1);
66 for (rm = *old_tail; rm; rm = rm->next)
67 rm->merge = 1;
68 }
@@ -75,7 +81,7 @@ static struct ref *get_ref_map(struct transport *transport,
81
82 if (ref_count || tags) {
83 for (i = 0; i < ref_count; i++) {
78 - get_fetch_map(remote_refs, &refs[i], &tail);
84 + get_fetch_map(remote_refs, &refs[i], &tail, 0);
85 if (refs[i].dst && refs[i].dst[0])
86 *autotags = 1;
87 }
@@ -88,7 +94,7 @@ static struct ref *get_ref_map(struct transport *transport,
94 refspec.dst = "refs/tags/";
95 refspec.pattern = 1;
96 refspec.force = 0;
91 - get_fetch_map(remote_refs, &refspec, &tail);
97 + get_fetch_map(remote_refs, &refspec, &tail, 0);
98 }
99 } else {
100 /* Use the defaults */
@@ -97,7 +103,7 @@ static struct ref *get_ref_map(struct transport *transport,
103 int has_merge = branch_has_merge_config(branch);
104 if (remote && (remote->fetch_refspec_nr || has_merge)) {
105 for (i = 0; i < remote->fetch_refspec_nr; i++) {
100 - get_fetch_map(remote_refs, &remote->fetch[i], &tail);
106 + get_fetch_map(remote_refs, &remote->fetch[i], &tail, 0);
107 if (remote->fetch[i].dst &&
108 remote->fetch[i].dst[0])
109 *autotags = 1;
@@ -110,11 +116,13 @@ static struct ref *get_ref_map(struct transport *transport,
116 * as given in branch.<name>.remote, we add the
117 * ref given in branch.<name>.merge, too.
118 */
113 - if (has_merge && !strcmp(branch->remote_name,
114 - remote->name))
119 + if (has_merge &&
120 + !strcmp(branch->remote_name, remote->name))
121 add_merge_config(&ref_map, remote_refs, branch, &tail);
122 } else {
123 ref_map = get_remote_ref(remote_refs, "HEAD");
124 + if (!ref_map)
125 + die("Couldn't find remote ref HEAD");
126 ref_map->merge = 1;
127 }
128 }
remote.c
+13 -9
@@ -857,7 +857,7 @@ struct ref *get_remote_ref(struct ref *remote_refs, const char *name)
857 struct ref *ref = find_ref_by_name_abbrev(remote_refs, name);
858
859 if (!ref)
860 - die("Couldn't find remote ref %s\n", name);
860 + return NULL;
861
862 return copy_ref(ref);
863 }
@@ -889,20 +889,24 @@ static struct ref *get_local_ref(const char *name)
889
890 int get_fetch_map(struct ref *remote_refs,
891 const struct refspec *refspec,
892 - struct ref ***tail)
892 + struct ref ***tail,
893 + int missing_ok)
894 {
895 struct ref *ref_map, *rm;
896
897 if (refspec->pattern) {
898 ref_map = get_expanded_map(remote_refs, refspec);
899 } else {
899 - ref_map = get_remote_ref(remote_refs,
900 - refspec->src[0] ?
901 - refspec->src : "HEAD");
902 -
903 - ref_map->peer_ref = get_local_ref(refspec->dst);
904 - if (ref_map->peer_ref && refspec->force)
905 - ref_map->peer_ref->force = 1;
900 + const char *name = refspec->src[0] ? refspec->src : "HEAD";
901 +
902 + ref_map = get_remote_ref(remote_refs, name);
903 + if (!missing_ok && !ref_map)
904 + die("Couldn't find remote ref %s", name);
905 + if (ref_map) {
906 + ref_map->peer_ref = get_local_ref(refspec->dst);
907 + if (ref_map->peer_ref && refspec->force)
908 + ref_map->peer_ref->force = 1;
909 + }
910 }
911
912 for (rm = ref_map; rm; rm = rm->next) {
remote.h
+4 -1
@@ -67,9 +67,12 @@ int match_refs(struct ref *src, struct ref *dst, struct ref ***dst_tail,
67 * *tail is the pointer to the tail pointer of the list of results
68 * beforehand, and will be set to the tail pointer of the list of
69 * results afterward.
70 + *
71 + * missing_ok is usually false, but when we are adding branch.$name.merge
72 + * it is Ok if the branch is not at the remote anymore.
73 */
74 int get_fetch_map(struct ref *remote_refs, const struct refspec *refspec,
72 - struct ref ***tail);
75 + struct ref ***tail, int missing_ok);
76
77 struct ref *get_remote_ref(struct ref *remote_refs, const char *name);
78