Merge branch 'jk/guess-repo-name-regression-fix'
authorJunio C Hamano <gitster@pobox.com>
Wed, 19 Aug 2015 21:48:54 +0000 (14:48 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 19 Aug 2015 21:48:54 +0000 (14:48 -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
@@@ -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);
@@@ -484,26 -484,16 +485,26 @@@ static void write_remote_refs(const str
  {
        const struct ref *r;
  
 -      lock_packed_refs(LOCK_DIE_ON_ERROR);
 +      struct ref_transaction *t;
 +      struct strbuf err = STRBUF_INIT;
 +
 +      t = ref_transaction_begin(&err);
 +      if (!t)
 +              die("%s", err.buf);
  
        for (r = local_refs; r; r = r->next) {
                if (!r->peer_ref)
                        continue;
 -              add_packed_ref(r->peer_ref->name, r->old_sha1);
 +              if (ref_transaction_create(t, r->peer_ref->name, r->old_sha1,
 +                                         0, NULL, &err))
 +                      die("%s", err.buf);
        }
  
 -      if (commit_packed_refs())
 -              die_errno("unable to overwrite old ref-pack file");
 +      if (initial_ref_transaction_commit(t, &err))
 +              die("%s", err.buf);
 +
 +      strbuf_release(&err);
 +      ref_transaction_free(t);
  }
  
  static void write_followtags(const struct ref *refs, const char *msg)