Skip to content

Fix tree object modes and ordering#17

Open
one-pyy wants to merge 1 commit into
GitJournal:masterfrom
one-pyy:fix-tree-object-modes-and-order
Open

Fix tree object modes and ordering#17
one-pyy wants to merge 1 commit into
GitJournal:masterfrom
one-pyy:fix-tree-object-modes-and-order

Conversation

@one-pyy

@one-pyy one-pyy commented Jul 16, 2026

Copy link
Copy Markdown

Summary

Fix Git tree objects generated from the worktree so they pass remote fsck checks:

  • normalize filesystem modes to Git tree modes before writing index entries
  • sort GitTree entries using Git tree ordering before hashing/serializing
  • add regression tests for both cases

Motivation

GitJournal mobile sync can create commits locally with malformed tree objects. When those objects are pushed to GitHub, GitHub rejects the pack with errors such as:

badFilemode: contains bad file modes
treeNotSorted: not properly sorted
fatal: fsck error in packed object

This showed up in GitJournal as malformed unpack status: 001dunpack index-pack failed. I added more detail to the related GitJournal issue here:

GitJournal/GitJournal#963 (comment)

Details

GitIndexEntry.fromFS previously used FileStat.mode directly. On platforms such as Android/Linux this can include filesystem file type and permission bits that are not valid Git tree modes. This PR maps filesystem modes to 100644 or 100755 before they are written to the index.

GitTree.create now sorts entries before computing the tree hash. Directories are compared as name/, matching Git tree ordering.

Tests

dart test test/index_test.dart test/plumbing/objects/tree_test.dart --reporter compact
dart analyze

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant