Skip to content

Commit 4697eeb

Browse files
tohojonewren
authored andcommitted
Don't crash on multi-line config values
The parsing of the output of `git config --list` fails if any of the config values contain newlines. Fix this by using the --null parameter to `git config`, which is designed for this purpose. Add a simple test that causes the crash pre-patch. Signed-off-by: Toke Høiland-Jørgensen <[email protected]>
1 parent 0ee22eb commit 4697eeb

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

git-filter-repo

+3-3
Original file line numberDiff line numberDiff line change
@@ -1683,14 +1683,14 @@ class GitUtils(object):
16831683
def get_config_settings(repo_working_dir):
16841684
output = ''
16851685
try:
1686-
output = subproc.check_output('git config --list'.split(),
1686+
output = subproc.check_output('git config --list --null'.split(),
16871687
cwd=repo_working_dir)
16881688
except subprocess.CalledProcessError as e: # pragma: no cover
16891689
raise SystemExit('fatal: {}'.format(e))
16901690

16911691
# FIXME: Ignores multi-valued keys, just let them overwrite for now
1692-
return dict(line.split(b'=', maxsplit=1)
1693-
for line in output.strip().split(b"\n"))
1692+
return dict(item.split(b'\n', maxsplit=1)
1693+
for item in output.strip().split(b"\0") if item)
16941694

16951695
@staticmethod
16961696
def get_blob_sizes(quiet = False):

t/t9390-filter-repo-basics.sh

+11
Original file line numberDiff line numberDiff line change
@@ -895,4 +895,15 @@ test_expect_success 'origin refs without origin remote does not die' '
895895
)
896896
'
897897

898+
test_expect_success 'multi-line config value' '
899+
test_create_repo multiline_config &&
900+
(
901+
cd multiline_config &&
902+
903+
git config set test.test "test
904+
test" &&
905+
git filter-repo --force
906+
)
907+
'
908+
898909
test_done

0 commit comments

Comments
 (0)