Skip to content

Commit 7bdebaa

Browse files
committed
Merge branch 'sg/ref-filter-wo-repository'
"git ls-remote --sort=<thing>" can feed an object that is not yet available into the comparison machinery and segfault, which has been corrected to check such a request upfront and reject it. * sg/ref-filter-wo-repository: ref-filter: don't look for objects when outside of a repository
2 parents 56e4af3 + 47bd3d0 commit 7bdebaa

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

ref-filter.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,10 @@ static int parse_ref_filter_atom(const struct ref_format *format,
534534
if (ARRAY_SIZE(valid_atom) <= i)
535535
return strbuf_addf_ret(err, -1, _("unknown field name: %.*s"),
536536
(int)(ep-atom), atom);
537+
if (valid_atom[i].source != SOURCE_NONE && !have_git_dir())
538+
return strbuf_addf_ret(err, -1,
539+
_("not a git repository, but the field '%.*s' requires access to object data"),
540+
(int)(ep-atom), atom);
537541

538542
/* Add it in, including the deref prefix */
539543
at = used_atom_cnt;

t/t5512-ls-remote.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,12 @@ test_expect_success 'ls-remote works outside repository' '
302302
nongit git ls-remote dst.git
303303
'
304304

305+
test_expect_success 'ls-remote --sort fails gracefully outside repository' '
306+
# Use a sort key that requires access to the referenced objects.
307+
nongit test_must_fail git ls-remote --sort=authordate "$TRASH_DIRECTORY" 2>err &&
308+
test_i18ngrep "^fatal: not a git repository, but the field '\''authordate'\'' requires access to object data" err
309+
'
310+
305311
test_expect_success 'ls-remote patterns work with all protocol versions' '
306312
git for-each-ref --format="%(objectname) %(refname)" \
307313
refs/heads/master refs/remotes/origin/master >expect &&

0 commit comments

Comments
 (0)