Skip to content

Commit ebed06a

Browse files
committed
Merge branch 'zh/scalar-progress'
"scalar" learned to give progress bar. * zh/scalar-progress: scalar: show progress if stderr refers to a terminal
2 parents 5287319 + 4433bd2 commit ebed06a

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

scalar.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ void load_builtin_commands(const char *prefix, struct cmdnames *cmds)
405405
static int cmd_clone(int argc, const char **argv)
406406
{
407407
const char *branch = NULL;
408-
int full_clone = 0, single_branch = 0;
408+
int full_clone = 0, single_branch = 0, show_progress = isatty(2);
409409
struct option clone_options[] = {
410410
OPT_STRING('b', "branch", &branch, N_("<branch>"),
411411
N_("branch to checkout after clone")),
@@ -500,7 +500,9 @@ static int cmd_clone(int argc, const char **argv)
500500
if (set_recommended_config(0))
501501
return error(_("could not configure '%s'"), dir);
502502

503-
if ((res = run_git("fetch", "--quiet", "origin", NULL))) {
503+
if ((res = run_git("fetch", "--quiet",
504+
show_progress ? "--progress" : "--no-progress",
505+
"origin", NULL))) {
504506
warning(_("partial clone failed; attempting full clone"));
505507

506508
if (set_config("remote.origin.promisor") ||
@@ -509,7 +511,9 @@ static int cmd_clone(int argc, const char **argv)
509511
goto cleanup;
510512
}
511513

512-
if ((res = run_git("fetch", "--quiet", "origin", NULL)))
514+
if ((res = run_git("fetch", "--quiet",
515+
show_progress ? "--progress" : "--no-progress",
516+
"origin", NULL)))
513517
goto cleanup;
514518
}
515519

t/t9211-scalar-clone.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
test_description='test the `scalar clone` subcommand'
44

55
. ./test-lib.sh
6+
. "${TEST_DIRECTORY}/lib-terminal.sh"
67

78
GIT_TEST_MAINT_SCHEDULER="crontab:test-tool crontab cron.txt,launchctl:true,schtasks:true"
89
export GIT_TEST_MAINT_SCHEDULER
@@ -148,4 +149,29 @@ test_expect_success '--no-single-branch clones all branches' '
148149
cleanup_clone $enlistment
149150
'
150151

152+
test_expect_success TTY 'progress with tty' '
153+
enlistment=progress1 &&
154+
155+
test_config -C to-clone uploadpack.allowfilter true &&
156+
test_config -C to-clone uploadpack.allowanysha1inwant true &&
157+
158+
test_terminal env GIT_PROGRESS_DELAY=0 \
159+
scalar clone "file://$(pwd)/to-clone" "$enlistment" 2>stderr &&
160+
grep "Enumerating objects" stderr >actual &&
161+
test_line_count = 2 actual &&
162+
cleanup_clone $enlistment
163+
'
164+
165+
test_expect_success 'progress without tty' '
166+
enlistment=progress2 &&
167+
168+
test_config -C to-clone uploadpack.allowfilter true &&
169+
test_config -C to-clone uploadpack.allowanysha1inwant true &&
170+
171+
GIT_PROGRESS_DELAY=0 scalar clone "file://$(pwd)/to-clone" "$enlistment" 2>stderr &&
172+
! grep "Enumerating objects" stderr &&
173+
! grep "Updating files" stderr &&
174+
cleanup_clone $enlistment
175+
'
176+
151177
test_done

0 commit comments

Comments
 (0)