Skip to content

Commit 2cb6009

Browse files
pcloudsgitster
authored andcommitted
bundle: run setup_git_directory_gently() sooner
Without this change, “git -p bundle” does not always respect the repository-local “[core] pager” setting. It is hard to notice because subcommands other than “git bundle unbundle” do not produce much output. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent d1ea896 commit 2cb6009

File tree

3 files changed

+36
-5
lines changed

3 files changed

+36
-5
lines changed

builtin/bundle.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ static const char builtin_bundle_usage[] =
1818
int cmd_bundle(int argc, const char **argv, const char *prefix)
1919
{
2020
struct bundle_header header;
21-
int nongit;
2221
const char *cmd, *bundle_file;
2322
int bundle_fd = -1;
2423
char buffer[PATH_MAX];
@@ -31,7 +30,6 @@ int cmd_bundle(int argc, const char **argv, const char *prefix)
3130
argc -= 2;
3231
argv += 2;
3332

34-
prefix = setup_git_directory_gently(&nongit);
3533
if (prefix && bundle_file[0] != '/') {
3634
snprintf(buffer, sizeof(buffer), "%s/%s", prefix, bundle_file);
3735
bundle_file = buffer;
@@ -54,11 +52,11 @@ int cmd_bundle(int argc, const char **argv, const char *prefix)
5452
return !!list_bundle_refs(&header, argc, argv);
5553
}
5654
if (!strcmp(cmd, "create")) {
57-
if (nongit)
55+
if (!startup_info->have_repository)
5856
die("Need a repository to create a bundle.");
5957
return !!create_bundle(&header, bundle_file, argc, argv);
6058
} else if (!strcmp(cmd, "unbundle")) {
61-
if (nongit)
59+
if (!startup_info->have_repository)
6260
die("Need a repository to unbundle.");
6361
return !!unbundle(&header, bundle_fd) ||
6462
list_bundle_refs(&header, argc, argv);

git.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ static void handle_internal_command(int argc, const char **argv)
306306
{ "bisect--helper", cmd_bisect__helper, RUN_SETUP | NEED_WORK_TREE },
307307
{ "blame", cmd_blame, RUN_SETUP },
308308
{ "branch", cmd_branch, RUN_SETUP },
309-
{ "bundle", cmd_bundle },
309+
{ "bundle", cmd_bundle, RUN_SETUP_GENTLY },
310310
{ "cat-file", cmd_cat_file, RUN_SETUP },
311311
{ "checkout", cmd_checkout, RUN_SETUP | NEED_WORK_TREE },
312312
{ "checkout-index", cmd_checkout_index,

t/t7006-pager.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,21 @@ test_expect_success TTY 'some commands use a pager' '
5858
test -e paginated.out
5959
'
6060

61+
test_expect_failure TTY 'pager runs from subdir' '
62+
echo subdir/paginated.out >expected &&
63+
mkdir -p subdir &&
64+
rm -f paginated.out subdir/paginated.out &&
65+
(
66+
cd subdir &&
67+
test_terminal git log
68+
) &&
69+
{
70+
ls paginated.out subdir/paginated.out ||
71+
:
72+
} >actual &&
73+
test_cmp expected actual
74+
'
75+
6176
test_expect_success TTY 'some commands do not use a pager' '
6277
rm -f paginated.out ||
6378
cleanup_fail &&
@@ -119,6 +134,24 @@ test_expect_success TTY 'configuration can disable pager' '
119134
! test -e paginated.out
120135
'
121136

137+
test_expect_success 'configuration can enable pager (from subdir)' '
138+
rm -f paginated.out &&
139+
mkdir -p subdir &&
140+
git config pager.bundle true &&
141+
test_when_finished "git config --unset pager.bundle" &&
142+
143+
git bundle create test.bundle --all &&
144+
rm -f paginated.out subdir/paginated.out &&
145+
(
146+
cd subdir &&
147+
test_terminal git bundle unbundle ../test.bundle
148+
) &&
149+
{
150+
test -e paginated.out ||
151+
test -e subdir/paginated.out
152+
}
153+
'
154+
122155
# A colored commit log will begin with an appropriate ANSI escape
123156
# for the first color; the text "commit" comes later.
124157
colorful() {

0 commit comments

Comments
 (0)