Skip to content

Commit 272fd91

Browse files
committed
Merge branch 'gt/core-bare-in-templates'
Code simplification. * gt/core-bare-in-templates: setup: remove unnecessary variable
2 parents 4fecb94 + 8145a8f commit 272fd91

File tree

3 files changed

+8
-49
lines changed

3 files changed

+8
-49
lines changed

setup.c

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1968,7 +1968,6 @@ void create_reference_database(unsigned int ref_storage_format,
19681968
static int create_default_files(const char *template_path,
19691969
const char *original_git_dir,
19701970
const struct repository_format *fmt,
1971-
int prev_bare_repository,
19721971
int init_shared_repository)
19731972
{
19741973
struct stat st1;
@@ -2003,34 +2002,8 @@ static int create_default_files(const char *template_path,
20032002
*/
20042003
if (init_shared_repository != -1)
20052004
set_shared_repository(init_shared_repository);
2006-
/*
2007-
* TODO: heed core.bare from config file in templates if no
2008-
* command-line override given
2009-
*/
2010-
is_bare_repository_cfg = prev_bare_repository || !work_tree;
2011-
/* TODO (continued):
2012-
*
2013-
* Unfortunately, the line above is equivalent to
2014-
* is_bare_repository_cfg = !work_tree;
2015-
* which ignores the config entirely even if no `--[no-]bare`
2016-
* command line option was present.
2017-
*
2018-
* To see why, note that before this function, there was this call:
2019-
* prev_bare_repository = is_bare_repository()
2020-
* expanding the right hand side:
2021-
* = is_bare_repository_cfg && !get_git_work_tree()
2022-
* = is_bare_repository_cfg && !work_tree
2023-
* note that the last simplification above is valid because nothing
2024-
* calls repo_init() or set_git_work_tree() between any of the
2025-
* relevant calls in the code, and thus the !get_git_work_tree()
2026-
* calls will return the same result each time. So, what we are
2027-
* interested in computing is the right hand side of the line of
2028-
* code just above this comment:
2029-
* prev_bare_repository || !work_tree
2030-
* = is_bare_repository_cfg && !work_tree || !work_tree
2031-
* = !work_tree
2032-
* because "A && !B || !B == !B" for all boolean values of A & B.
2033-
*/
2005+
2006+
is_bare_repository_cfg = !work_tree;
20342007

20352008
/*
20362009
* We would have created the above under user's umask -- under
@@ -2182,7 +2155,6 @@ int init_db(const char *git_dir, const char *real_git_dir,
21822155
int exist_ok = flags & INIT_DB_EXIST_OK;
21832156
char *original_git_dir = real_pathdup(git_dir, 1);
21842157
struct repository_format repo_fmt = REPOSITORY_FORMAT_INIT;
2185-
int prev_bare_repository;
21862158

21872159
if (real_git_dir) {
21882160
struct stat st;
@@ -2208,7 +2180,6 @@ int init_db(const char *git_dir, const char *real_git_dir,
22082180

22092181
safe_create_dir(git_dir, 0);
22102182

2211-
prev_bare_repository = is_bare_repository();
22122183

22132184
/* Check to see if the repository version is right.
22142185
* Note that a newly created repository does not have
@@ -2221,8 +2192,7 @@ int init_db(const char *git_dir, const char *real_git_dir,
22212192
validate_ref_storage_format(&repo_fmt, ref_storage_format);
22222193

22232194
reinit = create_default_files(template_dir, original_git_dir,
2224-
&repo_fmt, prev_bare_repository,
2225-
init_shared_repository);
2195+
&repo_fmt, init_shared_repository);
22262196

22272197
/*
22282198
* Now that we have set up both the hash algorithm and the ref storage

t/t1301-shared-repo.sh

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,26 +52,15 @@ test_expect_success 'shared=all' '
5252
test 2 = $(git config core.sharedrepository)
5353
'
5454

55-
test_expect_failure 'template can set core.bare' '
55+
test_expect_success 'template cannot set core.bare' '
5656
test_when_finished "rm -rf subdir" &&
5757
test_when_finished "rm -rf templates" &&
5858
test_config core.bare true &&
5959
umask 0022 &&
6060
mkdir -p templates/ &&
6161
cp .git/config templates/config &&
6262
git init --template=templates subdir &&
63-
test_path_exists subdir/HEAD
64-
'
65-
66-
test_expect_success 'template can set core.bare but overridden by command line' '
67-
test_when_finished "rm -rf subdir" &&
68-
test_when_finished "rm -rf templates" &&
69-
test_config core.bare true &&
70-
umask 0022 &&
71-
mkdir -p templates/ &&
72-
cp .git/config templates/config &&
73-
git init --no-bare --template=templates subdir &&
74-
test_path_exists subdir/.git/HEAD
63+
test_path_is_missing subdir/HEAD
7564
'
7665

7766
test_expect_success POSIXPERM 'update-server-info honors core.sharedRepository' '

t/t5606-clone-options.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,14 @@ test_expect_success 'prefers -c config over --template config' '
120120
121121
'
122122

123-
test_expect_failure 'prefers --template config even for core.bare' '
123+
test_expect_success 'ignore --template config for core.bare' '
124124
125125
template="$TRASH_DIRECTORY/template-with-bare-config" &&
126126
mkdir "$template" &&
127127
git config --file "$template/config" core.bare true &&
128128
git clone "--template=$template" parent clone-bare-config &&
129-
test "$(git -C clone-bare-config config --local core.bare)" = "true" &&
130-
test_path_is_file clone-bare-config/HEAD
129+
test "$(git -C clone-bare-config config --local core.bare)" = "false" &&
130+
test_path_is_missing clone-bare-config/HEAD
131131
'
132132

133133
test_expect_success 'prefers config "clone.defaultRemoteName" over default' '

0 commit comments

Comments
 (0)