summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorVicent Martí <vicent@github.com>2012-08-22 13:15:14 -0700
committerVicent Martí <vicent@github.com>2012-08-22 13:15:14 -0700
commitcfda29e38260f19e77f1746c4f6f1c2cab453934 (patch)
treedd2a15ccec2e763931c9913970d88a5811feb36a /include
parent697665c0c13e45a5d24af85c133ffaa0a0e0f8cc (diff)
parent2fb4e9b3c5fb410164a32724e42a10d1841d02cc (diff)
downloadlibgit2-cfda29e38260f19e77f1746c4f6f1c2cab453934.tar.gz
Merge pull request #891 from arrbee/internal-ignore-api
API for managing in-memory ignore rules
Diffstat (limited to 'include')
-rw-r--r--include/git2.h1
-rw-r--r--include/git2/ignore.h74
2 files changed, 75 insertions, 0 deletions
diff --git a/include/git2.h b/include/git2.h
index 40167484b..805044abb 100644
--- a/include/git2.h
+++ b/include/git2.h
@@ -41,6 +41,7 @@
#include "git2/checkout.h"
#include "git2/attr.h"
+#include "git2/ignore.h"
#include "git2/branch.h"
#include "git2/refspec.h"
#include "git2/net.h"
diff --git a/include/git2/ignore.h b/include/git2/ignore.h
new file mode 100644
index 000000000..f7e04e881
--- /dev/null
+++ b/include/git2/ignore.h
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2012 the libgit2 contributors
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
+#ifndef INCLUDE_git_ignore_h__
+#define INCLUDE_git_ignore_h__
+
+#include "common.h"
+#include "types.h"
+
+GIT_BEGIN_DECL
+
+/**
+ * Add ignore rules for a repository.
+ *
+ * Excludesfile rules (i.e. .gitignore rules) are generally read from
+ * .gitignore files in the repository tree or from a shared system file
+ * only if a "core.excludesfile" config value is set. The library also
+ * keeps a set of per-repository internal ignores that can be configured
+ * in-memory and will not persist. This function allows you to add to
+ * that internal rules list.
+ *
+ * Example usage:
+ *
+ * error = git_ignore_add(myrepo, "*.c\ndir/\nFile with space\n");
+ *
+ * This would add three rules to the ignores.
+ *
+ * @param repo The repository to add ignore rules to.
+ * @param rules Text of rules, a la the contents of a .gitignore file.
+ * It is okay to have multiple rules in the text; if so,
+ * each rule should be terminated with a newline.
+ * @return 0 on success
+ */
+GIT_EXTERN(int) git_ignore_add_rule(
+ git_repository *repo,
+ const char *rules);
+
+/**
+ * Clear ignore rules that were explicitly added.
+ *
+ * Clears the internal ignore rules that have been set up. This will not
+ * turn off the rules in .gitignore files that actually exist in the
+ * filesystem.
+ *
+ * @param repo The repository to remove ignore rules from.
+ * @return 0 on success
+ */
+GIT_EXTERN(int) git_ignore_clear_internal_rules(
+ git_repository *repo);
+
+/**
+ * Test if the ignore rules apply to a given path.
+ *
+ * This function simply checks the ignore rules to see if they would apply
+ * to the given file. This indicates if the file would be ignored regardless
+ * of whether the file is already in the index or commited to the repository.
+ *
+ * @param ignored boolean returning 0 if the file is not ignored, 1 if it is
+ * @param repo a repository object
+ * @param path the file to check ignores for, relative to the repo's workdir.
+ * @return 0 if ignore rules could be processed for the file (regardless
+ * of whether it exists or not), or an error < 0 if they could not.
+ */
+GIT_EXTERN(int) git_ignore_path_is_ignored(
+ int *ignored,
+ git_repository *repo,
+ const char *path);
+
+GIT_END_DECL
+
+#endif