commit 4d310c96ec77b8544747611c57338cd7c49c4753 from: Stefan Sperling via: Thomas Adam date: Thu May 15 16:08:55 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 - 90def070598b8850aabd6a6a621c4de2f1e31e74 commit + 4d310c96ec77b8544747611c57338cd7c49c4753 blob - 61a8dc9128abfd0e83897ca9b7f0b404ccc529aa blob + d220f0b3f3086bc1d22c96af2209ac3c42614327 --- got/got.c +++ got/got.c @@ -13151,7 +13151,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", @@ -13270,7 +13270,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; } @@ -13285,7 +13285,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; } @@ -13297,7 +13297,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 - 1446cf88c13ccf1495280a5f9e2ddb1321872824 blob + 7c025382cb49c81ae15a050a0ebb1d1718a764c8 --- lib/worktree.c +++ lib/worktree.c @@ -8277,7 +8277,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; @@ -8338,16 +8339,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; @@ -8356,22 +8347,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)