Skip to content
This repository was archived by the owner on Oct 19, 2026. It is now read-only.

Commit 2d05717

Browse files
authored
fix(create-entry): normalize create paths for tree match (#2050)
* fix(create-entry): normalize create paths for tree match Signed-off-by: jackieismpc <jackieismpc@gmail.com> * style(web): fix prettier format in NewCodeView Signed-off-by: jackieismpc <jackieismpc@gmail.com> * style(web): format NewCodeView for prettier Signed-off-by: jackieismpc <jackieismpc@gmail.com> --------- Signed-off-by: jackieismpc <jackieismpc@gmail.com>
1 parent 39adde6 commit 2d05717

3 files changed

Lines changed: 82 additions & 2 deletions

File tree

‎ceres/src/api_service/mono_api_service.rs‎

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,9 +309,14 @@ impl MonoServiceLogic {
309309

310310
loop {
311311
let clean_path = MonoServiceLogic::clean_path_str(&path_str);
312+
let ref_path = if clean_path == "/" || clean_path.starts_with('/') {
313+
clean_path
314+
} else {
315+
format!("/{clean_path}")
316+
};
312317

313318
ref_updates.push(RefUpdate {
314-
path: clean_path,
319+
path: ref_path,
315320
tree_id: updated_tree_hash,
316321
});
317322

@@ -4020,6 +4025,30 @@ mod test {
40204025
assert!(paths.contains(&"/test"));
40214026
}
40224027

4028+
#[test]
4029+
fn test_build_result_by_chain_normalizes_relative_paths_for_ref_updates() {
4030+
let old_hash = ObjectHash::from_str("1111111111111111111111111111111111111111").unwrap();
4031+
let updated_child_hash =
4032+
ObjectHash::from_str("2222222222222222222222222222222222222222").unwrap();
4033+
let item = TreeItem::new(TreeItemMode::Tree, old_hash, "src".to_string());
4034+
let tree = Tree::from_tree_items(vec![item]).expect("tree should build");
4035+
let update_chain = vec![Arc::new(tree)];
4036+
4037+
let result = MonoServiceLogic::build_result_by_chain(
4038+
PathBuf::from("project/buck2_test/src"),
4039+
update_chain,
4040+
updated_child_hash,
4041+
)
4042+
.expect("build_result_by_chain should succeed");
4043+
4044+
let paths: Vec<&str> = result.ref_updates.iter().map(|r| r.path.as_str()).collect();
4045+
assert!(paths.contains(&"/project/buck2_test/src"));
4046+
assert!(paths.contains(&"/project/buck2_test"));
4047+
4048+
let selected = MonoApiService::ref_update_tree_id_for_path(&result, "/project/buck2_test");
4049+
assert!(selected.is_some());
4050+
}
4051+
40234052
#[tokio::test]
40244053
async fn test_process_ref_updates_logic() {
40254054
let ref_update = RefUpdate {

‎ceres/src/build_trigger/changes_calculator.rs‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,56 @@ mod tests {
353353
);
354354
}
355355

356+
#[test]
357+
fn test_build_changes_keeps_added_paths_for_create_entry_variants() {
358+
let changes = build_changes_for_repo(
359+
"/project/buck2_test",
360+
vec![
361+
ClDiffFile::New(
362+
PathBuf::from("/project/buck2_test/src/new_file_abs.rs"),
363+
ObjectHash::from_str("7777777777777777777777777777777777777777").unwrap(),
364+
),
365+
ClDiffFile::New(
366+
PathBuf::from("project/buck2_test/src/new_file_prefixed.rs"),
367+
ObjectHash::from_str("8888888888888888888888888888888888888888").unwrap(),
368+
),
369+
ClDiffFile::New(
370+
PathBuf::from("src/new_file_relative.rs"),
371+
ObjectHash::from_str("9999999999999999999999999999999999999999").unwrap(),
372+
),
373+
],
374+
)
375+
.unwrap();
376+
377+
assert_eq!(
378+
changes,
379+
vec![
380+
Status::Added(ProjectRelativePath::new("src/new_file_abs.rs")),
381+
Status::Added(ProjectRelativePath::new("src/new_file_prefixed.rs")),
382+
Status::Added(ProjectRelativePath::new("src/new_file_relative.rs")),
383+
]
384+
);
385+
}
386+
387+
#[test]
388+
fn test_build_changes_keeps_added_gitkeep_for_new_directory() {
389+
let changes = build_changes_for_repo(
390+
"/project/buck2_test",
391+
vec![ClDiffFile::New(
392+
PathBuf::from("project/buck2_test/src/new_dir/.gitkeep"),
393+
ObjectHash::from_str("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa").unwrap(),
394+
)],
395+
)
396+
.unwrap();
397+
398+
assert_eq!(
399+
changes,
400+
vec![Status::Added(ProjectRelativePath::new(
401+
"src/new_dir/.gitkeep"
402+
))]
403+
);
404+
}
405+
356406
#[test]
357407
fn test_detect_single_level_prefixed_candidate_returns_unique_match() {
358408
let tempdir = TempDir::new().expect("create tempdir");

‎moon/apps/web/components/CodeView/NewCodeView/NewCodeView.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,15 @@ const NewCodeView = ({ currentPath = '', onClose, defaultType = 'file' }: NewCod
3434
const lastSlashIndex = fullPath.lastIndexOf('/')
3535

3636
const parentPath = lastSlashIndex > 0 ? fullPath.substring(0, lastSlashIndex) : lastSlashIndex === 0 ? '/' : ''
37+
const normalizedParentPath = parentPath === '' ? '/' : parentPath.startsWith('/') ? parentPath : `/${parentPath}`
3738

3839
// Use explicit name if provided, otherwise extract from path
3940
const fileName = name || (lastSlashIndex >= 0 ? fullPath.substring(lastSlashIndex + 1) : fullPath)
4041

4142
createEntryHook.mutate(
4243
{
4344
name: fileName,
44-
path: parentPath,
45+
path: normalizedParentPath,
4546
is_directory: fileType === 'folder',
4647
content: fileType === 'file' ? content : '',
4748
author_email: currentUser?.email,

0 commit comments

Comments
 (0)