Skip to content

Add configurable directory face mode for git status#1187

Open
rain-64 wants to merge 1 commit intoAlexander-Miller:masterfrom
rain-64:fix/directory-git-status-inheritance
Open

Add configurable directory face mode for git status#1187
rain-64 wants to merge 1 commit intoAlexander-Miller:masterfrom
rain-64:fix/directory-git-status-inheritance

Conversation

@rain-64
Copy link
Copy Markdown

@rain-64 rain-64 commented Apr 10, 2026

Summary

  • Parent directories of changed files were hardcoded to treemacs-git-modified-face regardless of children's actual git status (e.g., a directory with only staged/added files showed as "modified")
  • Introduces treemacs-git-directory-face-mode defcustom with three modes: modified (default, preserves existing behavior), severity (inherits highest-severity child status), and custom function
  • Adds treemacs-git-directory-face-severity-list defcustom for configuring the severity hierarchy

The three modes

modified (default) — directories always get treemacs-git-modified-face. This is the existing behavior; no user configuration changes are needed.

severity — resolves directory faces using a severity hierarchy. When all children share the same status, the directory inherits that status. When children have mixed statuses, the highest-severity status wins. Default hierarchy (highest to lowest):

Rank Status Rationale
1 Conflict (U) Blocks merges, must be resolved
2 Modified (M) Unstaged changes, dirty working tree
3 Untracked (?) Unknown to git, risk of being left out
4 Added (A) Already staged — deliberate user action
5 Renamed (R) Usually intentional, least concerning

The hierarchy is customizable via treemacs-git-directory-face-severity-list.

Custom function — a user-provided function that receives the git-info hash table for post-processing. The Python script resolves directory faces using severity logic as a baseline; the custom function then runs on the Emacs side to adjust the result (it operates on already-resolved severity faces, not raw status codes).

Files changed

  • src/elisp/treemacs-customization.el — new defcustom variables
  • src/elisp/treemacs-async.el — helper function, pass mode to Python, custom function post-processing
  • src/scripts/treemacs-git-status.py — two-pass directory resolution for severity mode
  • src/extra/treemacs-magit.el — pass mode arg, custom function post-processing

Backward compatibility

Default mode is modified, producing identical behavior to current code. No existing configuration breaks.

Test plan

  • modified mode: verify directories show treemacs-git-modified-face (unchanged behavior)
  • severity mode: git add new files only → parent directories show treemacs-git-added-face; add a modified file → directory switches to treemacs-git-modified-face
  • Custom function mode: provide a lambda that remaps faces, verify it takes effect
  • Magit integration: commit via magit, verify refresh uses correct mode

Parent directories of changed files were hardcoded to
treemacs-git-modified-face regardless of the children's actual git
status.  For example, a directory containing only staged/added files
would show as "modified" instead of "added".

Introduce treemacs-git-directory-face-mode defcustom with three modes:

- modified (default): preserves existing behavior — directories always
  get treemacs-git-modified-face.

- severity: uses a configurable hierarchy to pick the most severe child
  status.  The default hierarchy (highest to lowest) is:
    conflict (U) > modified (M) > untracked (?) > added (A) > renamed (R)
  Rationale: states requiring user action rank higher — conflicts block
  merges, modified files represent a dirty working tree, untracked files
  risk being left out of commits, while added/renamed files reflect
  deliberate user actions.  Customize via
  treemacs-git-directory-face-severity-list.

- custom function: a user-provided function that receives the git-info
  hash table for post-processing.  The Python script resolves directory
  faces using severity logic as a baseline; the custom function then runs
  on the Emacs side to adjust the result.  This means the function
  operates on already-resolved severity faces, not raw status codes.
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