git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Victoria Dye <vdye@github.com>
To: "herr.kaste" <herr.kaste@gmail.com>,
	"git@vger.kernel.org" <git@vger.kernel.org>,
	Derrick Stolee <derrickstolee@github.com>,
	Phillip Wood <phillip.wood123@gmail.com>,
	erik@cervined.in
Subject: Re: rebase -i --update-refs can lead to deletion of branches
Date: Thu, 3 Nov 2022 17:31:49 -0700	[thread overview]
Message-ID: <123628cc-1410-aaa0-0151-2dff35bd1855@github.com> (raw)
In-Reply-To: <CAFzd1+5F4zqQ1CNeY2xaaf0r__JmE4ECiBt5h5OdiJHbaE78VA@mail.gmail.com>

herr.kaste wrote:
> Now, I should just have not used `--update-refs` in the first place but anyway
> I decide late that I rather don't want to update "master" etc. and it should
> probably not delete the local refs.
> 

Agreed, this doesn't seem like desired behavior - the opposite of "update
the ref" isn't "delete the ref". ;)

The reason it's happening is because, when '--update-refs' is used, the
rebase starts by constructing a list of 'update_ref_record's for each of the
refs that *could* be updated. Each item in that list contains the
corresponding ref's "before" commit OID (i.e., what it currently points to)
and initializes the "after" OID to null. When an 'update-ref' line is
encountered in the 'rebase-todo', the "after" OID is updated with the
newly-rebased value. However, if an 'update-ref' line is removed from the
'rebase-todo', the "after" value is never updated. Then, when the rebase
finishes and the ref state data is applied, all of the entries with null
"after" OIDs are deleted.

The three options for a fix I can think of are:

  1. initialize the "after" OID to the value of "before".
  2. don't update refs with a null "after" OID.
  3. initialize the "after" OID to the value of "before", don't update the
     ref if "before" == "after".

I think #3 is the best option, since it avoids the unnecessary updates of #1
and leaves a cleaner path to a 'delete-ref' option (like the one proposed
elsewhere in the thread [1]) than #2. I'll send a patch shortly. 

[1] https://lore.kernel.org/git/CA+JQ7M-GbBTHZZ9xOLR=FitWFpUnkfuep9kSfNPxuSbJbKteGw@mail.gmail.com/

Thanks for reporting!
- Victoria


  parent reply	other threads:[~2022-11-04  0:32 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-20 17:01 rebase -i --update-refs can lead to deletion of branches herr.kaste
2022-10-20 20:49 ` Erik Cervin Edin
2022-11-03  9:32 ` Phillip Wood
2022-11-03 15:25   ` herr.kaste
2022-11-03 16:52     ` Erik Cervin Edin
2022-11-04  0:31 ` Victoria Dye [this message]
2022-11-04 10:40   ` Phillip Wood
2022-11-04 15:28     ` Victoria Dye
2022-11-04 16:57       ` [PATCH] rebase --update-refs: avoid unintended ref deletion Victoria Dye
2022-11-04 19:44         ` Taylor Blau
2022-11-04 20:17           ` Phillip Wood
2022-11-04 20:12         ` Phillip Wood
2022-11-07  2:39           ` Derrick Stolee
2022-11-07 17:47         ` [PATCH v2] " Victoria Dye
2022-11-07 19:17           ` Taylor Blau
2022-11-07 19:25           ` Derrick Stolee
2022-11-08  9:58           ` Phillip Wood

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=123628cc-1410-aaa0-0151-2dff35bd1855@github.com \
    --to=vdye@github.com \
    --cc=derrickstolee@github.com \
    --cc=erik@cervined.in \
    --cc=git@vger.kernel.org \
    --cc=herr.kaste@gmail.com \
    --cc=phillip.wood123@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).