Merge branch 'jk/guess-repo-name-regression-fix' into maint
authorJunio C Hamano <gitster@pobox.com>
Tue, 25 Aug 2015 23:09:17 +0000 (16:09 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 25 Aug 2015 23:09:17 +0000 (16:09 -0700)
"git clone $URL" in recent releases of Git contains a regression in
the code that invents a new repository name incorrectly based on
the $URL. This has been corrected.

* jk/guess-repo-name-regression-fix:
clone: use computed length in guess_dir_name
clone: add tests for output directory

1  2 
builtin/clone.c
diff --combined builtin/clone.c
index a72ff7e0098da9c89f6000e724ea097e3403601f,ed484cb6f488883872be7cde82c67d12cebeab4e..53cf545c5ec20a97e8380979d304acad7ec0e965
@@@ -174,7 -174,8 +174,8 @@@ static char *guess_dir_name(const char 
        /*
         * Strip .{bundle,git}.
         */
-       strip_suffix(start, is_bundle ? ".bundle" : ".git" , &len);
+       len = end - start;
+       strip_suffix_mem(start, &len, is_bundle ? ".bundle" : ".git");
  
        if (is_bare)
                dir = xstrfmt("%.*s.git", (int)len, start);
@@@ -277,17 -278,16 +278,17 @@@ static void copy_alternates(struct strb
        struct strbuf line = STRBUF_INIT;
  
        while (strbuf_getline(&line, in, '\n') != EOF) {
 -              char *abs_path, abs_buf[PATH_MAX];
 +              char *abs_path;
                if (!line.len || line.buf[0] == '#')
                        continue;
                if (is_absolute_path(line.buf)) {
                        add_to_alternates_file(line.buf);
                        continue;
                }
 -              abs_path = mkpath("%s/objects/%s", src_repo, line.buf);
 -              normalize_path_copy(abs_buf, abs_path);
 -              add_to_alternates_file(abs_buf);
 +              abs_path = mkpathdup("%s/objects/%s", src_repo, line.buf);
 +              normalize_path_copy(abs_path, abs_path);
 +              add_to_alternates_file(abs_path);
 +              free(abs_path);
        }
        strbuf_release(&line);
        fclose(in);