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

[PATCH v2 3/3] rebase (autostash): use an explicit OID to apply the stash

From
Johannes Schindelin via GitGitGadget <gitgitgadget@gmail.com>
Date
Oct 22, 2018, 22:15 UTC
Message-ID
<07140a71dd9ed3f709970f0ce5eb6aa014417b25.1540246499.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.52.v2.git.gitgitgadget@gmail.com>
From: Johannes Schindelin <johannes.schindelin@gmx.de>

When `git stash apply <argument>` sees an argument that consists only of digits, it tries to be smart and interpret it as `stash@{<number>}`.

Unfortunately, an all-digit hash (which is unlikely but still possible) is therefore misinterpreted as `stash@{<n>}` reflog.

To prevent that from happening, let's append `^0` after the stash hash, to make sure that it is interpreted as an OID rather than as a number.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 builtin/rebase.c | 2 ++
 1 file changed, 2 insertions(+)
diff --git a/builtin/rebase.c b/builtin/rebase.c
index 418624837..30d58118c 100644
--- a/builtin/rebase.c
+++ b/builtin/rebase.c
@@ -253,6 +253,8 @@ static int apply_autostash(struct rebase_options *opts)
 
 	if (read_one(path, &autostash))
 		return error(_("Could not read '%s'"), path);
+	/* Ensure that the hash is not mistake for a number */
+	strbuf_addstr(&autostash, "^0");
 	argv_array_pushl(&stash_apply.args,
 			 "stash", "apply", autostash.buf, NULL);
 	stash_apply.git_cmd = 1;
-- 
gitgitgadget
Previous: Johannes Schindelin via GitGitGadgetNext: Eric Sunshine
Message 2 of 9 in “Fix rebase autostash”
  1. 0/3 Fix rebase autostashJohannes Schindelin via GitGitGadget, Oct 22, 2018
  2. 3/3 rebase (autostash): use an explicit OID to apply the stashJohannes Schindelin via GitGitGadget, Oct 22, 2018
  3. Eric SunshineOct 22, 2018
  4. SZEDER GáborOct 22, 2018
  5. Junio C HamanoOct 23, 2018
  6. Johannes SchindelinOct 23, 2018
  7. Alban GruinOct 23, 2018
  8. 2/3 rebase (autostash): store the full OID in <state-dir>/autostashJohannes Schindelin via GitGitGadget, Oct 22, 2018
  9. 1/3 rebase (autostash): avoid duplicate call to state_dir_path()Johannes Schindelin via GitGitGadget, Oct 22, 2018

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.