Skip to content

Commit b63b3d1

Browse files
committed
Merge branch 'jk/setup-gitfile-diag-fix' into next
A regression in the error diagnosis code for invalid .git files has been fixed, avoiding a potential NULL-pointer crash when reporting that a .git file does not point to a valid repository. * jk/setup-gitfile-diag-fix: read_gitfile(): simplify NOT_A_REPO error message
2 parents cbb4e98 + 54a441b commit b63b3d1

5 files changed

Lines changed: 9 additions & 8 deletions

File tree

setup.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,7 @@ int verify_repository_format(const struct repository_format *format,
925925
return 0;
926926
}
927927

928-
void read_gitfile_error_die(int error_code, const char *path, const char *dir)
928+
void read_gitfile_error_die(int error_code, const char *path)
929929
{
930930
switch (error_code) {
931931
case READ_GITFILE_ERR_NOT_A_FILE:
@@ -945,7 +945,8 @@ void read_gitfile_error_die(int error_code, const char *path, const char *dir)
945945
case READ_GITFILE_ERR_NO_PATH:
946946
die(_("no path in gitfile: %s"), path);
947947
case READ_GITFILE_ERR_NOT_A_REPO:
948-
die(_("not a git repository: %s"), dir);
948+
die(_("gitfile does not point to a valid repository: %s"),
949+
path);
949950
default:
950951
BUG("unknown error code");
951952
}
@@ -1036,7 +1037,7 @@ const char *read_gitfile_gently(const char *path, int *return_error_code)
10361037
if (return_error_code)
10371038
*return_error_code = error_code;
10381039
else if (error_code)
1039-
read_gitfile_error_die(error_code, path, dir);
1040+
read_gitfile_error_die(error_code, path);
10401041

10411042
free(buf);
10421043
return error_code ? NULL : path;
@@ -1637,7 +1638,7 @@ static enum discovery_result setup_git_directory_gently_1(struct strbuf *dir,
16371638
return GIT_DIR_INVALID_GITFILE;
16381639
default:
16391640
if (die_on_error)
1640-
read_gitfile_error_die(error_code, dir->buf, NULL);
1641+
read_gitfile_error_die(error_code, dir->buf);
16411642
else
16421643
return GIT_DIR_INVALID_GITFILE;
16431644
}

setup.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ int is_nonbare_repository_dir(struct strbuf *path);
3838
#define READ_GITFILE_ERR_TOO_LARGE 8
3939
#define READ_GITFILE_ERR_MISSING 9
4040
#define READ_GITFILE_ERR_IS_A_DIR 10
41-
void read_gitfile_error_die(int error_code, const char *path, const char *dir);
41+
void read_gitfile_error_die(int error_code, const char *path);
4242
const char *read_gitfile_gently(const char *path, int *return_error_code);
4343
#define read_gitfile(path) read_gitfile_gently((path), NULL)
4444
const char *resolve_gitdir_gently(const char *suspect, int *return_error_code);

submodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2579,7 +2579,7 @@ void absorb_git_dir_into_superproject(const char *path,
25792579

25802580
if (err_code != READ_GITFILE_ERR_NOT_A_REPO)
25812581
/* We don't know what broke here. */
2582-
read_gitfile_error_die(err_code, path, NULL);
2582+
read_gitfile_error_die(err_code, path);
25832583

25842584
/*
25852585
* Maybe populated, but no git directory was found?

t/t0002-gitfile.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ test_expect_success 'bad setup: invalid .git file format' '
2727
test_expect_success 'bad setup: invalid .git file path' '
2828
echo "gitdir: $REAL.not" >.git &&
2929
test_must_fail git rev-parse 2>.err &&
30-
test_grep "not a git repository" .err
30+
test_grep "gitfile does not point to a valid repository" .err
3131
'
3232

3333
test_expect_success 'final setup + check rev-parse --git-dir' '

t/t7450-bad-git-dotfiles.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ test_expect_success 'git dirs of sibling submodules must not be nested' '
350350
test_expect_success 'submodule git dir nesting detection must work with parallel cloning' '
351351
test_must_fail git clone --recurse-submodules --jobs=2 nested clone_parallel 2>err &&
352352
cat err &&
353-
grep -E "(already exists|is inside git dir|not a git repository)" err &&
353+
grep -E "(already exists|is inside git dir|does not point to a valid repository)" err &&
354354
{
355355
test_path_is_missing .git/modules/hippo/HEAD ||
356356
test_path_is_missing .git/modules/hippo/hooks/HEAD

0 commit comments

Comments
 (0)