Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
2fb4e9b3
Commit
2fb4e9b3
authored
Aug 22, 2012
by
Russell Belfer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Wrap up ignore API and add tests
This fills out the ignore API and adds tests.
parent
f004c4a8
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
146 additions
and
9 deletions
+146
-9
include/git2/ignore.h
+74
-0
src/ignore.c
+17
-0
src/status.c
+1
-9
tests-clar/status/ignore.c
+54
-0
No files found.
include/git2/ignore.h
0 → 100644
View file @
2fb4e9b3
/*
* 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
src/ignore.c
View file @
2fb4e9b3
...
@@ -235,3 +235,20 @@ int git_ignore_clear_internal_rules(
...
@@ -235,3 +235,20 @@ int git_ignore_clear_internal_rules(
return
error
;
return
error
;
}
}
int
git_ignore_path_is_ignored
(
int
*
ignored
,
git_repository
*
repo
,
const
char
*
path
)
{
int
error
;
git_ignores
ignores
;
if
(
git_ignore__for_path
(
repo
,
path
,
&
ignores
)
<
0
)
return
-
1
;
error
=
git_ignore__lookup
(
&
ignores
,
path
,
ignored
);
git_ignore__free
(
&
ignores
);
return
error
;
}
src/status.c
View file @
2fb4e9b3
...
@@ -243,14 +243,6 @@ int git_status_should_ignore(
...
@@ -243,14 +243,6 @@ int git_status_should_ignore(
git_repository
*
repo
,
git_repository
*
repo
,
const
char
*
path
)
const
char
*
path
)
{
{
int
error
;
return
git_ignore_path_is_ignored
(
ignored
,
repo
,
path
);
git_ignores
ignores
;
if
(
git_ignore__for_path
(
repo
,
path
,
&
ignores
)
<
0
)
return
-
1
;
error
=
git_ignore__lookup
(
&
ignores
,
path
,
ignored
);
git_ignore__free
(
&
ignores
);
return
error
;
}
}
tests-clar/status/ignore.c
View file @
2fb4e9b3
...
@@ -139,9 +139,63 @@ void test_status_ignore__ignore_pattern_contains_space(void)
...
@@ -139,9 +139,63 @@ void test_status_ignore__ignore_pattern_contains_space(void)
g_repo
=
cl_git_sandbox_init
(
"empty_standard_repo"
);
g_repo
=
cl_git_sandbox_init
(
"empty_standard_repo"
);
cl_git_rewritefile
(
"empty_standard_repo/.gitignore"
,
"foo bar.txt
\n
"
);
cl_git_rewritefile
(
"empty_standard_repo/.gitignore"
,
"foo bar.txt
\n
"
);
cl_git_mkfile
(
"empty_standard_repo/foo bar.txt"
,
"I'm going to be ignored!"
);
cl_git_pass
(
git_status_file
(
&
flags
,
g_repo
,
"foo bar.txt"
));
cl_assert
(
flags
==
GIT_STATUS_IGNORED
);
cl_git_pass
(
git_futils_mkdir_r
(
"empty_standard_repo/foo"
,
NULL
,
mode
));
cl_git_pass
(
git_futils_mkdir_r
(
"empty_standard_repo/foo"
,
NULL
,
mode
));
cl_git_mkfile
(
"empty_standard_repo/foo/look-ma.txt"
,
"I'm not going to be ignored!"
);
cl_git_mkfile
(
"empty_standard_repo/foo/look-ma.txt"
,
"I'm not going to be ignored!"
);
cl_git_pass
(
git_status_file
(
&
flags
,
g_repo
,
"foo/look-ma.txt"
));
cl_git_pass
(
git_status_file
(
&
flags
,
g_repo
,
"foo/look-ma.txt"
));
cl_assert
(
flags
==
GIT_STATUS_WT_NEW
);
cl_assert
(
flags
==
GIT_STATUS_WT_NEW
);
}
}
void
test_status_ignore__adding_internal_ignores
(
void
)
{
int
ignored
;
g_repo
=
cl_git_sandbox_init
(
"empty_standard_repo"
);
cl_git_pass
(
git_status_should_ignore
(
&
ignored
,
g_repo
,
"one.txt"
));
cl_assert
(
!
ignored
);
cl_git_pass
(
git_status_should_ignore
(
&
ignored
,
g_repo
,
"two.bar"
));
cl_assert
(
!
ignored
);
cl_git_pass
(
git_ignore_add_rule
(
g_repo
,
"*.nomatch
\n
"
));
cl_git_pass
(
git_status_should_ignore
(
&
ignored
,
g_repo
,
"one.txt"
));
cl_assert
(
!
ignored
);
cl_git_pass
(
git_status_should_ignore
(
&
ignored
,
g_repo
,
"two.bar"
));
cl_assert
(
!
ignored
);
cl_git_pass
(
git_ignore_add_rule
(
g_repo
,
"*.txt
\n
"
));
cl_git_pass
(
git_status_should_ignore
(
&
ignored
,
g_repo
,
"one.txt"
));
cl_assert
(
ignored
);
cl_git_pass
(
git_status_should_ignore
(
&
ignored
,
g_repo
,
"two.bar"
));
cl_assert
(
!
ignored
);
cl_git_pass
(
git_ignore_add_rule
(
g_repo
,
"*.bar
\n
"
));
cl_git_pass
(
git_status_should_ignore
(
&
ignored
,
g_repo
,
"one.txt"
));
cl_assert
(
ignored
);
cl_git_pass
(
git_status_should_ignore
(
&
ignored
,
g_repo
,
"two.bar"
));
cl_assert
(
ignored
);
cl_git_pass
(
git_ignore_clear_internal_rules
(
g_repo
));
cl_git_pass
(
git_status_should_ignore
(
&
ignored
,
g_repo
,
"one.txt"
));
cl_assert
(
!
ignored
);
cl_git_pass
(
git_status_should_ignore
(
&
ignored
,
g_repo
,
"two.bar"
));
cl_assert
(
!
ignored
);
cl_git_pass
(
git_ignore_add_rule
(
g_repo
,
"multiple
\n
*.rules
\n
# comment line
\n
*.bar
\n
"
));
cl_git_pass
(
git_status_should_ignore
(
&
ignored
,
g_repo
,
"one.txt"
));
cl_assert
(
!
ignored
);
cl_git_pass
(
git_status_should_ignore
(
&
ignored
,
g_repo
,
"two.bar"
));
cl_assert
(
ignored
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment