# Forcing progerss output for clone

11 messages from 2008-10-03 to 2008-10-09. Participants: Constantine Plotnikov, Alex Riesen, Miklos Vajna, Shawn O. Pearce, Junio C Hamano.
Thread: https://gitlist.dev/t/15777

## Constantine Plotnikov, 2008-10-03 20:01

Subject: Forcing progerss output for clone
Message-ID: <85647ef50810031301k641c5f24n65fb213c2b481e7@mail.gmail.com>
URL: https://gitlist.dev/e/85647ef50810031301k641c5f24n65fb213c2b481e7%40mail.gmail.com

```
Hello!

Is there a way to force a progress output on stderr for git clone
preferably using options or environment variables?

The clone command in the git 1.6.0.2 does not print a progress
information to stderr if stdout and stderr are redirected (even if no
"-q" option is specified).

Such information would have been useful for displaying progress
information when cloning from IDE. IDE run git with streams
redirected, and this progress information could have been displayed to
user to indicate current status of operation.

Best Regards,
Constantine

```

## Alex Riesen, 2008-10-04 21:42

Subject: Re: Forcing progerss output for clone
Message-ID: <81b0412b0810041442i3aa29628lf66ef9b188fe8ce7@mail.gmail.com>
URL: https://gitlist.dev/e/81b0412b0810041442i3aa29628lf66ef9b188fe8ce7%40mail.gmail.com
In-Reply-To: <85647ef50810031301k641c5f24n65fb213c2b481e7@mail.gmail.com>

```
2008/10/3 Constantine Plotnikov <constantine.plotnikov@gmail.com>:
> Is there a way to force a progress output on stderr for git clone
> preferably using options or environment variables?

No, but "-v" option is not used for anything yet, so you are free to
implement it.

```

## Miklos Vajna, 2008-10-06 22:19

Subject: [PATCH] Implement git clone -v
Message-ID: <1223331590-22138-1-git-send-email-vmiklos@frugalware.org>
URL: https://gitlist.dev/e/1223331590-22138-1-git-send-email-vmiklos%40frugalware.org
In-Reply-To: <81b0412b0810041442i3aa29628lf66ef9b188fe8ce7@mail.gmail.com>

```
The new -v option forces the progressbar, even in case the output is not
a terminal.

Signed-off-by: Miklos Vajna <vmiklos@frugalware.org>
---

On Sat, Oct 04, 2008 at 11:42:15PM +0200, Alex Riesen <raa.lkml@gmail.com> wrote:
> 2008/10/3 Constantine Plotnikov <constantine.plotnikov@gmail.com>:
> > Is there a way to force a progress output on stderr for git clone
> > preferably using options or environment variables?
>
> No, but "-v" option is not used for anything yet, so you are free to
> implement it.

Something like this?

 Documentation/git-clone.txt |    5 +++++
 builtin-clone.c             |    4 ++++
 transport.c                 |    2 +-
 transport.h                 |    2 ++
 4 files changed, 12 insertions(+), 1 deletions(-)

diff --git a/Documentation/git-clone.txt b/Documentation/git-clone.txt
index 0e14e73..95f08b9 100644
--- a/Documentation/git-clone.txt
+++ b/Documentation/git-clone.txt
@@ -90,6 +90,11 @@ then the cloned repository will become corrupt.
 	Operate quietly.  This flag is also passed to the `rsync'
 	command when given.
 
+--verbose::
+-v::
+	Display the progressbar, even in case the standard output is not
+	a terminal.
+
 --no-checkout::
 -n::
 	No checkout of HEAD is performed after the clone is complete.
diff --git a/builtin-clone.c b/builtin-clone.c
index 49d2eb9..df71b23 100644
--- a/builtin-clone.c
+++ b/builtin-clone.c
@@ -38,9 +38,11 @@ static int option_local, option_no_hardlinks, option_shared;
 static char *option_template, *option_reference, *option_depth;
 static char *option_origin = NULL;
 static char *option_upload_pack = "git-upload-pack";
+static int option_verbose;
 
 static struct option builtin_clone_options[] = {
 	OPT__QUIET(&option_quiet),
+	OPT__VERBOSE(&option_verbose),
 	OPT_BOOLEAN('n', "no-checkout", &option_no_checkout,
 		    "don't create a checkout"),
 	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)
 
 		if (option_quiet)
 			transport->verbose = -1;
+		else if (option_verbose)
+			transport->progress = 1;
 
 		if (option_upload_pack)
 			transport_set_option(transport, TRANS_OPT_UPLOADPACK,
diff --git a/transport.c b/transport.c
index 5110c56..1c510a3 100644
--- a/transport.c
+++ b/transport.c
@@ -644,7 +644,7 @@ static int fetch_refs_via_pack(struct transport *transport,
 	args.include_tag = data->followtags;
 	args.verbose = (transport->verbose > 0);
 	args.quiet = (transport->verbose < 0);
-	args.no_progress = args.quiet || !isatty(1);
+	args.no_progress = args.quiet || (!transport->progress && !isatty(1));
 	args.depth = data->depth;
 
 	for (i = 0; i < nr_heads; i++)
diff --git a/transport.h b/transport.h
index d0b5205..6bbc1a8 100644
--- a/transport.h
+++ b/transport.h
@@ -25,6 +25,8 @@ struct transport {
 	int (*disconnect)(struct transport *connection);
 	char *pack_lockfile;
 	signed verbose : 2;
+	/* Force progress even if the output is not a tty */
+	unsigned progress : 1;
 };
 
 #define TRANSPORT_PUSH_ALL 1
-- 
1.6.0.2

```

## Alex Riesen, 2008-10-07 06:21

Subject: Re: [PATCH] Implement git clone -v
Message-ID: <81b0412b0810062321h33abe076kd87b60bffdaf218b@mail.gmail.com>
URL: https://gitlist.dev/e/81b0412b0810062321h33abe076kd87b60bffdaf218b%40mail.gmail.com
In-Reply-To: <1223331590-22138-1-git-send-email-vmiklos@frugalware.org>

```
2008/10/7 Miklos Vajna <vmiklos@frugalware.org>:
> The new -v option forces the progressbar, even in case the output is not
> a terminal.
>
> Signed-off-by: Miklos Vajna <vmiklos@frugalware.org>
> ---
>
> On Sat, Oct 04, 2008 at 11:42:15PM +0200, Alex Riesen <raa.lkml@gmail.com> wrote:
>> 2008/10/3 Constantine Plotnikov <constantine.plotnikov@gmail.com>:
>> > Is there a way to force a progress output on stderr for git clone
>> > preferably using options or environment variables?
>>
>> No, but "-v" option is not used for anything yet, so you are free to
>> implement it.
>
> Something like this?
>

Yes. Does it work? :)

```

## Miklos Vajna, 2008-10-07 19:39

Subject: Re: [PATCH] Implement git clone -v
Message-ID: <20081007193956.GB536@genesis.frugalware.org>
URL: https://gitlist.dev/e/20081007193956.GB536%40genesis.frugalware.org
In-Reply-To: <81b0412b0810062321h33abe076kd87b60bffdaf218b@mail.gmail.com>

```
On Tue, Oct 07, 2008 at 08:21:28AM +0200, Alex Riesen <raa.lkml@gmail.com> wrote:
> Yes. Does it work? :)

Yes, it does. I'm not sure how to test it from the testsuite, maybe
redirect the output to a file and grep in it? It's ugly, that's why I
did not do so, but if you think a testcase is a musthave for this
feature then that's the way to go, I guess.

```

## Shawn O. Pearce, 2008-10-08 06:02

Subject: Re: [PATCH] Implement git clone -v
Message-ID: <20081008060257.GA15240@spearce.org>
URL: https://gitlist.dev/e/20081008060257.GA15240%40spearce.org
In-Reply-To: <20081007193956.GB536@genesis.frugalware.org>

```
Miklos Vajna <vmiklos@frugalware.org> wrote:
> On Tue, Oct 07, 2008 at 08:21:28AM +0200, Alex Riesen <raa.lkml@gmail.com> wrote:
> > Yes. Does it work? :)
> 
> Yes, it does. I'm not sure how to test it from the testsuite, maybe
> redirect the output to a file and grep in it? It's ugly, that's why I
> did not do so, but if you think a testcase is a musthave for this
> feature then that's the way to go, I guess.

Actually its not a bad way to test the feature.  Normally we disable
progress if stdout is not a tty.  If you redirect to a file then
-v should be needed to get anything at all on stderr.

You may be able to just test the size of the file:

	git fetch -v ... >out 2>err &&
	test -s err

-- 
Shawn.

```

## Alex Riesen, 2008-10-08 06:25

Subject: Re: [PATCH] Implement git clone -v
Message-ID: <20081008062529.GA4028@blimp.localhost>
URL: https://gitlist.dev/e/20081008062529.GA4028%40blimp.localhost
In-Reply-To: <20081008060257.GA15240@spearce.org>

```
Shawn O. Pearce, Wed, Oct 08, 2008 08:02:57 +0200:
> Miklos Vajna <vmiklos@frugalware.org> wrote:
> > On Tue, Oct 07, 2008 at 08:21:28AM +0200, Alex Riesen <raa.lkml@gmail.com> wrote:
> > > Yes. Does it work? :)
> > 
> > Yes, it does. I'm not sure how to test it from the testsuite, maybe
> > redirect the output to a file and grep in it? It's ugly, that's why I
> > did not do so, but if you think a testcase is a musthave for this
> > feature then that's the way to go, I guess.
> 
> Actually its not a bad way to test the feature.  Normally we disable
> progress if stdout is not a tty.  If you redirect to a file then
> -v should be needed to get anything at all on stderr.
> 
> You may be able to just test the size of the file:
> 
> 	git fetch -v ... >out 2>err &&

git clone

> 	test -s err

Right, but I don't think you need tests for progress bar. As a typical
eye candy, it tends to change often enough to be too annoying to test.

```

## Miklos Vajna, 2008-10-08 23:40

Subject: [PATCH] Implement git clone -v
Message-ID: <1223509232-3520-1-git-send-email-vmiklos@frugalware.org>
URL: https://gitlist.dev/e/1223509232-3520-1-git-send-email-vmiklos%40frugalware.org
In-Reply-To: <20081008060257.GA15240@spearce.org>

```
The new -v option forces the progressbar, even in case the output is not
a terminal.

Signed-off-by: Miklos Vajna <vmiklos@frugalware.org>
---

On Tue, Oct 07, 2008 at 11:02:57PM -0700, "Shawn O. Pearce" <spearce@spearce.org> wrote:
> You may be able to just test the size of the file:
>
>       git fetch -v ... >out 2>err &&
>       test -s err

Here is an updated patch, now with testcases.

 Documentation/git-clone.txt |    5 +++++
 builtin-clone.c             |    4 ++++
 t/t5702-clone-options.sh    |   13 +++++++++++++
 transport.c                 |    2 +-
 transport.h                 |    2 ++
 5 files changed, 25 insertions(+), 1 deletions(-)

diff --git a/Documentation/git-clone.txt b/Documentation/git-clone.txt
index 0e14e73..95f08b9 100644
--- a/Documentation/git-clone.txt
+++ b/Documentation/git-clone.txt
@@ -90,6 +90,11 @@ then the cloned repository will become corrupt.
 	Operate quietly.  This flag is also passed to the `rsync'
 	command when given.
 
+--verbose::
+-v::
+	Display the progressbar, even in case the standard output is not
+	a terminal.
+
 --no-checkout::
 -n::
 	No checkout of HEAD is performed after the clone is complete.
diff --git a/builtin-clone.c b/builtin-clone.c
index 49d2eb9..df71b23 100644
--- a/builtin-clone.c
+++ b/builtin-clone.c
@@ -38,9 +38,11 @@ static int option_local, option_no_hardlinks, option_shared;
 static char *option_template, *option_reference, *option_depth;
 static char *option_origin = NULL;
 static char *option_upload_pack = "git-upload-pack";
+static int option_verbose;
 
 static struct option builtin_clone_options[] = {
 	OPT__QUIET(&option_quiet),
+	OPT__VERBOSE(&option_verbose),
 	OPT_BOOLEAN('n', "no-checkout", &option_no_checkout,
 		    "don't create a checkout"),
 	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)
 
 		if (option_quiet)
 			transport->verbose = -1;
+		else if (option_verbose)
+			transport->progress = 1;
 
 		if (option_upload_pack)
 			transport_set_option(transport, TRANS_OPT_UPLOADPACK,
diff --git a/t/t5702-clone-options.sh b/t/t5702-clone-options.sh
index 328e4d9..27825f5 100755
--- a/t/t5702-clone-options.sh
+++ b/t/t5702-clone-options.sh
@@ -19,4 +19,17 @@ test_expect_success 'clone -o' '
 
 '
 
+test_expect_success 'redirected clone' '
+
+	git clone "file://$(pwd)/parent" clone-redirected >out 2>err &&
+	test ! -s err
+
+'
+test_expect_success 'redirected clone -v' '
+
+	git clone -v "file://$(pwd)/parent" clone-redirected-v >out 2>err &&
+	test -s err
+
+'
+
 test_done
diff --git a/transport.c b/transport.c
index 5110c56..1c510a3 100644
--- a/transport.c
+++ b/transport.c
@@ -644,7 +644,7 @@ static int fetch_refs_via_pack(struct transport *transport,
 	args.include_tag = data->followtags;
 	args.verbose = (transport->verbose > 0);
 	args.quiet = (transport->verbose < 0);
-	args.no_progress = args.quiet || !isatty(1);
+	args.no_progress = args.quiet || (!transport->progress && !isatty(1));
 	args.depth = data->depth;
 
 	for (i = 0; i < nr_heads; i++)
diff --git a/transport.h b/transport.h
index d0b5205..6bbc1a8 100644
--- a/transport.h
+++ b/transport.h
@@ -25,6 +25,8 @@ struct transport {
 	int (*disconnect)(struct transport *connection);
 	char *pack_lockfile;
 	signed verbose : 2;
+	/* Force progress even if the output is not a tty */
+	unsigned progress : 1;
 };
 
 #define TRANSPORT_PUSH_ALL 1
-- 
1.6.0.2

```

## Junio C Hamano, 2008-10-09 11:06

Subject: Re: [PATCH] Implement git clone -v
Message-ID: <7vr66qown3.fsf@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vr66qown3.fsf%40gitster.siamese.dyndns.org
In-Reply-To: <1223509232-3520-1-git-send-email-vmiklos@frugalware.org>

```
Miklos Vajna <vmiklos@frugalware.org> writes:

> The new -v option forces the progressbar, even in case the output is not
> a terminal.
>
> Signed-off-by: Miklos Vajna <vmiklos@frugalware.org>

The patch made me wonder why this new feature had to be implemented in the
first place and had me look up the message the patch was an follow-up to.
For somebody who would not recall the original request-for-feature (that
includes you 6 months from now), it would have been easier to understand
the context if the commit message said what the intended purpose of this
(i.e. "have it read by an IDE").

```

## Shawn O. Pearce, 2008-10-09 15:20

Subject: Re: [PATCH] Implement git clone -v
Message-ID: <20081009152028.GA29829@spearce.org>
URL: https://gitlist.dev/e/20081009152028.GA29829%40spearce.org
In-Reply-To: <7vr66qown3.fsf@gitster.siamese.dyndns.org>

```
Junio C Hamano <gitster@pobox.com> wrote:
> Miklos Vajna <vmiklos@frugalware.org> writes:
> 
> > The new -v option forces the progressbar, even in case the output is not
> > a terminal.
> >
> > Signed-off-by: Miklos Vajna <vmiklos@frugalware.org>
> 
> The patch made me wonder why this new feature had to be implemented in the
> first place and had me look up the message the patch was an follow-up to.
> For somebody who would not recall the original request-for-feature (that
> includes you 6 months from now), it would have been easier to understand
> the context if the commit message said what the intended purpose of this
> (i.e. "have it read by an IDE").

I'm amending the message as the following:

--8<--
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>
--

-- 
Shawn.

```

## Miklos Vajna, 2008-10-09 21:26

Subject: Re: [PATCH] Implement git clone -v
Message-ID: <20081009212644.GX536@genesis.frugalware.org>
URL: https://gitlist.dev/e/20081009212644.GX536%40genesis.frugalware.org
In-Reply-To: <20081009152028.GA29829@spearce.org>

```
On Thu, Oct 09, 2008 at 08:20:28AM -0700, "Shawn O. Pearce" <spearce@spearce.org> wrote:
> I'm amending the message as the following:
> 
> --8<--
> 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.

Thanks!

```
