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

[PATCH 1/1] p4 unshelve: fix "Not a valid object name HEAD0"

From
MGMike Mueller via GitGitGadget <gitgitgadget@gmail.com>
Date
May 10, 2019, 15:33 UTC
Message-ID
<fc580e902bedb92b5caea8047c1ddd1c9fc822f6.1557502383.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.183.git.gitgitgadget@gmail.com>
From: Mike Mueller <mike.mueller@moodys.com>
git p4 unshelve was failing with these errors on Windows:

fatal: Not a valid object name HEAD0 Command failed: git cat-file commit HEAD^0

(git version 2.21.0.windows.1, python 2.7.16)

The pOpen call used by git-p4 to invoke the git command can take either a string or an array as a first argument. The array form is preferred however the extractLogMessageFromGitCommit method was using the string form, which makes the caller responsible for escaping the command text appropriately (see https://docs.python.org/2/library/subprocess.html)

Somewhat ironically, the carat character is the escape character in Windows and so should be escaped (HEAD^^0). Without the extra carat, the OS was passing an escaped 0 to the git command instead, and the git command was rejecting the invalid object name "HEAD0"

The behaviour can be confirmed by typing ECHO HEAD^0 at the command- prompt, which emits HEAD0.

The solution is simply to use the array format of passing the command to fOpen, which is preferred and used in other parts of this code anyway.

Signed-off-by: Mike Mueller <mike.mueller@moodys.com>
---
 git-p4.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/git-p4.py b/git-p4.py
index 5b79920f46..0b5bfcbc5e 100755
--- a/git-p4.py
+++ b/git-p4.py
@@ -737,7 +737,7 @@ def extractLogMessageFromGitCommit(commit):
 
     ## fixme: title is first line of commit, not 1st paragraph.
     foundTitle = False
-    for log in read_pipe_lines("git cat-file commit %s" % commit):
+    for log in read_pipe_lines(["git", "cat-file", "commit", commit]):
        if not foundTitle:
            if len(log) == 1:
                foundTitle = True
-- 
gitgitgadget
Previous: Mike Mueller via GitGitGadgetNext: Junio C Hamano
Message 2 of 7 in “p4: fix "Not a valid object name HEAD0" when unshelving”
  1. 0/1 p4: fix "Not a valid object name HEAD0" when unshelvingMike Mueller via GitGitGadget, May 10, 2019
  2. 1/1 p4 unshelve: fix "Not a valid object name HEAD0"Mike Mueller via GitGitGadget, May 10, 2019
  3. Junio C HamanoMay 15, 2019
  4. 0/1 p4: fix "Not a valid object name HEAD0" when unshelvingMike Mueller via GitGitGadget, May 28, 2019
  5. 1/1 p4 unshelve: fix "Not a valid object name HEAD0" on WindowsMike Mueller via GitGitGadget, May 28, 2019
  6. Junio C HamanoMay 28, 2019
  7. Johannes SchindelinMay 29, 2019

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.