When cloning a repo with --mirror, and adding more remotes later,
get_stale_heads for origin would mark all refs from other repos as
stale. There's no "good" way to solve, this so the best thing we can do
is refusing to prune if we detect this and warning the user.

Signed-off-by: Dennis Kaarsemaker <den...@kaarsemaker.net>
---
 remote.c          | 23 +++++++++++++++++++++++
 t/t5505-remote.sh |  2 +-
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/remote.c b/remote.c
index e71f66d..39a9405 100644
--- a/remote.c
+++ b/remote.c
@@ -1912,11 +1912,34 @@ static int get_stale_heads_cb(const char *refname,
        return 0;
 }
 
+static int check_overlapping_remotes(struct remote *first, void *priv) {
+       struct remote *second = priv;
+       int i, j;
+       if(!second)
+               return for_each_remote(check_overlapping_remotes, first);
+       if(first == second)
+               return 0;
+       for (i = 0; i < first->fetch_refspec_nr; i++) {
+               for (j = 0; j < second->fetch_refspec_nr; j++) {
+                       if(strcmp(first->fetch[i].dst, second->fetch[j].dst) &&
+                          (!fnmatch(first->fetch[i].dst, second->fetch[j].dst, 
0) ||
+                           !fnmatch(second->fetch[j].dst, first->fetch[i].dst, 
0))) {
+                               warning(_("Overlapping refspecs detected: '%s' 
and '%s', not pruning."),
+                                       first->fetch[i].dst, 
second->fetch[j].dst);
+                               return 1;
+                       }
+               }
+       }
+       return 0;
+}
+
 struct ref *get_stale_heads(struct refspec *refs, int ref_count, struct ref 
*fetch_map)
 {
        struct ref *ref, *stale_refs = NULL;
        struct string_list ref_names = STRING_LIST_INIT_NODUP;
        struct stale_heads_info info;
+       if(for_each_remote(check_overlapping_remotes, NULL))
+               return NULL;
        info.ref_names = &ref_names;
        info.stale_refs_tail = &stale_refs;
        info.refs = refs;
diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh
index 439e996..d4ac6ce 100755
--- a/t/t5505-remote.sh
+++ b/t/t5505-remote.sh
@@ -428,7 +428,7 @@ test_expect_success 'add alt && prune' '
         git rev-parse --verify refs/remotes/origin/side2)
 '
 
-test_expect_failure 'prune and overlapping refspecs' '
+test_expect_success 'prune and overlapping refspecs' '
        (git clone --mirror one prunetst &&
         cd prunetst &&
         git remote add two ../two &&
-- 
1.8.3.1-619-gbec0aa7

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to