From 00a914c3e4772bed8f713cbd1e2b409d57e93dc9 Mon Sep 17 00:00:00 2001 From: Elijah Newren Date: Thu, 11 Mar 2021 14:46:18 -0800 Subject: [PATCH 1/4] filter-repo: fix --use-mailmap --use-mailmap was defined as `--mailmap .mailmap` except that it would set args.mailmap to ".mailmap" rather than b".mailmap" (in other words, it accidentally set it to a string rather than a bytestring). Since the --mailmap parameter is always passed as a bytestring, we ran into errors with calling unknown functions due to the type mismatch. Signed-off-by: Elijah Newren --- git-filter-repo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-filter-repo b/git-filter-repo index 10401e45..8fc4745b 100755 --- a/git-filter-repo +++ b/git-filter-repo @@ -1862,7 +1862,7 @@ EXAMPLES "part of git history, historical versions of the file will " "be ignored; only the current contents are consulted.")) people.add_argument('--use-mailmap', dest='mailmap', - action='store_const', const='.mailmap', + action='store_const', const=b'.mailmap', help=_("Same as: '--mailmap .mailmap' ")) parents = parser.add_argument_group(title=_("Parent rewriting")) From 8dc74b1633a590216ff00632544befac58cd9d5d Mon Sep 17 00:00:00 2001 From: Lassi Kortela Date: Fri, 12 Mar 2021 15:30:18 +0200 Subject: [PATCH 2/4] Fix bug in --path-rename argument without colon The --path-rename flag expected an argument with a colon character (':') in it, which it assumed without checking. If the user gave an argument with no colon in it, this backtrace would be shown: File "/usr/local/bin/git-filter-repo", line 1626, in __call__ if values[0] and values[1] and not ( IndexError: list index out of range Add a real error message in place of the backtrace. Also check that there's exactly one colon; show an error message if there's more than one, as that syntax has no interpretation that is obviously the right one. Signed-off-by: Lassi Kortela --- git-filter-repo | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/git-filter-repo b/git-filter-repo index 10401e45..8dcdad42 100755 --- a/git-filter-repo +++ b/git-filter-repo @@ -1622,7 +1622,10 @@ class FilteringOptions(object): if suffix.startswith('rename'): mod_type = 'rename' match_type = option_string[len('--path-rename-'):] or 'match' - values = values.split(b':', 1) + values = values.split(b':') + if len(values) != 2: + raise SystemExit(_("Error: --path-rename expects one colon in its" + " argument: .")) if values[0] and values[1] and not ( values[0].endswith(b'/') == values[1].endswith(b'/')): raise SystemExit(_("Error: With --path-rename, if OLD_NAME and " From 3ebe845857d7f8ea810468f1782a39ddfae45baf Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Tue, 30 Mar 2021 20:57:23 +0200 Subject: [PATCH 3/4] Fix the Python path on Windows On Windows, we want to run with a native Python, i.e. the separator is a semicolon, and the paths should be Windows paths (although they're allowed to have forward slashes instead of backslashes). Since we're most likely running this in an MSYS2 Bash, allow for `$TEST_DIRECTORY` to pretend to be a Unix path, and translate it via `cygpath` into a Windows path. Signed-off-by: Johannes Schindelin --- t/t9391-filter-repo-lib-usage.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/t/t9391-filter-repo-lib-usage.sh b/t/t9391-filter-repo-lib-usage.sh index 761f43a1..059b6d52 100755 --- a/t/t9391-filter-repo-lib-usage.sh +++ b/t/t9391-filter-repo-lib-usage.sh @@ -4,7 +4,14 @@ test_description='Usage of git-filter-repo as a library' . ./test-lib.sh # for git_filter_repo.py import -export PYTHONPATH=$(dirname $TEST_DIRECTORY):$PYTHONPATH +case "$(uname -s)" in +MINGW*|MSYS) + export PYTHONPATH=$(cygpath -am $TEST_DIRECTORY/..)\;$PYTHONPATH + ;; +*) + export PYTHONPATH=$(dirname $TEST_DIRECTORY):$PYTHONPATH + ;; +esac # Avoid writing git_filter_repo.pyc file export PYTHONDONTWRITEBYTECODE=1 export CONTRIB_DIR=$TEST_DIRECTORY/../contrib/filter-repo-demos From 18a137cce5e38e17f4280947c84c83558118a0ea Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Tue, 30 Mar 2021 22:47:26 +0200 Subject: [PATCH 4/4] lint-history: do decode bytes This fixes the "TypeError: a bytes-like object is required, not 'str'" problem on Windows, letting t9391 pass. Signed-off-by: Johannes Schindelin --- contrib/filter-repo-demos/lint-history | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/filter-repo-demos/lint-history b/contrib/filter-repo-demos/lint-history index 4ec34ed9..5b45b7e3 100755 --- a/contrib/filter-repo-demos/lint-history +++ b/contrib/filter-repo-demos/lint-history @@ -114,7 +114,7 @@ def lint_with_real_filenames(commit, metadata): f.write(contents_plus_newline[:-1]) # Lint the file - subprocess.check_call(lint_args.command + [filename]) + subprocess.check_call(lint_args.command + [filename.decode('utf-8')]) # Get the new contents with open(filename, "rb") as f: