1 /* 2 * Copyright (C) the libgit2 contributors. All rights reserved. 3 * 4 * This file is part of libgit2, distributed under the GNU GPL v2 with 5 * a Linking Exception. For full terms see the included COPYING file. 6 */ 7 #ifndef INCLUDE_git_ignore_h__ 8 #define INCLUDE_git_ignore_h__ 9 10 #include "common.h" 11 #include "types.h" 12 13 GIT_BEGIN_DECL 14 15 /** 16 * Add ignore rules for a repository. 17 * 18 * Excludesfile rules (i.e. .gitignore rules) are generally read from 19 * .gitignore files in the repository tree or from a shared system file 20 * only if a "core.excludesfile" config value is set. The library also 21 * keeps a set of per-repository internal ignores that can be configured 22 * in-memory and will not persist. This function allows you to add to 23 * that internal rules list. 24 * 25 * Example usage: 26 * 27 * error = git_ignore_add_rule(myrepo, "*.c\ndir/\nFile with space\n"); 28 * 29 * This would add three rules to the ignores. 30 * 31 * @param repo The repository to add ignore rules to. 32 * @param rules Text of rules, a la the contents of a .gitignore file. 33 * It is okay to have multiple rules in the text; if so, 34 * each rule should be terminated with a newline. 35 * @return 0 on success 36 */ 37 GIT_EXTERN(int) git_ignore_add_rule( 38 git_repository *repo, 39 const char *rules); 40 41 /** 42 * Clear ignore rules that were explicitly added. 43 * 44 * Resets to the default internal ignore rules. This will not turn off 45 * rules in .gitignore files that actually exist in the filesystem. 46 * 47 * The default internal ignores ignore ".", ".." and ".git" entries. 48 * 49 * @param repo The repository to remove ignore rules from. 50 * @return 0 on success 51 */ 52 GIT_EXTERN(int) git_ignore_clear_internal_rules( 53 git_repository *repo); 54 55 /** 56 * Test if the ignore rules apply to a given path. 57 * 58 * This function checks the ignore rules to see if they would apply to the 59 * given file. This indicates if the file would be ignored regardless of 60 * whether the file is already in the index or committed to the repository. 61 * 62 * One way to think of this is if you were to do "git check-ignore --no-index" 63 * on the given file, would it be shown or not? 64 * 65 * @param ignored boolean returning 0 if the file is not ignored, 1 if it is 66 * @param repo a repository object 67 * @param path the file to check ignores for, relative to the repo's workdir. 68 * @return 0 if ignore rules could be processed for the file (regardless 69 * of whether it exists or not), or an error < 0 if they could not. 70 */ 71 GIT_EXTERN(int) git_ignore_path_is_ignored( 72 int *ignored, 73 git_repository *repo, 74 const char *path); 75 76 GIT_END_DECL 77 78 #endif 79