git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[RFC PATCH 3/3] rebase: update branch tail after rebasing

From
Felipe Contreras <felipe.contreras@gmail.com>
Date
Mar 10, 2023, 21:45 UTC
Message-ID
<20230310214515.39154-4-felipe.contreras@gmail.com>
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
Previous: Felipe ContrerasNext: Junio C Hamano
Message 4 of 6 in “Support for tail (branch point) experiment”
  1. 0/3 Support for tail (branch point) experimentFelipe Contreras, Mar 10, 2023
  2. 1/3 branch: add new 'tail' conceptFelipe Contreras, Mar 10, 2023
  3. 2/3 sha1-name: add @{tail} helpersFelipe Contreras, Mar 10, 2023
  4. 3/3 rebase: update branch tail after rebasingFelipe Contreras, Mar 10, 2023
  5. Junio C HamanoMar 11, 2023
  6. Felipe ContrerasMar 11, 2023

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.