fetch --prune: always print header url
If "fetch --prune" is run with no new refs to fetch, but it has refs to prune. Then, the header url is not printed as it would if there were new refs to fetch. Output before this patch: $ git fetch --prune remote-with-no-new-refs x [deleted] (none) -> origin/world Output after this patch: $ git fetch --prune remote-with-no-new-refs From https://github.com/git/git x [deleted] (none) -> origin/test Signed-off-by: Tom Miller <jackerran@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Tom Miller committed
Jan 2, 2014 at 20:28 UTC
4b3b33a747c325f76b1f6eef89c231609dd4d361
2 files changed
+39
-5
builtin/fetch.c
+27
-5
@@ -44,6 +44,7 @@ static struct transport *gtransport;
44
static struct transport *gsecondary;
45
static const char *submodule_prefix = "";
46
static const char *recurse_submodules_default;
47
+static int shown_url = 0;
48
49
static int option_parse_recurse_submodules(const struct option *opt,
50
const char *arg, int unset)
@@ -535,7 +536,7 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
536
{
537
FILE *fp;
538
struct commit *commit;
538
- int url_len, i, shown_url = 0, rc = 0;
539
+ int url_len, i, rc = 0;
540
struct strbuf note = STRBUF_INIT;
541
const char *what, *kind;
542
struct ref *rm;
@@ -708,17 +709,36 @@ static int fetch_refs(struct transport *transport, struct ref *ref_map)
709
return ret;
710
}
711
711
-static int prune_refs(struct refspec *refs, int ref_count, struct ref *ref_map)
712
+static int prune_refs(struct refspec *refs, int ref_count, struct ref *ref_map,
713
+ const char *raw_url)
714
{
713
- int result = 0;
715
+ int url_len, i, result = 0;
716
struct ref *ref, *stale_refs = get_stale_heads(refs, ref_count, ref_map);
717
+ char *url;
718
const char *dangling_msg = dry_run
719
? _(" (%s will become dangling)")
720
: _(" (%s has become dangling)");
721
722
+ if (raw_url)
723
+ url = transport_anonymize_url(raw_url);
724
+ else
725
+ url = xstrdup("foreign");
726
+
727
+ url_len = strlen(url);
728
+ for (i = url_len - 1; url[i] == '/' && 0 <= i; i--)
729
+ ;
730
+
731
+ url_len = i + 1;
732
+ if (4 < i && !strncmp(".git", url + i - 3, 4))
733
+ url_len = i - 3;
734
+
735
for (ref = stale_refs; ref; ref = ref->next) {
736
if (!dry_run)
737
result |= delete_ref(ref->name, NULL, 0);
738
+ if (verbosity >= 0 && !shown_url) {
739
+ fprintf(stderr, _("From %.*s\n"), url_len, url);
740
+ shown_url = 1;
741
+ }
742
if (verbosity >= 0) {
743
fprintf(stderr, " x %-*s %-*s -> %s\n",
744
TRANSPORT_SUMMARY(_("[deleted]")),
@@ -726,6 +746,7 @@ static int prune_refs(struct refspec *refs, int ref_count, struct ref *ref_map)
746
warn_dangling_symref(stderr, dangling_msg, ref->name);
747
}
748
}
749
+ free(url);
750
free_refs(stale_refs);
751
return result;
752
}
@@ -854,11 +875,12 @@ static int do_fetch(struct transport *transport,
875
* don't care whether --tags was specified.
876
*/
877
if (ref_count) {
857
- prune_refs(refs, ref_count, ref_map);
878
+ prune_refs(refs, ref_count, ref_map, transport->url);
879
} else {
880
prune_refs(transport->remote->fetch,
881
transport->remote->fetch_refspec_nr,
861
- ref_map);
882
+ ref_map,
883
+ transport->url);
884
}
885
}
886
free_refs(ref_map);
t/t5510-fetch.sh
+12
@@ -614,4 +614,16 @@ test_expect_success 'all boundary commits are excluded' '
614
test_bundle_object_count .git/objects/pack/pack-${pack##pack }.pack 3
615
'
616
617
+test_expect_success 'fetch --prune prints the remotes url' '
618
+ git branch goodbye &&
619
+ git clone . only-prunes &&
620
+ git branch -D goodbye &&
621
+ (
622
+ cd only-prunes &&
623
+ git fetch --prune origin 2>&1 | head -n1 >../actual
624
+ ) &&
625
+ echo "From ${D}/." >expect &&
626
+ test_cmp expect actual
627
+'
628
+
629
test_done