Skip to content

Commit 4433bd2

Browse files
adlternativegitster
authored andcommitted
scalar: show progress if stderr refers to a terminal
Sometimes when users use scalar to download a monorepo with a long commit history, they want to check the progress bar to know how long they still need to wait during the fetch process, but scalar suppresses this output by default. So let's check whether scalar stderr refer to a terminal, if so, show progress, otherwise disable it. Signed-off-by: ZheNing Hu <[email protected]> Acked-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c48035d commit 4433bd2

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
@@ -404,7 +404,7 @@ void load_builtin_commands(const char *prefix, struct cmdnames *cmds)
404404
static int cmd_clone(int argc, const char **argv)
405405
{
406406
const char *branch = NULL;
407-
int full_clone = 0, single_branch = 0;
407+
int full_clone = 0, single_branch = 0, show_progress = isatty(2);
408408
struct option clone_options[] = {
409409
OPT_STRING('b', "branch", &branch, N_("<branch>"),
410410
N_("branch to checkout after clone")),
@@ -499,7 +499,9 @@ static int cmd_clone(int argc, const char **argv)
499499
if (set_recommended_config(0))
500500
return error(_("could not configure '%s'"), dir);
501501

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

505507
if (set_config("remote.origin.promisor") ||
@@ -508,7 +510,9 @@ static int cmd_clone(int argc, const char **argv)
508510
goto cleanup;
509511
}
510512

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

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)