diff options
Diffstat (limited to 'builtin-fetch.c')
-rw-r--r-- | builtin-fetch.c | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/builtin-fetch.c b/builtin-fetch.c index ee93d3a93d..f151cfa2fd 100644 --- a/builtin-fetch.c +++ b/builtin-fetch.c @@ -521,8 +521,8 @@ static void find_non_local_tags(struct transport *transport, will_fetch(head, ref->old_sha1))) { string_list_insert(ref_name, &new_refs); - rm = alloc_ref_from_str(ref_name); - rm->peer_ref = alloc_ref_from_str(ref_name); + rm = alloc_ref(ref_name); + rm->peer_ref = alloc_ref(ref_name); hashcpy(rm->old_sha1, ref_sha1); **tail = rm; @@ -534,6 +534,19 @@ static void find_non_local_tags(struct transport *transport, string_list_clear(&new_refs, 0); } +static void check_not_current_branch(struct ref *ref_map) +{ + struct branch *current_branch = branch_get(NULL); + + if (is_bare_repository() || !current_branch) + return; + + for (; ref_map; ref_map = ref_map->next) + if (ref_map->peer_ref && !strcmp(current_branch->refname, + ref_map->peer_ref->name)) + die("Refusing to fetch into current branch"); +} + static int do_fetch(struct transport *transport, struct refspec *refs, int ref_count) { @@ -558,6 +571,8 @@ static int do_fetch(struct transport *transport, } ref_map = get_ref_map(transport, refs, ref_count, tags, &autotags); + if (!update_head_ok) + check_not_current_branch(ref_map); for (rm = ref_map; rm; rm = rm->next) { if (rm->peer_ref) |