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

Re: git ls-tree -d doesn't work if the specified path is the repository root?

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Sep 25, 2017, 22:25 UTC
Message-ID
<20170925222556.GH27425@aiede.mtv.corp.google.com>
In-Reply-To
<CAF5E6=pqGZt_BUDRDeN2uAQK7qBTeO+zcR8NsvSPg-rLjbsqdQ@mail.gmail.com>
Hi,
Roy Wellington wrote:
Show 8 quoted lines
> When I run `git ls-tree -d HEAD -- subdir` from the root of my
> repository, where `subdir` is a subdirectory in that root, I get the
> treehash of that subdirectory. This is what I expect.
>
> However, if I merely replace `subdir` with `.` (the root of the
> repository), (i.e., `git ls-tree -d HEAD -- .`) git ls-tree returns
> the treehashes of the /children/ of the root, instead of the root
> itself, contrary to the documented behavior of -d.

Can you be more specific? What documentation led you to this expectation?

I don't have a strong opinion about this behavior, but in any case if the documentation and command disagree about the correct behavior then one of them needs to be fixed. :)

> Is there some reason for this? This behavior seems like a bug to me:
> it means that prior to calling ls-tree I need to check if the
> referenced path happens to be the root, and if so, find some other
> means (rev-parse?) of converting it to a treehash.
Does
	git rev-parse HEAD:subdir

work better for what you're trying to accomplish? To get the root of the repository, you can use

	git rev-parse HEAD:

Thanks and hope that helps, Jonathan

Previous: Santiago Torres
Message 3 of 3 in “git ls-tree -d doesn't work if the specified path is the repository root?”
  1. Roy WellingtonSep 25, 2017
  2. Santiago TorresSep 25, 2017
  3. Jonathan NiederSep 25, 2017

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.