git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Felipe Contreras <felipe.contreras@gmail.com>
To: git@vger.kernel.org
Cc: "Antoine Beaupré" <anarcat@debian.org>,
	"Phillip Wood" <phillip.wood@dunelm.org.uk>,
	"Felipe Contreras" <felipe.contreras@gmail.com>
Subject: [RFC PATCH 3/3] rebase: update branch tail after rebasing
Date: Fri, 10 Mar 2023 15:45:15 -0600	[thread overview]
Message-ID: <20230310214515.39154-4-felipe.contreras@gmail.com> (raw)
In-Reply-To: <20230310214515.39154-1-felipe.contreras@gmail.com>

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 builtin/rebase.c          | 15 +++++++++++++++
 t/t1514-rev-parse-tail.sh | 10 ++++++++++
 2 files changed, 25 insertions(+)

diff --git a/builtin/rebase.c b/builtin/rebase.c
index 6635f10d52..19cfb0d0e4 100644
--- a/builtin/rebase.c
+++ b/builtin/rebase.c
@@ -252,6 +252,16 @@ static int init_basic_state(struct replay_opts *opts, const char *head_name,
 	return write_basic_state(opts, head_name, onto, orig_head);
 }
 
+static void update_tail(struct rebase_options *opts)
+{
+	const char *shortname = NULL;
+	struct strbuf ref = STRBUF_INIT;
+	skip_prefix(opts->head_name, "refs/heads/", &shortname);
+	strbuf_addf(&ref, "refs/tails/%s", shortname);
+	update_ref(NULL, ref.buf, &opts->onto->object.oid, NULL, 0, UPDATE_REFS_DIE_ON_ERR);
+	strbuf_release(&ref);
+}
+
 static int do_interactive_rebase(struct rebase_options *opts, unsigned flags)
 {
 	int ret = -1;
@@ -294,6 +304,9 @@ static int do_interactive_rebase(struct rebase_options *opts, unsigned flags)
 			shortrevisions, opts->onto_name, opts->onto,
 			&opts->orig_head->object.oid, &opts->exec,
 			opts->autosquash, opts->update_refs, &todo_list);
+
+		if (!ret)
+			update_tail(opts);
 	}
 
 cleanup:
@@ -564,6 +577,8 @@ static int finish_rebase(struct rebase_options *opts)
 		strbuf_release(&dir);
 	}
 
+	update_tail(opts);
+
 	return ret;
 }
 
diff --git a/t/t1514-rev-parse-tail.sh b/t/t1514-rev-parse-tail.sh
index 6024b4276c..7b3482de55 100755
--- a/t/t1514-rev-parse-tail.sh
+++ b/t/t1514-rev-parse-tail.sh
@@ -26,4 +26,14 @@ test_expect_success 'test @{tail}' '
 	test_cmp expect actual
 '
 
+test_expect_success 'test rebase tail update' '
+	git checkout -b next master &&
+	echo three > content &&
+	git commit -a -m three &&
+	git rebase --onto next test@{tail} test &&
+	git rev-parse test@{tail} > actual &&
+	git rev-parse next > expect &&
+	test_cmp expect actual
+'
+
 test_done
-- 
2.40.0.rc2.1.gf652911b76.dirty


  parent reply	other threads:[~2023-03-10 21:49 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-10 21:45 [RFC PATCH 0/3] Support for tail (branch point) experiment Felipe Contreras
2023-03-10 21:45 ` [RFC PATCH 1/3] branch: add new 'tail' concept Felipe Contreras
2023-03-10 21:45 ` [RFC PATCH 2/3] sha1-name: add @{tail} helpers Felipe Contreras
2023-03-10 21:45 ` Felipe Contreras [this message]
2023-03-11  0:04 ` [RFC PATCH 0/3] Support for tail (branch point) experiment Junio C Hamano
2023-03-11  3:26   ` Felipe Contreras

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=20230310214515.39154-4-felipe.contreras@gmail.com \
    --to=felipe.contreras@gmail.com \
    --cc=anarcat@debian.org \
    --cc=git@vger.kernel.org \
    --cc=phillip.wood@dunelm.org.uk \
    /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).