| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -58,8 +58,8 @@ Config | |||
| 58 | 58 | ------ | |
| 59 | 59 | * The git configuration can now be read and manipulated directly from within python | |
| 60 | 60 | using the GitConfigParser | |
| 61 | - * Repo.config_reader returns a read-only parser | ||
| 62 | - * Repo.config_writer returns a read-write parser | ||
| 61 | + * Repo.config_reader() returns a read-only parser | ||
| 62 | + * Repo.config_writer() returns a read-write parser | ||
| 63 | 63 | ||
| 64 | 64 | Diff | |
| 65 | 65 | ---- | |
@@ -115,8 +115,9 @@ Repo | |||
| 115 | 115 | - 'head', creates a head object | |
| 116 | 116 | - 'tag', creates a tag object | |
| 117 | 117 | - 'iter_trees' method | |
| 118 | - - 'config_reader' property | ||
| 119 | - - 'config_writer' property | ||
| 118 | + - 'config_reader' method | ||
| 119 | + - 'config_writer' method | ||
| 120 | + - 'bare' property, previously it was a simple attribute that could be written | ||
| 120 | 121 | ||
| 121 | 122 | Remote | |
| 122 | 123 | ------ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -31,8 +31,6 @@ Index | |||
| 31 | 31 | Repo | |
| 32 | 32 | ---- | |
| 33 | 33 | * Nice fetch/pull handling, at least supported/wired throuhg to the git command | |
| 34 | - * repo.bare is set according to the path it is initialized with, although it | ||
| 35 | - should be read from the configuration in fact. Check uses of repo.bare. | ||
| 36 | 34 | * Blame: Read the blame format making assumptions about its structure, | |
| 37 | 35 | currently regex are used a lot although we can deduct what will be next. | |
| 38 | 36 | - Read data from a stream directly from git command | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -77,7 +77,7 @@ def _config_section_name(self): | |||
| 77 | 77 | ||
| 78 | 78 | def _set_cache_(self, attr): | |
| 79 | 79 | if attr == "_config_reader": | |
| 80 | - self._config_reader = _SectionConstraint(self.repo.config_reader, self._config_section_name()) | ||
| 80 | + self._config_reader = _SectionConstraint(self.repo.config_reader(), self._config_section_name()) | ||
| 81 | 81 | else: | |
| 82 | 82 | super(Remote, self)._set_cache_(attr) | |
| 83 | 83 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -79,22 +79,30 @@ def __init__(self, path=None): | |||
| 79 | 79 | ||
| 80 | 80 | self.path = None | |
| 81 | 81 | curpath = epath | |
| 82 | + | ||
| 83 | + # walk up the path to find the .git dir | ||
| 82 | 84 | while curpath: | |
| 83 | 85 | if is_git_dir(curpath): | |
| 84 | - self.bare = True | ||
| 85 | 86 | self.path = curpath | |
| 86 | 87 | self.wd = curpath | |
| 87 | 88 | break | |
| 88 | 89 | gitpath = os.path.join(curpath, '.git') | |
| 89 | 90 | if is_git_dir(gitpath): | |
| 90 | - self.bare = False | ||
| 91 | 91 | self.path = gitpath | |
| 92 | 92 | self.wd = curpath | |
| 93 | 93 | break | |
| 94 | 94 | curpath, dummy = os.path.split(curpath) | |
| 95 | 95 | if not dummy: | |
| 96 | 96 | break | |
| 97 | - | ||
| 97 | + # END while curpath | ||
| 98 | + | ||
| 99 | + self._bare = False | ||
| 100 | + try: | ||
| 101 | + self._bare = self.config_reader("repository").getboolean('core','bare') | ||
| 102 | + except Exception: | ||
| 103 | + # lets not assume the option exists, although it should | ||
| 104 | + pass | ||
| 105 | + | ||
| 98 | 106 | if self.path is None: | |
| 99 | 107 | raise InvalidGitRepositoryError(epath) | |
| 100 | 108 | ||
@@ -113,6 +121,15 @@ def _set_description(self, descr): | |||
| 113 | 121 | doc="the project's description") | |
| 114 | 122 | del _get_description | |
| 115 | 123 | del _set_description | |
| 124 | + | ||
| 125 | + | ||
| 126 | + @property | ||
| 127 | + def bare(self): | ||
| 128 | + """ | ||
| 129 | + Returns | ||
| 130 | + True if the repository is bare | ||
| 131 | + """ | ||
| 132 | + return self._bare | ||
| 116 | 133 | ||
| 117 | 134 | @property | |
| 118 | 135 | def heads(self): | |
@@ -194,8 +211,7 @@ def _get_config_path(self, config_level ): | |||
| 194 | 211 | ||
| 195 | 212 | raise ValueError( "Invalid configuration level: %r" % config_level ) | |
| 196 | 213 | ||
| 197 | - @property | ||
| 198 | - def config_reader(self): | ||
| 214 | + def config_reader(self, config_level=None): | ||
| 199 | 215 | """ | |
| 200 | 216 | Returns | |
| 201 | 217 | GitConfigParser allowing to read the full git configuration, but not to write it | |
@@ -205,8 +221,18 @@ def config_reader(self): | |||
| 205 | 221 | ||
| 206 | 222 | NOTE: On windows, system configuration cannot currently be read as the path is | |
| 207 | 223 | unknown, instead the global path will be used. | |
| 208 | - """ | ||
| 209 | - files = [ self._get_config_path(f) for f in self.config_level ] | ||
| 224 | + | ||
| 225 | + ``config_level`` | ||
| 226 | + For possible values, see config_writer method | ||
| 227 | + If None, all applicable levels will be used. Specify a level in case | ||
| 228 | + you know which exact file you whish to read to prevent reading multiple files for | ||
| 229 | + instance | ||
| 230 | + """ | ||
| 231 | + files = None | ||
| 232 | + if config_level is None: | ||
| 233 | + files = [ self._get_config_path(f) for f in self.config_level ] | ||
| 234 | + else: | ||
| 235 | + files = [ self._get_config_path(config_level) ] | ||
| 210 | 236 | return GitConfigParser(files, read_only=True) | |
| 211 | 237 | ||
| 212 | 238 | def config_writer(self, config_level="repository"): | |
@@ -393,7 +419,7 @@ def is_dirty(self, index=True, working_tree=True, untracked_files=False): | |||
| 393 | 419 | like a git-status without untracked files, hence it is dirty if the | |
| 394 | 420 | index or the working copy have changes. | |
| 395 | 421 | """ | |
| 396 | - if self.bare: | ||
| 422 | + if self._bare: | ||
| 397 | 423 | # Bare repositories with no associated working directory are | |
| 398 | 424 | # always consired to be clean. | |
| 399 | 425 | return False | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -91,6 +91,9 @@ def test_init(self, git, repo): | |||
| 91 | 91 | ||
| 92 | 92 | assert_true(git.called) | |
| 93 | 93 | assert_true(repo.called) | |
| 94 | + | ||
| 95 | + def test_bare_property(self): | ||
| 96 | + self.repo.bare | ||
| 94 | 97 | ||
| 95 | 98 | @patch_object(Repo, '__init__') | |
| 96 | 99 | @patch_object(Git, '_call_process') | |
@@ -156,19 +159,19 @@ def test_repr(self): | |||
| 156 | 159 | assert_equal('<git.Repo "%s">' % path, repr(self.repo)) | |
| 157 | 160 | ||
| 158 | 161 | def test_is_dirty_with_bare_repository(self): | |
| 159 | - self.repo.bare = True | ||
| 162 | + self.repo._bare = True | ||
| 160 | 163 | assert_false(self.repo.is_dirty) | |
| 161 | 164 | ||
| 162 | 165 | def test_is_dirty(self): | |
| 163 | - self.repo.bare = False | ||
| 166 | + self.repo._bare = False | ||
| 164 | 167 | for index in (0,1): | |
| 165 | 168 | for working_tree in (0,1): | |
| 166 | 169 | for untracked_files in (0,1): | |
| 167 | 170 | assert self.repo.is_dirty in (True, False) | |
| 168 | 171 | # END untracked files | |
| 169 | 172 | # END working tree | |
| 170 | 173 | # END index | |
| 171 | - self.repo.bare = True | ||
| 174 | + self.repo._bare = True | ||
| 172 | 175 | assert self.repo.is_dirty == False | |
| 173 | 176 | ||
| 174 | 177 | @patch_object(Git, '_call_process') | |
@@ -236,7 +239,9 @@ def test_untracked_files(self): | |||
| 236 | 239 | assert len(self.repo.untracked_files) == (num_recently_untracked - len(files)) | |
| 237 | 240 | ||
| 238 | 241 | def test_config_reader(self): | |
| 239 | - reader = self.repo.config_reader | ||
| 242 | + reader = self.repo.config_reader() # all config files | ||
| 243 | + assert reader.read_only | ||
| 244 | + reader = self.repo.config_reader("repository") # single config file | ||
| 240 | 245 | assert reader.read_only | |
| 241 | 246 | ||
| 242 | 247 | def test_config_writer(self): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,6 +7,7 @@ | |||
| 7 | 7 | import os | |
| 8 | 8 | from test.testlib import * | |
| 9 | 9 | from git import * | |
| 10 | + from git.cmd import dashify | ||
| 10 | 11 | ||
| 11 | 12 | class TestUtils(object): | |
| 12 | 13 | def setup(self): | |
| Back | FazBrowse Home | New Git URL |
0 commit comments