Merge branch 'jk/clone-progress-to-stderr'
authorJunio C Hamano <gitster@pobox.com>
Fri, 18 Oct 2013 20:49:51 +0000 (13:49 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 18 Oct 2013 20:49:51 +0000 (13:49 -0700)
Some progress and diagnostic messages from "git clone" were
incorrectly sent to the standard output stream, not to the standard
error stream.

* jk/clone-progress-to-stderr:
clone: always set transport options
clone: treat "checking connectivity" like other progress
clone: send diagnostic messages to stderr

1  2 
builtin/clone.c
t/t5601-clone.sh
diff --combined builtin/clone.c
index b708c115a344974b79501ec896ce87ad30905450,63f298be9c991e50e476f21cdbbc333d849a734a..874e0fd0b6e3ea4882783c0b2377016d93bd989d
@@@ -62,22 -62,23 +62,22 @@@ static struct option builtin_clone_opti
        OPT__VERBOSITY(&option_verbosity),
        OPT_BOOL(0, "progress", &option_progress,
                 N_("force progress reporting")),
 -      OPT_BOOLEAN('n', "no-checkout", &option_no_checkout,
 -                  N_("don't create a checkout")),
 -      OPT_BOOLEAN(0, "bare", &option_bare, N_("create a bare repository")),
 -      { OPTION_BOOLEAN, 0, "naked", &option_bare, NULL,
 -              N_("create a bare repository"),
 -              PARSE_OPT_NOARG | PARSE_OPT_HIDDEN },
 -      OPT_BOOLEAN(0, "mirror", &option_mirror,
 -                  N_("create a mirror repository (implies bare)")),
 +      OPT_BOOL('n', "no-checkout", &option_no_checkout,
 +               N_("don't create a checkout")),
 +      OPT_BOOL(0, "bare", &option_bare, N_("create a bare repository")),
 +      OPT_HIDDEN_BOOL(0, "naked", &option_bare,
 +                      N_("create a bare repository")),
 +      OPT_BOOL(0, "mirror", &option_mirror,
 +               N_("create a mirror repository (implies bare)")),
        OPT_BOOL('l', "local", &option_local,
                N_("to clone from a local repository")),
 -      OPT_BOOLEAN(0, "no-hardlinks", &option_no_hardlinks,
 +      OPT_BOOL(0, "no-hardlinks", &option_no_hardlinks,
                    N_("don't use local hardlinks, always copy")),
 -      OPT_BOOLEAN('s', "shared", &option_shared,
 +      OPT_BOOL('s', "shared", &option_shared,
                    N_("setup as shared repository")),
 -      OPT_BOOLEAN(0, "recursive", &option_recursive,
 +      OPT_BOOL(0, "recursive", &option_recursive,
                    N_("initialize submodules in the clone")),
 -      OPT_BOOLEAN(0, "recurse-submodules", &option_recursive,
 +      OPT_BOOL(0, "recurse-submodules", &option_recursive,
                    N_("initialize submodules in the clone")),
        OPT_STRING(0, "template", &option_template, N_("template-directory"),
                   N_("directory from which templates will be used")),
@@@ -379,7 -380,7 +379,7 @@@ static void clone_local(const char *src
        }
  
        if (0 <= option_verbosity)
-               printf(_("done.\n"));
+               fprintf(stderr, _("done.\n"));
  }
  
  static const char *junk_work_tree;
@@@ -550,13 -551,13 +550,13 @@@ static void update_remote_refs(const st
        const struct ref *rm = mapped_refs;
  
        if (check_connectivity) {
-               if (0 <= option_verbosity)
-                       printf(_("Checking connectivity... "));
+               if (transport->progress)
+                       fprintf(stderr, _("Checking connectivity... "));
                if (check_everything_connected_with_transport(iterate_ref_map,
                                                              0, &rm, transport))
                        die(_("remote did not send all necessary objects"));
-               if (0 <= option_verbosity)
-                       printf(_("done.\n"));
+               if (transport->progress)
 -                      fprintf(stderr, _("done\n"));
++                      fprintf(stderr, _("done.\n"));
        }
  
        if (refs) {
@@@ -849,9 -850,9 +849,9 @@@ int cmd_clone(int argc, const char **ar
  
        if (0 <= option_verbosity) {
                if (option_bare)
-                       printf(_("Cloning into bare repository '%s'...\n"), dir);
+                       fprintf(stderr, _("Cloning into bare repository '%s'...\n"), dir);
                else
-                       printf(_("Cloning into '%s'...\n"), dir);
+                       fprintf(stderr, _("Cloning into '%s'...\n"), dir);
        }
        init_db(option_template, INIT_DB_QUIET);
        write_config(&option_config);
        remote = remote_get(option_origin);
        transport = transport_get(remote, remote->url[0]);
  
-       if (!is_local) {
-               if (!transport->get_refs_list || !transport->fetch)
-                       die(_("Don't know how to clone %s"), transport->url);
+       if (!transport->get_refs_list || (!is_local && !transport->fetch))
+               die(_("Don't know how to clone %s"), transport->url);
  
-               transport_set_option(transport, TRANS_OPT_KEEP, "yes");
+       transport_set_option(transport, TRANS_OPT_KEEP, "yes");
  
-               if (option_depth)
-                       transport_set_option(transport, TRANS_OPT_DEPTH,
-                                            option_depth);
-               if (option_single_branch)
-                       transport_set_option(transport, TRANS_OPT_FOLLOWTAGS, "1");
+       if (option_depth)
+               transport_set_option(transport, TRANS_OPT_DEPTH,
+                                    option_depth);
+       if (option_single_branch)
+               transport_set_option(transport, TRANS_OPT_FOLLOWTAGS, "1");
  
-               transport_set_verbosity(transport, option_verbosity, option_progress);
+       transport_set_verbosity(transport, option_verbosity, option_progress);
  
-               if (option_upload_pack)
-                       transport_set_option(transport, TRANS_OPT_UPLOADPACK,
-                                            option_upload_pack);
+       if (option_upload_pack)
+               transport_set_option(transport, TRANS_OPT_UPLOADPACK,
+                                    option_upload_pack);
  
-               if (transport->smart_options && !option_depth)
-                       transport->smart_options->check_self_contained_and_connected = 1;
-       }
+       if (transport->smart_options && !option_depth)
+               transport->smart_options->check_self_contained_and_connected = 1;
  
        refs = transport_get_remote_refs(transport);
  
                        our_head_points_at = remote_head_points_at;
        }
        else {
 +              if (option_branch)
 +                      die(_("Remote branch %s not found in upstream %s"),
 +                                      option_branch, option_origin);
 +
                warning(_("You appear to have cloned an empty repository."));
                mapped_refs = NULL;
                our_head_points_at = NULL;
diff --combined t/t5601-clone.sh
index a3e3d489ec9db3c3ca0e53ffd2307dd3652c3713,b3b11e61c03e5d6d3e49a6f2d4a2281f05a7a600..8f3cd44d514f3996b62da28f6f83be7b1d786f01
@@@ -36,7 -36,7 +36,7 @@@ test_expect_success 'clone with excess 
  
  test_expect_success C_LOCALE_OUTPUT 'output from clone' '
        rm -fr dst &&
-       git clone -n "file://$(pwd)/src" dst >output &&
+       git clone -n "file://$(pwd)/src" dst >output 2>&1 &&
        test $(grep Clon output | wc -l) = 1
  '
  
@@@ -280,53 -280,9 +280,53 @@@ test_expect_success 'clone checking ou
        test_cmp fetch.expected fetch.actual
  '
  
 +test_expect_success 'setup ssh wrapper' '
 +      write_script "$TRASH_DIRECTORY/ssh-wrapper" <<-\EOF &&
 +      echo >>"$TRASH_DIRECTORY/ssh-output" "ssh: $*" &&
 +      # throw away all but the last argument, which should be the
 +      # command
 +      while test $# -gt 1; do shift; done
 +      eval "$1"
 +      EOF
 +
 +      GIT_SSH="$TRASH_DIRECTORY/ssh-wrapper" &&
 +      export GIT_SSH &&
 +      export TRASH_DIRECTORY
 +'
 +
 +clear_ssh () {
 +      >"$TRASH_DIRECTORY/ssh-output"
 +}
 +
 +expect_ssh () {
 +      {
 +              case "$1" in
 +              none)
 +                      ;;
 +              *)
 +                      echo "ssh: $1 git-upload-pack '$2'"
 +              esac
 +      } >"$TRASH_DIRECTORY/ssh-expect" &&
 +      (cd "$TRASH_DIRECTORY" && test_cmp ssh-expect ssh-output)
 +}
 +
 +test_expect_success 'cloning myhost:src uses ssh' '
 +      clear_ssh &&
 +      git clone myhost:src ssh-clone &&
 +      expect_ssh myhost src
 +'
 +
  test_expect_success NOT_MINGW,NOT_CYGWIN 'clone local path foo:bar' '
 +      clear_ssh &&
        cp -R src "foo:bar" &&
 -      git clone "./foo:bar" foobar
 +      git clone "./foo:bar" foobar &&
 +      expect_ssh none
 +'
 +
 +test_expect_success 'bracketed hostnames are still ssh' '
 +      clear_ssh &&
 +      git clone "[myhost:123]:src" ssh-bracket-clone &&
 +      expect_ssh myhost:123 src
  '
  
  test_done