diff options
author | Mike Frysinger <vapier@google.com> | 2020-02-19 15:50:00 -0500 |
---|---|---|
committer | Mike Frysinger <vapier@google.com> | 2020-02-19 23:44:10 +0000 |
commit | f81c72ed7727ca408d1859a86c56b532a8de8d59 (patch) | |
tree | 9cdd3f23feed26c922528e8d1db86c3ebde03cc8 /project.py | |
parent | 77b4397a7376fe52fe0725ed538891c89da161ed (diff) | |
download | git-repo-f81c72ed7727ca408d1859a86c56b532a8de8d59.tar.gz |
project: set core.repositoryFormatVersion=1 when using extensions
When using extensions, make sure we set the git repo format version
so git knows to check the extension compatibility. We can add a
helper to the Project API to simplify this and make it foolproof.
Change-Id: I9ab6c32d92fe2b8e5df6e2b080ca71556332e909
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/256035
Tested-by: Mike Frysinger <vapier@google.com>
Reviewed-by: Jonathan Nieder <jrn@google.com>
Diffstat (limited to 'project.py')
-rw-r--r-- | project.py | 22 |
1 files changed, 20 insertions, 2 deletions
@@ -2186,6 +2186,24 @@ class Project(object): | |||
2186 | return result | 2186 | return result |
2187 | 2187 | ||
2188 | # Direct Git Commands ## | 2188 | # Direct Git Commands ## |
2189 | def EnableRepositoryExtension(self, key, value='true', version=1): | ||
2190 | """Enable git repository extension |key| with |value|. | ||
2191 | |||
2192 | Args: | ||
2193 | key: The extension to enabled. Omit the "extensions." prefix. | ||
2194 | value: The value to use for the extension. | ||
2195 | version: The minimum git repository version needed. | ||
2196 | """ | ||
2197 | # Make sure the git repo version is new enough already. | ||
2198 | found_version = self.config.GetInt('core.repositoryFormatVersion') | ||
2199 | if found_version is None: | ||
2200 | found_version = 0 | ||
2201 | if found_version < version: | ||
2202 | self.config.SetString('core.repositoryFormatVersion', str(version)) | ||
2203 | |||
2204 | # Enable the extension! | ||
2205 | self.config.SetString('extensions.%s' % (key,), value) | ||
2206 | |||
2189 | def _CheckForImmutableRevision(self): | 2207 | def _CheckForImmutableRevision(self): |
2190 | try: | 2208 | try: |
2191 | # if revision (sha or tag) is not present then following function | 2209 | # if revision (sha or tag) is not present then following function |
@@ -2314,7 +2332,7 @@ class Project(object): | |||
2314 | if clone_filter: | 2332 | if clone_filter: |
2315 | git_require((2, 19, 0), fail=True, msg='partial clones') | 2333 | git_require((2, 19, 0), fail=True, msg='partial clones') |
2316 | cmd.append('--filter=%s' % clone_filter) | 2334 | cmd.append('--filter=%s' % clone_filter) |
2317 | self.config.SetString('extensions.partialclone', self.remote.name) | 2335 | self.EnableRepositoryExtension('partialclone', self.remote.name) |
2318 | 2336 | ||
2319 | if depth: | 2337 | if depth: |
2320 | cmd.append('--depth=%s' % depth) | 2338 | cmd.append('--depth=%s' % depth) |
@@ -2630,7 +2648,7 @@ class Project(object): | |||
2630 | # Enable per-worktree config file support if possible. This is more a | 2648 | # Enable per-worktree config file support if possible. This is more a |
2631 | # nice-to-have feature for users rather than a hard requirement. | 2649 | # nice-to-have feature for users rather than a hard requirement. |
2632 | if self.use_git_worktrees and git_require((2, 19, 0)): | 2650 | if self.use_git_worktrees and git_require((2, 19, 0)): |
2633 | self.config.SetString('extensions.worktreeConfig', 'true') | 2651 | self.EnableRepositoryExtension('worktreeConfig') |
2634 | 2652 | ||
2635 | # If we have a separate directory to hold refs, initialize it as well. | 2653 | # If we have a separate directory to hold refs, initialize it as well. |
2636 | if self.objdir != self.gitdir: | 2654 | if self.objdir != self.gitdir: |