rustic icon indicating copy to clipboard operation
rustic copied to clipboard

gitignore not pass to child folder

Open kuyagic opened this issue 1 year ago • 9 comments

I must copy my gitignore file in every folder , will it be inherited from the parent folder ?

kuyagic avatar Jun 16 '23 08:06 kuyagic

Actually .gitignore files from parent folders should be taken into account - if you use the git-ignore option and if that parent folder is also included in the backup.

If something isn't working for you, can you please send your .gitignore file, tell where it lies and which file doesn't get correctly ignored?

aawsome avatar Jun 16 '23 10:06 aawsome

I'm on windows

G:\restic-test>rustic -V
rustic v0.5.4

my test stuff tree is below image

my .gitignore file content

**/debug
*.log

my backup command is

G:\restic-test>rustic -r g:\r backup --log-level debug --git-ignore -n g:\restic-test

the program debug output is below

using no config file (.\rustic.toml doesn't exist)
enter repository password: [INFO] repository local:g:\r: password is correct.
[INFO] using cache at C:\Users\Chinni\AppData\Local\rustic\d8496a57f56610b4e77cb39ad0edbac73be8090282924a97b712c6390ea8229d
[00:00:00] reading index...               ████████████████████████████████████████          0/0                         [INFO] starting to backup "G:\\restic-test"...
[00:00:00] getting latest snapshot...     ████████████████████████████████████████          0/0                         [INFO] using no parent
[00:00:00] determining size...            ████████████████████████████████████████         0B/0B         0B/s         (ETA -)[DEBUG] (1) globset: built glob set; 0 literals, 1 basenames, 1 extensions, 0 prefixes, 0 suffixes, 0 required exte[00:00:00] backing up...                  ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░         0B/25.73 KiB  0B/s         (ETA -)[DEBUG] (1) globset: built glob set; 0 literals, 1 basenames, 1 extensions, 0 prefixes, 0 suffixes, 0 required extensions, 0 regexes
[DEBUG] (1) rustic::archiver::tree_archiver: new       file: "G:\\restic-test\\.gitignore"
[DEBUG] (1) rustic::archiver::tree_archiver: new       file: "G:\\restic-test\\ct\\CACHEDIR.TAG"
[DEBUG] (1) rustic::archiver::tree_archiver: new       file: "G:\\restic-test\\ct\\cache-tag-ignore.txt"
[DEBUG] (1) rustic::archiver::tree_archiver: new       tree: "G:\\restic-test\\ct" 550 B
[DEBUG] (1) rustic::archiver::tree_archiver: new       file: "G:\\restic-test\\debug\\root-debug-file.txt"
[DEBUG] (1) rustic::archiver::tree_archiver: new       tree: "G:\\restic-test\\debug" 283 B
[DEBUG] (1) rustic::archiver::tree_archiver: new       file: "G:\\restic-test\\log"
[DEBUG] (1) rustic::archiver::tree_archiver: new       file: "G:\\restic-test\\n1\\debug\\n1-debug-file.txt"
[DEBUG] (1) rustic::archiver::tree_archiver: new       tree: "G:\\restic-test\\n1\\debug" 282 B
[DEBUG] (1) rustic::archiver::tree_archiver: new       tree: "G:\\restic-test\\n1" 272 B
[DEBUG] (1) rustic::archiver::tree_archiver: new       file: "G:\\restic-test\\n2\\a.log"
[DEBUG] (1) rustic::archiver::tree_archiver: new       file: "G:\\restic-test\\n2\\log.txt"
[DEBUG] (1) rustic::archiver::tree_archiver: new       tree: "G:\\restic-test\\n2" 536 B
[DEBUG] (1) rustic::archiver::tree_archiver: new       tree: "G:\\restic-test" 1.5 kiB
[DEBUG] (1) rustic::archiver::tree_archiver: new       tree: "G:" 140 B
[00:00:00] backing up...                  ████████████████████████████████████████  25.73 KiB/25.73 KiB  1.95 MiB/s   (ETA 0s)[DEBUG] (1) rustic::commands::backup: Data Blobs:  8 new
[DEBUG] (1) rustic::commands::backup: Tree Blobs:  8 new
[INFO] backup of "G:\\restic-test" done.

kuyagic avatar Jun 16 '23 13:06 kuyagic

with the following command , the result should be the right one rustic -r g:\r backup --log-level debug -n --glob "!*.log" g:\restic-test

output

G:\restic-test>rustic -r g:\r backup --log-level debug -n --glob "!*.log" g:\restic-test
using no config file (.\rustic.toml doesn't exist)
enter repository password:
[INFO] repository local:g:\r: password is correct.
[INFO] using cache at C:\Users\Chinni\AppData\Local\rustic\d8496a57f56610b4e77cb39ad0edbac73be8090282924a97b712c6390ea8229d
[00:00:00] reading index...               ████████████████████████████████████████          0/0                         [INFO] starting to backup "G:\\restic-test"...
[00:00:00] getting latest snapshot...     ████████████████████████████████████████          0/0                         [INFO] using no parent
[00:00:00] determining size...            ████████████████████████████████████████         0B/0B         0B/s         (ETA -)[DEBUG] (1) globset: built glob set; 0 literals, 0 basenames, 1 extensions, 0 prefixes, 0 suffixes, 0 required exte[00:00:00] determining size...            ████████████████████████████████████████         0B/0B         0B/s         (ETA -)[DEBUG] (1) ignore::walk: ignoring G:\restic-test\n2\a.log: Ignore(IgnoreMatch(Override(Glob(Matched(Glob { from: N[00:00:00] backing up...                  ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░         0B/13.10 KiB  0B/s         (ETA -)[DEBUG] (1) rustic::archiver::tree_archiver: new       file: "G:\\restic-test\\.gitignore"
[DEBUG] (45) ignore::walk: ignoring G:\restic-test\n2\a.log: Ignore(IgnoreMatch(Override(Glob(Matched(Glob { from: None, original: "!*.log", actual: "**/*.log", is_whitelist: true, is_only_dir: false })))))
[DEBUG] (1) rustic::archiver::tree_archiver: new       file: "G:\\restic-test\\ct\\CACHEDIR.TAG"
[DEBUG] (1) rustic::archiver::tree_archiver: new       file: "G:\\restic-test\\ct\\cache-tag-ignore.txt"
[DEBUG] (1) rustic::archiver::tree_archiver: new       tree: "G:\\restic-test\\ct" 550 B
[DEBUG] (1) rustic::archiver::tree_archiver: new       file: "G:\\restic-test\\debug\\root-debug-file.txt"
[DEBUG] (1) rustic::archiver::tree_archiver: new       tree: "G:\\restic-test\\debug" 283 B
[DEBUG] (1) rustic::archiver::tree_archiver: new       file: "G:\\restic-test\\log"
[DEBUG] (1) rustic::archiver::tree_archiver: new       file: "G:\\restic-test\\n1\\debug\\n1-debug-file.txt"
[DEBUG] (1) rustic::archiver::tree_archiver: new       tree: "G:\\restic-test\\n1\\debug" 282 B
[DEBUG] (1) rustic::archiver::tree_archiver: new       tree: "G:\\restic-test\\n1" 272 B
[DEBUG] (1) rustic::archiver::tree_archiver: new       file: "G:\\restic-test\\n2\\log.txt"
[DEBUG] (1) rustic::archiver::tree_archiver: new       tree: "G:\\restic-test\\n2" 275 B
[DEBUG] (1) rustic::archiver::tree_archiver: new       tree: "G:\\restic-test" 1.5 kiB
[DEBUG] (1) rustic::archiver::tree_archiver: new       tree: "G:" 140 B
[00:00:00] backing up...                  ████████████████████████████████████████  13.10 KiB/13.10 KiB  1.11 MiB/s   (ETA 0s)Files:       7 new, 0 changed, 0 unchanged
Dirs:        8 new, 0 changed, 0 unchanged
[DEBUG] (1) rustic::commands::backup: Data Blobs:  7 new
[DEBUG] (1) rustic::commands::backup: Tree Blobs:  8 new
Added to the repo: 5.7 kiB (raw: 16.5 kiB)
processed 7 files, 13.1 kiB
snapshot 00000000 successfully saved.
[INFO] backup of "G:\\restic-test" done.

kuyagic avatar Jun 16 '23 13:06 kuyagic

Did you try a git add . to see what git would add?

IIRC, you have to put **/*.log into .gitignore in order to ignore .log files in all subdirectories.

aawsome avatar Jun 16 '23 13:06 aawsome

git add . and git commit shows the following file image

it is the correct result without changing *.log to **/*.log

kuyagic avatar Jun 16 '23 13:06 kuyagic

Mhh.. if the git-ignore option doesn't ignore like git does, I would say, this is a bug.. Can you check if this affects only the windows version or also Linux/MacOs?

aawsome avatar Jun 18 '23 18:06 aawsome

I think Linux should be OK

same file set and .gitignore file

./rustic -r r backup --log-level debug --git-ignore -n ./restic-test
using no config file (./rustic.toml doesn't exist)
enter repository password:
[INFO] repository local:r: password is correct.
[INFO] using cache at /root/.cache/rustic/d8496a57f56610b4e77cb39ad0edbac73be8090282924a97b712c6390ea8229d
[00:00:00] reading index...               ████████████████████████████████████████          0/0                                              [INFO] starting to backup "/root/rr/restic-test"...
[00:00:00] getting latest snapshot...     ████████████████████████████████████████          0/0                                              [INFO] using no parent
[00:00:00] determining size...            ████████████████████████████████████████         0B/0B         0B/s         (ETA -)                [DEBUG] (1) globset: built glob set; 0 literals, 2 basenames, 1 extensions, 0 prefixes, 0 suffixes, 0 required extensions, 0 regexes
[DEBUG] (1) ignore::walk: ignoring /root/rr/restic-test/.git: Ignore(IgnoreMatch(Gitignore(Glob { from: Some("/root/rr/restic-test/.gitignore"), original: ".git", actual: "**/.git", is_whitelist: false, is_only_dir: false })))
[DEBUG] (1) ignore::walk: ignoring /root/rr/restic-test/debug: Ignore(IgnoreMatch(Gitignore(Glob { from: Some("/root/rr/restic-test/.gitignore"), original: "**/debug", actual: "**/debug", is_whitelist: false, is_only_dir: false })))
[DEBUG] (1) ignore::walk: ignoring /root/rr/restic-test/n1/debug: Ignore(IgnoreMatch(Gitignore(Glob { from: Some("/root/rr/restic-test/.gitignore"), original: "**/debug", actual: "**/debug", is_whitelist: false, is_only_dir: false })))
[DEBUG] (1) ignore::walk: ignoring /root/rr/restic-test/n2/a.log: Ignore(IgnoreMatch(Gitignore(Glob { from: Some("/root/rr/restic-test/.gitignore"), original: "*.log", actual: "**/*.log", is_whitelist: false, is_only_dir: false })))
[00:00:00] backing up...                  ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░         0B/13.09 KiB  0B/s         (ETA -)                [DEBUG] (1) globset: built glob set; 0 literals, 2 basenames, 1 extensions, 0 prefixes, 0 suffixes, 0 required extensions, 0 regexes
[DEBUG] (1) ignore::walk: ignoring /root/rr/restic-test/.git: Ignore(IgnoreMatch(Gitignore(Glob { from: Some("/root/rr/restic-test/.gitignore"), original: ".git", actual: "**/.git", is_whitelist: false, is_only_dir: false })))
[DEBUG] (57) ignore::walk: ignoring /root/rr/restic-test/debug: Ignore(IgnoreMatch(Gitignore(Glob { from: Some("/root/rr/restic-test/.gitignore"), original: "**/debug", actual: "**/debug", is_whitelist: false, is_only_dir: false })))
[DEBUG] (57) ignore::walk: ignoring /root/rr/restic-test/n1/debug: Ignore(IgnoreMatch(Gitignore(Glob { from: Some("/root/rr/restic-test/.gitignore"), original: "**/debug", actual: "**/debug", is_whitelist: false, is_only_dir: false })))
[DEBUG] (57) ignore::walk: ignoring /root/rr/restic-test/n2/a.log: Ignore(IgnoreMatch(Gitignore(Glob { from: Some("/root/rr/restic-test/.gitignore"), original: "*.log", actual: "**/*.log", is_whitelist: false, is_only_dir: false })))
[DEBUG] (1) rustic::archiver::tree_archiver: new       file: "/root/rr/restic-test/.gitignore"
[DEBUG] (1) rustic::archiver::tree_archiver: new       file: "/root/rr/restic-test/ct/CACHEDIR.TAG"
[DEBUG] (1) rustic::archiver::tree_archiver: new       file: "/root/rr/restic-test/ct/cache-tag-ignore.txt"
[DEBUG] (1) rustic::archiver::tree_archiver: new       tree: "/root/rr/restic-test/ct" 746 B
[DEBUG] (1) rustic::archiver::tree_archiver: new       file: "/root/rr/restic-test/log"
[DEBUG] (1) rustic::archiver::tree_archiver: new       tree: "/root/rr/restic-test/n1" 13 B
[DEBUG] (1) rustic::archiver::tree_archiver: new       file: "/root/rr/restic-test/n2/log.txt"
[DEBUG] (1) rustic::archiver::tree_archiver: new       tree: "/root/rr/restic-test/n2" 373 B
[DEBUG] (1) rustic::archiver::tree_archiver: new       tree: "/root/rr/restic-test" 1.7 kiB
[DEBUG] (1) rustic::archiver::tree_archiver: new       tree: "/root/rr" 140 B
[DEBUG] (1) rustic::archiver::tree_archiver: new       tree: "/root" 131 B
[DEBUG] (1) rustic::archiver::tree_archiver: new       tree: "" 133 B
[00:00:00] backing up...                  ████████████████████████████████████████  13.09 KiB/13.09 KiB  869.81 KiB/s (ETA 0s)               Files:       5 new, 0 changed, 0 unchanged
Dirs:        7 new, 0 changed, 0 unchanged

kuyagic avatar Jun 20 '23 12:06 kuyagic

I think it could be related, because I faced a similar issue, that .gitignore didn't work. By default it's true: ignore::WalkBuilder::require_git

upd. No, I read it wrong

istudyatuni avatar Jun 21 '23 19:06 istudyatuni

Yes, It seems to me this is a Windows-only issue..

aawsome avatar Jun 22 '23 17:06 aawsome