Skip to content

Commit a2e5c79

Browse files
committed
Merge branch 'jk/filter-branch-use-of-sed-on-incomplete-line' into maint
"filter-branch" corrupted commit log message that ends with an incomplete line on platforms with some "sed" implementations that munge such a line. Work it around by avoiding to use "sed". * jk/filter-branch-use-of-sed-on-incomplete-line: filter-branch: avoid passing commit message through sed
2 parents 6fd5836 + df06201 commit a2e5c79

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

git-filter-branch.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,15 @@ while read commit parents; do
346346
die "parent filter failed: $filter_parent"
347347
fi
348348

349-
sed -e '1,/^$/d' <../commit | \
349+
{
350+
while read -r header_line && test -n "$header_line"
351+
do
352+
# skip header lines...
353+
:;
354+
done
355+
# and output the actual commit message
356+
cat
357+
} <../commit |
350358
eval "$filter_msg" > ../message ||
351359
die "msg filter failed: $filter_msg"
352360
workdir=$workdir @SHELL_PATH@ -c "$filter_commit" "git commit-tree" \

t/t7003-filter-branch.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,4 +394,14 @@ test_expect_success 'replace submodule revision' '
394394
test $orig_head != `git show-ref --hash --head HEAD`
395395
'
396396

397+
test_expect_success 'filter commit message without trailing newline' '
398+
git reset --hard original &&
399+
commit=$(printf "no newline" | git commit-tree HEAD^{tree}) &&
400+
git update-ref refs/heads/no-newline $commit &&
401+
git filter-branch -f refs/heads/no-newline &&
402+
echo $commit >expect &&
403+
git rev-parse refs/heads/no-newline >actual &&
404+
test_cmp expect actual
405+
'
406+
397407
test_done

0 commit comments

Comments
 (0)