1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2025-09-30 19:22:08 +00:00

[v12.0/forgejo] fix: do better parsing of file modes (#9171)

**Backport: forgejo/forgejo#9161**

- No longer hardcode the file modes we expect, parse them as numbers and
do bitmask tricks that Git does so we allow a more variety of _weird_
file modes that can happen in the wild.
- Ref: https://codeberg.org/forgejo/forgejo/pulls/8900#issuecomment-6429175
- Resolves Codeberg/Community#2111

(cherry picked from commit 1cfd5e0b98)

Conflict resolution: trivial, choose the new code. Confliction arised
because v12 doesn't contain forgejo/forgejo#8900

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/9171
Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org>
Reviewed-by: Otto <otto@codeberg.org>
Co-authored-by: Gusted <postmaster@gusted.xyz>
Co-committed-by: Gusted <postmaster@gusted.xyz>
This commit is contained in:
Gusted 2025-09-05 00:23:30 +02:00 committed by Otto
parent ea5371e4cf
commit 019430c0d5
2 changed files with 69 additions and 31 deletions

View file

@ -101,3 +101,38 @@ func TestParseTreeEntriesInvalid(t *testing.T) {
require.Error(t, err)
assert.Empty(t, entries)
}
func TestParseMode(t *testing.T) {
ok := func(t *testing.T, mode string, entry EntryMode) {
t.Helper()
actualEntry, err := parseMode(mode)
require.NoError(t, err)
assert.Equal(t, entry, actualEntry)
}
fail := func(t *testing.T, mode string) {
t.Helper()
entry, err := parseMode(mode)
require.Error(t, err)
assert.Zero(t, entry)
}
ok(t, "100644", EntryModeBlob)
ok(t, "100755", EntryModeExec)
ok(t, "100754", EntryModeExec)
ok(t, "100700", EntryModeExec)
ok(t, "100744", EntryModeExec)
ok(t, "120000", EntryModeSymlink)
ok(t, "120644", EntryModeSymlink)
ok(t, "160000", EntryModeCommit)
ok(t, "160644", EntryModeCommit)
ok(t, "040000", EntryModeTree)
ok(t, "040755", EntryModeTree)
ok(t, "040775", EntryModeTree)
ok(t, "040754", EntryModeTree)
fail(t, "not-a-number")
fail(t, "000000")
fail(t, "400000")
fail(t, "111111")
}