Enhance git metadata handling and improve change detection logic

- Introduced a new function `getGitMetadata` in `ApiContext` to fetch current git metadata, including new file IDs.
- Updated the `PatchTree.build` function to handle new file IDs, allowing for better differentiation between tracked and untracked files during patch processing.
- Modified the `git_changed_files` function to return both tracked and untracked files, improving accuracy in change detection.
- Enhanced the `App` component to debounce git metadata refreshes, ensuring the UI reflects the latest changes without unnecessary calls.

These changes aim to improve the integration with git and enhance the accuracy of change detection in the application.
This commit is contained in:
Joe 2026-03-01 07:10:14 -06:00
parent b8bd92d665
commit 640b2d3d97
7 changed files with 128 additions and 30 deletions

View file

@ -250,7 +250,7 @@ local PatchTree = {}
-- Builds a new tree from a patch and instanceMap
-- uses changeListHeaders in node.changeList
-- gitMetadata is optional: { changedIds: {string}, scriptCommittedHashes: {[string]: {string}} }
-- gitMetadata is optional: { changedIds: {string}, scriptCommittedHashes: {[string]: {string}}, newFileIds: {string}? }
function PatchTree.build(patch, instanceMap, changeListHeaders, gitMetadata)
Timer.start("PatchTree.build")
local clock = os.clock()
@ -267,6 +267,14 @@ function PatchTree.build(patch, instanceMap, changeListHeaders, gitMetadata)
end
end
local newFileIdSet = nil
if gitMetadata and gitMetadata.newFileIds then
newFileIdSet = {}
for _, id in gitMetadata.newFileIds do
newFileIdSet[id] = true
end
end
Timer.start("patch.updated")
for _, change in patch.updated do
clock = yieldIfNeeded(clock)
@ -518,8 +526,14 @@ function PatchTree.build(patch, instanceMap, changeListHeaders, gitMetadata)
table.insert(changeList, 1, changeListHeaders)
end
-- Add this node to tree
-- Default to nil (unselected) - user must explicitly choose Push/Pull/Skip
-- Truly new files (untracked in git) default to "push" (Atlas).
-- Tracked files appearing as additions are ambiguous (Studio may have
-- deleted them), so they remain nil for user review.
local defaultSelection = nil
if newFileIdSet and newFileIdSet[id] then
defaultSelection = "push"
end
tree:addNode(change.Parent, {
id = change.Id,
patchType = "Add",
@ -528,7 +542,7 @@ function PatchTree.build(patch, instanceMap, changeListHeaders, gitMetadata)
changeInfo = changeInfo,
changeList = changeList,
instance = instanceMap.fromIds[id],
defaultSelection = nil,
defaultSelection = defaultSelection,
})
end
Timer.stop()