summaryrefslogtreecommitdiff
path: root/sequencer.c
diff options
context:
space:
mode:
authorVictoria Dye <vdye@github.com>2022-11-07 17:47:52 (GMT)
committerTaylor Blau <me@ttaylorr.com>2022-11-07 19:16:45 (GMT)
commit44da9e08413ec6a579ce4238acf1937b333836fe (patch)
tree0095cf082e93db1e597e008e4df5f5693e2d1d38 /sequencer.c
parent3b08839926fcc7cc48cf4c759737c1a71af430c1 (diff)
downloadgit-44da9e08413ec6a579ce4238acf1937b333836fe.zip
git-44da9e08413ec6a579ce4238acf1937b333836fe.tar.gz
git-44da9e08413ec6a579ce4238acf1937b333836fe.tar.bz2
rebase --update-refs: avoid unintended ref deletion
In b3b1a21d1a5 (sequencer: rewrite update-refs as user edits todo list, 2022-07-19), the 'todo_list_filter_update_refs()' step was added to handle the removal of 'update-ref' lines from a 'rebase-todo'. Specifically, it removes potential ref updates from the "update refs state" if a ref does not have a corresponding 'update-ref' line. However, because 'write_update_refs_state()' will not update the state if the 'refs_to_oids' list was empty, removing *all* 'update-ref' lines will result in the state remaining unchanged from how it was initialized (with all refs' "after" OID being null). Then, when the ref update is applied, all refs will be updated to null and consequently deleted. To fix this, delete the 'update-refs' state file when 'refs_to_oids' is empty. Additionally, add a tests covering "all update-ref lines removed" cases. Reported-by: herr.kaste <herr.kaste@gmail.com> Helped-by: Phillip Wood <phillip.wood@dunelm.org.uk> Helped-by: Derrick Stolee <derrickstolee@github.com> Signed-off-by: Victoria Dye <vdye@github.com> Signed-off-by: Taylor Blau <me@ttaylorr.com>
Diffstat (limited to 'sequencer.c')
-rw-r--r--sequencer.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/sequencer.c b/sequencer.c
index e658df7..798a970 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -4130,11 +4130,14 @@ static int write_update_refs_state(struct string_list *refs_to_oids)
struct string_list_item *item;
char *path;
- if (!refs_to_oids->nr)
- return 0;
-
path = rebase_path_update_refs(the_repository->gitdir);
+ if (!refs_to_oids->nr) {
+ if (unlink(path) && errno != ENOENT)
+ result = error_errno(_("could not unlink: %s"), path);
+ goto cleanup;
+ }
+
if (safe_create_leading_directories(path)) {
result = error(_("unable to create leading directories of %s"),
path);