Skip to content

Commit 68b813c

Browse files
committed
Merge pull request #2315 from ROGERSM94/fix-rebase
rebase-merges: improve --rebase-merges label generation
2 parents e3278e0 + 6262fef commit 68b813c

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

sequencer.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4646,8 +4646,18 @@ static int make_script_with_merges(struct pretty_print_context *pp,
46464646
else
46474647
strbuf_addbuf(&label, &oneline);
46484648

4649+
/*
4650+
* Sanitize labels by replacing non-alpha-numeric characters
4651+
* (including white-space ones) by dashes, as they might be
4652+
* illegal in file names (and hence in ref names).
4653+
*
4654+
* Note that we retain non-ASCII UTF-8 characters (identified
4655+
* via the most significant bit). They should be all acceptable
4656+
* in file names. We do not validate the UTF-8 here, that's not
4657+
* the job of this function.
4658+
*/
46494659
for (p1 = label.buf; *p1; p1++)
4650-
if (isspace(*p1))
4660+
if (!(*p1 & 0x80) && !isalnum(*p1))
46514661
*(char *)p1 = '-';
46524662

46534663
strbuf_reset(&buf);

t/t3430-rebase-merges.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,4 +462,10 @@ test_expect_success '--rebase-merges with strategies' '
462462
test_cmp expect G.t
463463
'
464464

465+
test_expect_success '--rebase-merges with commit that can generate bad characters for filename' '
466+
git checkout -b colon-in-label E &&
467+
git merge -m "colon: this should work" G &&
468+
git rebase --rebase-merges --force-rebase E
469+
'
470+
465471
test_done

0 commit comments

Comments
 (0)