Implement git clone -v
The new -v option forces the progressbar, even in case the output is not a terminal. This can be useful if the caller is an IDE or wrapper which wants to scrape the progressbar from stderr and show its information in a different format. Signed-off-by: Miklos Vajna <vmiklos@frugalware.org> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Miklos Vajna committed
Oct 9, 2008 at 01:40 UTC
21188b1eafd3741fda0f7905dc997279a17b50ba
5 files changed
+25
-1
Documentation/git-clone.txt
+5
@@ -90,6 +90,11 @@ then the cloned repository will become corrupt.
90
Operate quietly. This flag is also passed to the `rsync'
91
command when given.
92
93
+--verbose::
94
+-v::
95
+ Display the progressbar, even in case the standard output is not
96
+ a terminal.
97
+
98
--no-checkout::
99
-n::
100
No checkout of HEAD is performed after the clone is complete.
builtin-clone.c
+4
@@ -38,9 +38,11 @@ static int option_local, option_no_hardlinks, option_shared;
38
static char *option_template, *option_reference, *option_depth;
39
static char *option_origin = NULL;
40
static char *option_upload_pack = "git-upload-pack";
41
+static int option_verbose;
42
43
static struct option builtin_clone_options[] = {
44
OPT__QUIET(&option_quiet),
45
+ OPT__VERBOSE(&option_verbose),
46
OPT_BOOLEAN('n', "no-checkout", &option_no_checkout,
47
"don't create a checkout"),
48
OPT_BOOLEAN(0, "bare", &option_bare, "create a bare repository"),
@@ -506,6 +508,8 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
508
509
if (option_quiet)
510
transport->verbose = -1;
511
+ else if (option_verbose)
512
+ transport->progress = 1;
513
514
if (option_upload_pack)
515
transport_set_option(transport, TRANS_OPT_UPLOADPACK,
t/t5702-clone-options.sh
+13
@@ -19,4 +19,17 @@ test_expect_success 'clone -o' '
19
20
'
21
22
+test_expect_success 'redirected clone' '
23
+
24
+ git clone "file://$(pwd)/parent" clone-redirected >out 2>err &&
25
+ test ! -s err
26
+
27
+'
28
+test_expect_success 'redirected clone -v' '
29
+
30
+ git clone -v "file://$(pwd)/parent" clone-redirected-v >out 2>err &&
31
+ test -s err
32
+
33
+'
34
+
35
test_done
transport.c
+1
-1
@@ -644,7 +644,7 @@ static int fetch_refs_via_pack(struct transport *transport,
644
args.include_tag = data->followtags;
645
args.verbose = (transport->verbose > 0);
646
args.quiet = (transport->verbose < 0);
647
- args.no_progress = args.quiet || !isatty(1);
647
+ args.no_progress = args.quiet || (!transport->progress && !isatty(1));
648
args.depth = data->depth;
649
650
for (i = 0; i < nr_heads; i++)
transport.h
+2
@@ -25,6 +25,8 @@ struct transport {
25
int (*disconnect)(struct transport *connection);
26
char *pack_lockfile;
27
signed verbose : 2;
28
+ /* Force progress even if the output is not a tty */
29
+ unsigned progress : 1;
30
};
31
32
#define TRANSPORT_PUSH_ALL 1