-g or --gitignore doesn't seem to work
Version
ouch 0.4.2
Description
-g or --gitignore doesn't seem to work (see attached video). Or am I doing it wrong? The use of --gitignore or -g is not mentioned anywhere in the documentation. I found it with --help then https://github.com/ouch-org/ouch/issues/170 to https://github.com/ouch-org/ouch/pull/245
The contents of the .gitignore file are as follows :
*.zip
*.tar.gz
https://github.com/ouch-org/ouch/assets/56940294/e0cddc56-f27c-4a29-9b95-d3fd9e544ef5
Current Behavior
No response
Expected Behavior
It should normally ignore files/folders mentioned in .gitignore
Additional Information
No response
This can be a bit confusing, here's how -g/--gitignore works:
When recursing through directory entries, do not include the ones in .gitignore.
(This can be useful if you want to compress a repository without including the build artifacts.)
However, you can bypass -g/--gitignore by providing the explicit name of the files you want.
That's what you're doing, your shell (bash, zsh or fish) expands * to the two arguments "PNG.zip" and "SVG.zip", so you're bypassing the -g flag.
The current workaround would be to pass the folder itself to Ouch.
cd ..
ouch compress folder testo.tar.gz --gitignore
But we can also discuss wether we want to remove the capability to bypass --gitignore.
-g, --gitignore
Ignores files matched by git's ignore files
Also, we need to update the --help to make this clear, and maybe document it in README.md.
@marcospb19 Thanks for your response
However, you can bypass -g/--gitignore by providing the explicit name of the files you want.
The files contained in folders are too numerous to be defined by hand. That's why I took PNG.zip and SVG.zip to create this issue. 🔥.
The current workaround would be to pass the folder itself to Ouch.
It wasn't the folder I wanted to compress, but the contents only, and above all to be able to access the files directly when opening the archive (to avoid --strip-components=1 with tar for example).
That's what you're doing, your shell (bash, zsh or fish) expands * to the two arguments "PNG.zip" and "SVG.zip", so you're bypassing the -g flag.
The idea is to take everything (*) in the folder but exclude the files mentioned in .gitignore and/or .gitignore file itself. To use git with .gitignore file, you have to be in the folder itself at the root of the .git folder and the git command takes .gitignore into account in the same place, no need to pass the parent folder.
Ouch could perhaps be inspired by the "tar" command with --exclude arg. Passing several exclusion arguments in the same way (--exclude "<regex/*.ext/string...etc>") otherwise the .gitignore or .ouchignore file idea is also good to avoid multiple --exclude arguments.
tar -czvf testo.tar.gz --exclude "*.zip" --exclude "*.tar.gz" -C <path> .(dot) --overwrite
tar -czvf testo.tar.gz --exclude "*.zip" --exclude "*.tar.gz" .(dot) --overwrite
The output of "ouch --help" gives "Usage: ouch [OPTIONS] <COMMAND>" the options before the command. Is it necessary to respect the order?
The output of "ouch --help" gives "Usage: ouch [OPTIONS] <COMMAND>" the options before the command. Is it necessary to respect the order?
No, --gitignore is currently a global flag because it applies to all 3 subcommands.
Thanks for your input, having a --exclude flag sounds like a great path to solve this one.