commit e03756bbbc44041d2e02bc6668ba8f9129053400 from: Stefan Sperling date: Sat May 03 14:33:41 2025 UTC fix unrelated errors being reported if a histedit operation is aborted This avoids errors such as "object not found" or "reference not found" when exiting the histedit script editor without making any changes to the script. got_worktree_histedit_abort() was filling up error.c error buffers with unrelated errors that were simply being ignored. I now see the expected "no changes made to histedit script" error. Issue reported by ninjin on IRC commit - fcd4ab70e8a9040434264a073cde99eac4999186 commit + e03756bbbc44041d2e02bc6668ba8f9129053400 blob - 7f05e93a2d2a8e26f43477b49ca6c54875bf2ddf blob + 4e9891df54e61ef79c78c24c78c772e6664da73a --- got/got.c +++ got/got.c @@ -13153,7 +13153,7 @@ cmd_histedit(int argc, char *argv[]) printf("Switching work tree to %s\n", got_ref_get_symref_target(branch)); error = got_worktree_histedit_abort(worktree, fileindex, repo, - branch, base_commit_id, abort_progress, &upa); + branch, base_commit_id, abort_progress, &upa, 1); if (error) goto done; printf("Histedit of %s aborted\n", @@ -13272,7 +13272,7 @@ cmd_histedit(int argc, char *argv[]) if (error) { got_worktree_histedit_abort(worktree, fileindex, repo, branch, base_commit_id, - abort_progress, &upa); + abort_progress, &upa, 0); print_merge_progress_stats(&upa); goto done; } @@ -13287,7 +13287,7 @@ cmd_histedit(int argc, char *argv[]) if (error) { got_worktree_histedit_abort(worktree, fileindex, repo, branch, base_commit_id, - abort_progress, &upa); + abort_progress, &upa, 0); print_merge_progress_stats(&upa); goto done; } @@ -13299,7 +13299,7 @@ cmd_histedit(int argc, char *argv[]) if (error) { got_worktree_histedit_abort(worktree, fileindex, repo, branch, base_commit_id, - abort_progress, &upa); + abort_progress, &upa, 0); print_merge_progress_stats(&upa); goto done; } blob - c3fa46bbe00087fcbd8a9b114bedd1cabed012d6 blob + 83894a63327d718f09bcb4236d42ccb4c872da6b --- include/got_worktree.h +++ include/got_worktree.h @@ -456,7 +456,7 @@ const struct got_error *got_worktree_histedit_complete */ const struct got_error *got_worktree_histedit_abort(struct got_worktree *, struct got_fileindex *, struct got_repository *, struct got_reference *, - struct got_object_id *, got_worktree_checkout_cb, void *); + struct got_object_id *, got_worktree_checkout_cb, void *, int); /* Get the path to this work tree's histedit script file. */ const struct got_error *got_worktree_get_histedit_script_path(char **, blob - 347dee89931812371ac672ad6fde03759da76d4f blob + 8dde07e115ca4bfbb8f8c8498d793847a4343c27 --- lib/worktree.c +++ lib/worktree.c @@ -8280,7 +8280,8 @@ const struct got_error * got_worktree_histedit_abort(struct got_worktree *worktree, struct got_fileindex *fileindex, struct got_repository *repo, struct got_reference *branch, struct got_object_id *base_commit_id, - got_worktree_checkout_cb progress_cb, void *progress_arg) + got_worktree_checkout_cb progress_cb, void *progress_arg, + int restore_working_files) { const struct got_error *err, *unlockerr, *sync_err; struct got_reference *resolved = NULL; @@ -8341,16 +8342,6 @@ got_worktree_histedit_abort(struct got_worktree *workt if (err) goto done; - err = got_object_open_as_commit(&commit, repo, - worktree->base_commit_id); - if (err) - goto done; - - err = got_object_id_by_path(&tree_id, repo, commit, - worktree->path_prefix); - if (err) - goto done; - err = delete_histedit_refs(worktree, repo); if (err) goto done; @@ -8359,22 +8350,34 @@ got_worktree_histedit_abort(struct got_worktree *workt if (err) goto done; - rfa.worktree = worktree; - rfa.fileindex = fileindex; - rfa.progress_cb = progress_cb; - rfa.progress_arg = progress_arg; - rfa.patch_cb = NULL; - rfa.patch_arg = NULL; - rfa.repo = repo; - rfa.unlink_added_files = 1; - rfa.added_files_to_unlink = &added_paths; - err = worktree_status(worktree, "", fileindex, repo, - revert_file, &rfa, NULL, NULL, 1, 0); - if (err) - goto sync; + if (restore_working_files) { + err = got_object_open_as_commit(&commit, repo, + worktree->base_commit_id); + if (err) + goto done; - err = checkout_files(worktree, fileindex, "", tree_id, NULL, - repo, progress_cb, progress_arg, NULL, NULL); + err = got_object_id_by_path(&tree_id, repo, commit, + worktree->path_prefix); + if (err) + goto done; + + rfa.worktree = worktree; + rfa.fileindex = fileindex; + rfa.progress_cb = progress_cb; + rfa.progress_arg = progress_arg; + rfa.patch_cb = NULL; + rfa.patch_arg = NULL; + rfa.repo = repo; + rfa.unlink_added_files = 1; + rfa.added_files_to_unlink = &added_paths; + err = worktree_status(worktree, "", fileindex, repo, + revert_file, &rfa, NULL, NULL, 1, 0); + if (err) + goto sync; + + err = checkout_files(worktree, fileindex, "", tree_id, NULL, + repo, progress_cb, progress_arg, NULL, NULL); + } sync: sync_err = sync_fileindex(fileindex, fileindex_path); if (sync_err && err == NULL)