Skip to content

Commit

Permalink
clean-ignore: support utf-8 filenames found in .gitignore
Browse files Browse the repository at this point in the history
If someone names files with emoji, and puts those files in their
.gitignore, ensure we correctly parse and handle those files.  Do
so by passing -z to `git check-ignore`, so that we don't have to
worry about weird quoting of special characters.

Reported-by: Yufan Lou (@louy2 on github)
Reported-by: Martin Ranieri (@maffinyep on github)
Reported-by: Aral Balkan <[email protected]>
Signed-off-by: Elijah Newren <[email protected]>
  • Loading branch information
newren committed Jul 3, 2024
1 parent 5c54a53 commit 2800bcc
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 5 deletions.
10 changes: 5 additions & 5 deletions contrib/filter-repo-demos/clean-ignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class CheckIgnores:
self.ignored = set()
self.okay = set()

cmd = 'git check-ignore --stdin --verbose --non-matching --no-index'
cmd = 'git check-ignore --stdin --verbose --non-matching --no-index -z'
self.check_ignore_process = subprocess.Popen(cmd.split(),
stdin=subprocess.PIPE,
stdout=subprocess.PIPE)
Expand All @@ -46,13 +46,13 @@ class CheckIgnores:
elif name in self.okay:
continue
else:
self.check_ignore_process.stdin.write(name+b'\n')
self.check_ignore_process.stdin.write(name+b'\0')
self.check_ignore_process.stdin.flush()
result = self.check_ignore_process.stdout.readline().rstrip(b'\n')
(rest, pathname) = result.split(b"\t")
result = os.read(self.check_ignore_process.stdout.fileno(), 65535).rstrip(b'\0')
(source, linenum, pattern, pathname) = result.split(b"\0")
if name != pathname:
raise SystemExit("Error: Passed {} but got {}".format(name, pathname))
if rest == b'::':
if not source and not linenum and not pattern:
self.okay.add(name)
else:
self.ignored.add(name)
Expand Down
15 changes: 15 additions & 0 deletions t/t9391-filter-repo-lib-usage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ esac
export PYTHONDONTWRITEBYTECODE=1
export CONTRIB_DIR=$TEST_DIRECTORY/../contrib/filter-repo-demos

DATA="$TEST_DIRECTORY/t9391"

setup()
{
git init $1 &&
Expand Down Expand Up @@ -203,4 +205,17 @@ test_expect_success 'lint-history' '
)
'

test_expect_success 'clean-ignore with emoji in filenames' '
test_create_repo clean-ignore &&
(
cd clean-ignore &&
git fast-import --quiet <$DATA/emoji-repo &&
git reset --hard &&
$CONTRIB_DIR/clean-ignore --force &&
printf ".gitignore\nfilename\n" >expect &&
git ls-files >actual &&
test_cmp expect actual
)
'

test_done
29 changes: 29 additions & 0 deletions t/t9391/emoji-repo
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
feature done
blob
mark :1
data 8
initial

blob
mark :2
data 5
lock

blob
mark :3
data 11
*.bak
🔒

reset refs/heads/master
commit refs/heads/master
mark :4
author Little O. Me <[email protected]> 1535228562 -0700
committer Little O. Me <[email protected]> 1535228562 -0700
data 10
My commit
M 100644 :1 filename
M 100644 :2 🔒
M 100644 :3 .gitignore

done

0 comments on commit 2800bcc

Please sign in to comment.