From: SZEDER Gábor Date: Wed, 14 Nov 2018 12:27:25 +0000 (+0100) Subject: ref-filter: don't look for objects when outside of a repository X-Git-Tag: v2.20.0-rc0~4^2 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/47bd3d0c14f081a3ea32b0720f7d59559802904d?hp=47bd3d0c14f081a3ea32b0720f7d59559802904d ref-filter: don't look for objects when outside of a repository The command 'git ls-remote --sort=authordate ' segfaults when run outside of a repository, ever since the introduction of its '--sort' option in 1fb20dfd8e (ls-remote: create '--sort' option, 2018-04-09). While in general the 'git ls-remote' command can be run outside of a repository just fine, its '--sort=' option with certain keys does require access to the referenced objects. This sorting is implemented using the generic ref-filter sorting facility, which already handles missing objects gracefully with the appropriate 'missing object deadbeef for HEAD' message. However, being generic means that it checks replace refs while trying to retrieve an object, and while doing so it accesses the 'git_replace_ref_base' variable, which has not been initialized and is still a NULL pointer when outside of a repository, thus causing the segfault. Make ref-filter more careful upfront while parsing the format string, and make it error out when encountering a format atom requiring object access when we are not in a repository. Also add a test to ensure that 'git ls-remote --sort' fails gracefully when executed outside of a repository. Reported-by: H.Merijn Brand Signed-off-by: SZEDER Gábor Signed-off-by: Junio C Hamano ---