Sign in

Search issue titles and bodies, change requests and comments. Private repositories you cannot read are not included.

vole
Site
Clone

Read only, no credentials:

https://rodent.software/vole.git

Write over SSH with a registered key:

git clone ssh://git@rodent.software/vole.git

Self-hosted forge that lives in your Git repo.

Enforce path gates on the names git stores

617cda58a98595daf8a0a42758d383f8e40c3fd2 · Keenan Nemetz · 13d ago · parent 87bab8e1

Enforce path gates on the names git stores

DiffStatusPaths parsed git diff-tree's tab-separated output. Git C-quotes
non-ASCII, tab, newline, quote, and space-edged names by default, so the map
was keyed by the escaped spelling. A lock on Content/Héros/Épée.uasset was
stored, listed, and never matched against a push; protected scopes, CI path
filters, and the index refresh read the same map.

Use -z and NUL records so the key is always the path git stores. Pass
--no-renames so a rename reports its source as a deletion and its destination
as an addition: a lock or protected path on either side stays visible.

The old tests neutralized the problem with core.quotePath=false. The new tests
use the filenames that trigger quoting and tab-separated ambiguity.

core/git/git.go +17−11

@@ -1003,7 +1003,17 @@ func (r *Repo) DiffStatus(old, new string) (map[string]string, error) {
1003 1003 // refresh only cares about the subtrees it indexes, so a range that also carries
1004 1004 // unrelated changes does not scan them.
1005 1005 func (r *Repo) DiffStatusPaths(old, new string, pathspecs ...string) (map[string]string, error) {
1006 args := []string{"diff-tree", "-r", "--no-commit-id", "--name-status", old, new}
1006 // -z is not an optimization: without it git C-quotes any path with a
1007 // non-ASCII byte, a tab, a newline or a quote, and the map would be keyed by
1008 // the quoted spelling. A lock on `Héros.uasset` would never match a push of
1009 // the file itself. NUL-delimited records also leave leading and trailing
1010 // spaces in a filename alone.
1011 //
1012 // Rename detection is off on purpose: a rename then reports the source as a
1013 // deletion and the destination as an addition, so a lock or protected path on
1014 // either side is seen. Detecting the rename would hide the source path, which
1015 // is exactly the path a lock is most likely to guard.
1016 args := []string{"diff-tree", "-r", "--no-commit-id", "--name-status", "-z", "--no-renames", old, new}
1007 1017 if len(pathspecs) > 0 {
1008 1018 args = append(args, "--")
1009 1019 args = append(args, pathspecs...)
@@ -1013,17 +1023,13 @@ func (r *Repo) DiffStatusPaths(old, new string, pathspecs ...string) (map[string
1013 1023 return nil, fmt.Errorf("diff-tree %s..%s: %w: %s", old, new, err, errs)
1014 1024 }
1015 1025 status := map[string]string{}
1016 for _, line := range strings.Split(strings.TrimSpace(string(out)), "\n") {
1017 if line == "" {
1018 continue
1019 }
1020 parts := strings.SplitN(line, "\t", 2)
1021 if len(parts) != 2 {
1022 continue
1026 records := strings.Split(string(out), "\x00")
1027 for i := 0; i+1 < len(records); i += 2 {
1028 code := records[i]
1029 if code == "" {
1030 break
1023 1031 }
1024 // Rename and copy entries carry two paths; the destination is the one that
1025 // matters for a write check.
1026 status[strings.TrimSpace(parts[1])] = strings.TrimSpace(parts[0])[:1]
1032 status[records[i+1]] = code[:1]
1027 1033 }
1028 1034 return status, nil
1029 1035 }