From be5c7f6605f622ed51eed0388071e5a52b9a2ed0 Mon Sep 17 00:00:00 2001 From: civts Date: Thu, 2 Mar 2023 11:32:41 +0100 Subject: [PATCH] Add CLI flag to enable excluding from gitignore --- cmd/restic/cmd_backup.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cmd/restic/cmd_backup.go b/cmd/restic/cmd_backup.go index 1244e2ed1..0fb161484 100644 --- a/cmd/restic/cmd_backup.go +++ b/cmd/restic/cmd_backup.go @@ -95,6 +95,7 @@ type BackupOptions struct { ExcludeIfPresent []string ExcludeCaches bool ExcludeLargerThan string + ExcludeGitignored bool Stdin bool StdinFilename string Tags restic.TagLists @@ -132,6 +133,7 @@ func init() { f.StringArrayVar(&backupOptions.ExcludeIfPresent, "exclude-if-present", nil, "takes `filename[:header]`, exclude contents of directories containing filename (except filename itself) if header of that file is as provided (can be specified multiple times)") f.BoolVar(&backupOptions.ExcludeCaches, "exclude-caches", false, `excludes cache directories that are marked with a CACHEDIR.TAG file. See https://bford.info/cachedir/ for the Cache Directory Tagging Standard`) f.StringVar(&backupOptions.ExcludeLargerThan, "exclude-larger-than", "", "max `size` of the files to be backed up (allowed suffixes: k/K, m/M, g/G, t/T)") + f.BoolVar(&backupOptions.ExcludeGitignored, "exclude-gitignored", false, "excludes from the backup any file or directory which is ignored through a `.gitignore`. Files and directories which are specified directly (through file args, `files-from` or `files-from-x` arguments) are always included.") f.BoolVar(&backupOptions.Stdin, "stdin", false, "read backup from stdin") f.StringVar(&backupOptions.StdinFilename, "stdin-filename", "stdin", "`filename` to use when reading from stdin") f.Var(&backupOptions.Tags, "tag", "add `tags` for the new snapshot in the format `tag[,tag,...]` (can be specified multiple times)") @@ -338,6 +340,14 @@ func collectRejectByNameFuncs(opts BackupOptions, repo *repository.Repository, t fs = append(fs, f) } + if opts.ExcludeGitignored { + f, err := rejectGitignored(targets) + if err != nil { + return nil, err + } + fs = append(fs, f) + } + return fs, nil }