Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork939
Read conditional include#1054
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Byron merged 12 commits intogitpython-developers:masterfrombuddly27:read-conditional-includeSep 4, 2020
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
12 commits Select commitHold shift + click to select a range
c16f584
Add Regex to match content of "includeIf" section
buddly279766832
Update check method to find all includes
buddly27d5262ac
Add reference to repository to config.
buddly278e263b8
Add method to retrieve all possible paths to include
buddly27f37011d
Fix logic to properly compare glob pattern to value
buddly273dcb520
Add unit tests
buddly2716d3ebf
Update AUTHOR to respect to contributing guidelines.
buddly27c3fc83f
Add missing rules to match hierarchy path
buddly27c3eae2c
Add missing blank line
buddly272c4dec4
Remove name as not necessary to track down authors.
buddly273787f62
Reformat code to remove unnecessary indentation
buddly275b88532
Ensure that detached HEAD does not raise when comparing branch name.
buddly27File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
67 changes: 63 additions & 4 deletionsgit/config.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletionsgit/repo/base.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletionstest/test_config.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -6,6 +6,8 @@ | ||
import glob | ||
import io | ||
import os | ||
from unittest import mock | ||
from git import ( | ||
GitConfigParser | ||
@@ -238,6 +240,128 @@ def check_test_value(cr, value): | ||
with GitConfigParser(fpa, read_only=True) as cr: | ||
check_test_value(cr, tv) | ||
@with_rw_directory | ||
def test_conditional_includes_from_git_dir(self, rw_dir): | ||
# Initiate repository path | ||
git_dir = osp.join(rw_dir, "target1", "repo1") | ||
os.makedirs(git_dir) | ||
# Initiate mocked repository | ||
repo = mock.Mock(git_dir=git_dir) | ||
Byron marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
# Initiate config files. | ||
path1 = osp.join(rw_dir, "config1") | ||
path2 = osp.join(rw_dir, "config2") | ||
template = "[includeIf \"{}:{}\"]\n path={}\n" | ||
with open(path1, "w") as stream: | ||
stream.write(template.format("gitdir", git_dir, path2)) | ||
# Ensure that config is ignored if no repo is set. | ||
Byron marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
with GitConfigParser(path1) as config: | ||
assert not config._has_includes() | ||
assert config._included_paths() == [] | ||
# Ensure that config is included if path is matching git_dir. | ||
with GitConfigParser(path1, repo=repo) as config: | ||
assert config._has_includes() | ||
assert config._included_paths() == [("path", path2)] | ||
# Ensure that config is ignored if case is incorrect. | ||
with open(path1, "w") as stream: | ||
stream.write(template.format("gitdir", git_dir.upper(), path2)) | ||
with GitConfigParser(path1, repo=repo) as config: | ||
assert not config._has_includes() | ||
assert config._included_paths() == [] | ||
# Ensure that config is included if case is ignored. | ||
with open(path1, "w") as stream: | ||
stream.write(template.format("gitdir/i", git_dir.upper(), path2)) | ||
with GitConfigParser(path1, repo=repo) as config: | ||
assert config._has_includes() | ||
assert config._included_paths() == [("path", path2)] | ||
# Ensure that config is included with path using glob pattern. | ||
with open(path1, "w") as stream: | ||
stream.write(template.format("gitdir", "**/repo1", path2)) | ||
with GitConfigParser(path1, repo=repo) as config: | ||
assert config._has_includes() | ||
assert config._included_paths() == [("path", path2)] | ||
# Ensure that config is ignored if path is not matching git_dir. | ||
with open(path1, "w") as stream: | ||
stream.write(template.format("gitdir", "incorrect", path2)) | ||
with GitConfigParser(path1, repo=repo) as config: | ||
assert not config._has_includes() | ||
assert config._included_paths() == [] | ||
# Ensure that config is included if path in hierarchy. | ||
with open(path1, "w") as stream: | ||
stream.write(template.format("gitdir", "target1/", path2)) | ||
with GitConfigParser(path1, repo=repo) as config: | ||
assert config._has_includes() | ||
assert config._included_paths() == [("path", path2)] | ||
@with_rw_directory | ||
def test_conditional_includes_from_branch_name(self, rw_dir): | ||
# Initiate mocked branch | ||
branch = mock.Mock() | ||
type(branch).name = mock.PropertyMock(return_value="/foo/branch") | ||
# Initiate mocked repository | ||
repo = mock.Mock(active_branch=branch) | ||
# Initiate config files. | ||
path1 = osp.join(rw_dir, "config1") | ||
path2 = osp.join(rw_dir, "config2") | ||
template = "[includeIf \"onbranch:{}\"]\n path={}\n" | ||
# Ensure that config is included is branch is correct. | ||
with open(path1, "w") as stream: | ||
stream.write(template.format("/foo/branch", path2)) | ||
with GitConfigParser(path1, repo=repo) as config: | ||
assert config._has_includes() | ||
assert config._included_paths() == [("path", path2)] | ||
# Ensure that config is included is branch is incorrect. | ||
with open(path1, "w") as stream: | ||
stream.write(template.format("incorrect", path2)) | ||
with GitConfigParser(path1, repo=repo) as config: | ||
assert not config._has_includes() | ||
assert config._included_paths() == [] | ||
# Ensure that config is included with branch using glob pattern. | ||
with open(path1, "w") as stream: | ||
stream.write(template.format("/foo/**", path2)) | ||
with GitConfigParser(path1, repo=repo) as config: | ||
assert config._has_includes() | ||
assert config._included_paths() == [("path", path2)] | ||
@with_rw_directory | ||
def test_conditional_includes_from_branch_name_error(self, rw_dir): | ||
# Initiate mocked repository to raise an error if HEAD is detached. | ||
repo = mock.Mock() | ||
type(repo).active_branch = mock.PropertyMock(side_effect=TypeError) | ||
# Initiate config file. | ||
path1 = osp.join(rw_dir, "config1") | ||
# Ensure that config is ignored when active branch cannot be found. | ||
with open(path1, "w") as stream: | ||
stream.write("[includeIf \"onbranch:foo\"]\n path=/path\n") | ||
with GitConfigParser(path1, repo=repo) as config: | ||
assert not config._has_includes() | ||
assert config._included_paths() == [] | ||
def test_rename(self): | ||
file_obj = self._to_memcache(fixture_path('git_config')) | ||
with GitConfigParser(file_obj, read_only=False, merge_includes=False) as cw: | ||
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.