mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-23 22:25:26 +00:00
Add --git-since option to rojo serve
- Add new GitFilter struct for tracking files changed since a Git reference - Only sync changed (added/deleted/modified) files to Roblox Studio - Files remain acknowledged once synced, even if content is reverted - Add enhanced logging for debugging sync issues - Force acknowledge project structure to prevent 'Cannot sync a model as a place' errors
This commit is contained in:
@@ -61,6 +61,10 @@ pub use self::{
|
||||
/// This will inspect the path and find the appropriate middleware for it,
|
||||
/// taking user-written rules into account. Then, it will attempt to convert
|
||||
/// the path into an InstanceSnapshot using that middleware.
|
||||
///
|
||||
/// If a git filter is active in the context and the path is not acknowledged
|
||||
/// (i.e., the file hasn't changed since the base git reference), this function
|
||||
/// returns `Ok(None)` to skip syncing that file.
|
||||
#[profiling::function]
|
||||
pub fn snapshot_from_vfs(
|
||||
context: &InstanceContext,
|
||||
@@ -72,6 +76,16 @@ pub fn snapshot_from_vfs(
|
||||
None => return Ok(None),
|
||||
};
|
||||
|
||||
// Check if this path is acknowledged by the git filter.
|
||||
// If not, skip this path entirely.
|
||||
if !context.is_path_acknowledged(path) {
|
||||
log::trace!(
|
||||
"Skipping path {} (not acknowledged by git filter)",
|
||||
path.display()
|
||||
);
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
if meta.is_dir() {
|
||||
let (middleware, dir_name, init_path) = get_dir_middleware(vfs, path)?;
|
||||
// TODO: Support user defined init paths
|
||||
@@ -213,6 +227,10 @@ pub enum Middleware {
|
||||
impl Middleware {
|
||||
/// Creates a snapshot for the given path from the Middleware with
|
||||
/// the provided name.
|
||||
///
|
||||
/// When a git filter is active in the context, `ignore_unknown_instances`
|
||||
/// will be set to `true` on all generated snapshots to preserve descendants
|
||||
/// in Studio that are not tracked by Rojo.
|
||||
fn snapshot(
|
||||
&self,
|
||||
context: &InstanceContext,
|
||||
@@ -262,6 +280,14 @@ impl Middleware {
|
||||
};
|
||||
if let Ok(Some(ref mut snapshot)) = output {
|
||||
snapshot.metadata.middleware = Some(*self);
|
||||
|
||||
// When git filter is active, force ignore_unknown_instances to true
|
||||
// so that we don't delete children in Studio that aren't tracked.
|
||||
if context.has_git_filter() {
|
||||
snapshot.metadata.ignore_unknown_instances = true;
|
||||
// Also apply this recursively to all children
|
||||
set_ignore_unknown_instances_recursive(&mut snapshot.children);
|
||||
}
|
||||
}
|
||||
output
|
||||
}
|
||||
@@ -365,6 +391,16 @@ impl Middleware {
|
||||
}
|
||||
}
|
||||
|
||||
/// Recursively sets `ignore_unknown_instances` to `true` on all children.
|
||||
/// This is used when git filter is active to ensure we don't delete
|
||||
/// children in Studio that aren't tracked by Rojo.
|
||||
fn set_ignore_unknown_instances_recursive(children: &mut [InstanceSnapshot]) {
|
||||
for child in children {
|
||||
child.metadata.ignore_unknown_instances = true;
|
||||
set_ignore_unknown_instances_recursive(&mut child.children);
|
||||
}
|
||||
}
|
||||
|
||||
/// A helper for easily defining a SyncRule. Arguments are passed literally
|
||||
/// to this macro in the order `include`, `middleware`, `suffix`,
|
||||
/// and `exclude`. Both `suffix` and `exclude` are optional.
|
||||
|
||||
@@ -192,6 +192,17 @@ pub fn snapshot_project_node(
|
||||
}
|
||||
|
||||
(_, None, _, Some(PathNode::Required(path))) => {
|
||||
// If git filter is active and the path was filtered out, treat it
|
||||
// as if the path was optional and skip this node.
|
||||
if context.has_git_filter() {
|
||||
log::trace!(
|
||||
"Skipping project node '{}' because its path was filtered by git filter: {}",
|
||||
instance_name,
|
||||
path.display()
|
||||
);
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
anyhow::bail!(
|
||||
"Rojo project referred to a file using $path that could not be turned into a Roblox Instance by Rojo.\n\
|
||||
Check that the file exists and is a file type known by Rojo.\n\
|
||||
@@ -282,7 +293,12 @@ pub fn snapshot_project_node(
|
||||
// If the user didn't specify it AND $path was not specified (meaning
|
||||
// there's no existing value we'd be stepping on from a project file or meta
|
||||
// file), set it to true.
|
||||
if let Some(ignore) = node.ignore_unknown_instances {
|
||||
//
|
||||
// When git filter is active, always set to true to preserve descendants
|
||||
// in Studio that are not tracked by Rojo.
|
||||
if context.has_git_filter() {
|
||||
metadata.ignore_unknown_instances = true;
|
||||
} else if let Some(ignore) = node.ignore_unknown_instances {
|
||||
metadata.ignore_unknown_instances = ignore;
|
||||
} else if node.path.is_none() {
|
||||
// TODO: Introduce a strict mode where $ignoreUnknownInstances is never
|
||||
|
||||
Reference in New Issue
Block a user