Re: Using git-update-index to add existing tree objects at other paths
- From
- Phillip Wood <phillip.wood123@gmail.com>
- Date
- Oct 4, 2022, 15:13 UTC
- Message-ID
- <25ec850e-8677-8011-912e-315efb93db4f@dunelm.org.uk>
- In-Reply-To
- <87o7ur1wi9.fsf@gmail.com>
Hi Sean
On 04/10/2022 14:44, Sean Allred wrote:
Show 47 quoted lines
> Hi all, > [...] >> USING --INDEX-INFO >> ------------------ >> >> `--index-info` is a more powerful mechanism that lets you feed >> multiple entry definitions from the standard input, and designed >> specifically for scripts. It can take inputs of three formats: >> >> . mode SP type SP sha1 TAB path >> + >> This format is to stuff `git ls-tree` output into the index. > > but the following does not work: > > $ cat | git update-index --index-info > 040000 tree TREEID1 PATH1 > > (using the appropriate delimiters, of course). This command succeeds, > but checking git-status (and confirming with other tools like `git > ls-files -s`) reveal that this invocation did not have the desired > effect: > >> (mode) (oid) (stage) (path) >> (...) >> 100755 (oid1) 0 PATH1FILENAME >> 100755 (oid2) 0 PATH1FILENAME >> 100755 (oid3) 0 PATH1FILENAME > > with `PATH1` simply prepended to each file in TREEID1. In contrast, the > desired state is > >> 100755 (oid1) 0 PATH1/FILENAME >> 100755 (oid2) 0 PATH1/FILENAME >> 100755 (oid3) 0 PATH1/FILENAME > > I also tried appending a / at the end of PATH1 (this isn't ls-tree > output, but it's 'reasonable'), but git-update-index simply ignores the > line with the message > >> Ignoring path PATH1/ > > Is there a better, recommended way to do this? Given the language in > git-update-index.txt, is this a bug / functionality gap in update-index? > The documentation reads as if I could > > $ git ls-tree <args> | git update-index --index-info
I agree update-index sounds like the right tool for what you want to do and this sounds like a bug but I'm not that familiar with update-index. As a workaround you could try
git ls-tree -r arg | sed s: : new/prefix/: | git update-index --index-info
Best Wishes
Phillip