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

Bug in git archive + .gitattributes + relative path

From
CLCristian Le <cristian.le@mpsd.mpg.de>
Date
Mar 3, 2023, 10:25 UTC
Message-ID
<42f13cda-9de6-bfc6-7e81-64c94f5640db@mpsd.mpg.de>

Using `git archive` with or without `--worktree-attributes` does not properly read `.gitattributes` files if using a relative path in `<tree-ish>`. Related github comment: https://github.com/rpm-software-management/tito/pull/445#issuecomment-1450298871 Related stackoverflow discussion: https://stackoverflow.com/questions/52804334/how-to-ignore-files-directories-in-git-archive-and-only-create-an-archive-of-a

Git version: `2.39.2` Mwe git repo: Two files: ``` # .gitattributes: .git_archival.txt export-subst ``` ``` # .git_archival.txt: node: $Format:%H$ ```

Commands to reproduce and expected behaviour:
```console
$ git archive HEAD:./ --output=test.tar.gz
$ tar -axf test.tar.gz .git_archival.txt -O
node: 745ce26169fb44e04d91d40ee581cccd591c941e
```
Important: Notice the path `./` given after `HEAD`.

Actual output: ```console $ tar -axf test.tar.gz .git_archival.txt -O node: $Format:%H$ ```

It doesn't matter if `.gitattributes` is in a subfolder, or if I change the relative path `./` to a subfolder, the files are still not properly generated.

Using `--worktree-attributes` did not have any effect either.
According to the documentation, I understand that the expected behaviour 
with regards to `--worktree-attributes`:
- Read the `.gitattributes` of the relative path, e.g. `./sub_dir` 
regardless of `--worktree-attributes`. (similar behaviour as not passing 
a relative path)
- Include the `.gitattributes` of the top-level path if 
`--worktree-attributes` is passed

Maybe the intended behaviour is to completely ignore all `.gitattributes` unless `--worktree-attributes` is provided, in which case, it does not have the intended behaviour and please include a flag to achieve the above behaviour.

Next: René Scharfe
Message 1 of 22 in “Bug in git archive + .gitattributes + relative path”
  1. Cristian LeMar 3, 2023
  2. René ScharfeMar 3, 2023
  3. Cristian LeMar 3, 2023
  4. René ScharfeMar 4, 2023
  5. Cristian LeMar 4, 2023
  6. René ScharfeMar 5, 2023
  7. Junio C HamanoMar 6, 2023
  8. René ScharfeMar 6, 2023
  9. Junio C HamanoMar 6, 2023
  10. René ScharfeMar 6, 2023
  11. Junio C HamanoMar 6, 2023
  12. René ScharfeMar 6, 2023
  13. Junio C HamanoMar 6, 2023
  14. René ScharfeMar 11, 2023
  15. Junio C HamanoMar 12, 2023
  16. René ScharfeMar 18, 2023
  17. Junio C HamanoMar 20, 2023
  18. archive: improve support for running in a subdirectoryRené Scharfe, Mar 20, 2023
  19. Junio C HamanoMar 21, 2023
  20. René ScharfeMar 24, 2023
  21. archive: improve support for running in subdirectoryRené Scharfe, Mar 24, 2023
  22. Junio C HamanoMar 27, 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.