diff options
author | Richard Maw <richard.maw@codethink.co.uk> | 2014-08-21 12:58:46 +0000 |
---|---|---|
committer | Richard Maw <richard.maw@codethink.co.uk> | 2014-08-21 16:04:41 +0000 |
commit | 23e86c643a82731aba6561321b8bb5b168e80598 (patch) | |
tree | 4e50e39d30b775d3e911cfd375ec4bbcfa793eb4 /morphlib/sysbranchdir_tests.py | |
parent | 35f3a8779a316ed6a44ce5bb62bea9e2d7c67a16 (diff) | |
download | morph-23e86c643a82731aba6561321b8bb5b168e80598.tar.gz |
Prevent git-replace refs affecting git operations
We assumed that the sha1 of the tree of the commit of the ref we care
about was sufficient to cache, but `git replace` means that you need to
know the state of other branches too, since anything in refs/replace can
completely change what the tree you check-out is.
This behaviour can be disabled globally by setting
GIT_NO_REPLACE_OBJECTS, so we're going to do that.
If we need to integrate a project that uses git-replace to change the
contents of their git trees then we could support that by:
if any(refs/replace/*):
potentially_replacable_objects = [
`git rev-parse HEAD`,
`git rev-parse HEAD^{commit}`,
`git rev-parse HEAD^{tree}`]
potentially_replacable_objects.extend(
`git ls-tree -r HEAD | awk '{print $3}'`)
# NOTE: doesn't handle submodules, and you'd need to expand this
# set whenever you process a replacement
for object in refs/replace/*:
if basename(object) not in potentially_replacable_objects: continue
cache_key['replacements'][basename(object)] = `git rev-parse $object`
If we were to support this would need to traverse the tree anyway, doing
replacements, so we may as well use libgit to do the checkout anyway,
and list which replacements were used.
However, since the expected use-case of `git replace` is as a better way
to do history grafting, we're unlikely to need it, as it would only have
any effect if it replaced the commit we were using with a different one.
Rubber-stamped-by: Daniel Silverstone
Diffstat (limited to 'morphlib/sysbranchdir_tests.py')
-rw-r--r-- | morphlib/sysbranchdir_tests.py | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/morphlib/sysbranchdir_tests.py b/morphlib/sysbranchdir_tests.py index 8b40f69c..1aca54e6 100644 --- a/morphlib/sysbranchdir_tests.py +++ b/morphlib/sysbranchdir_tests.py @@ -50,16 +50,17 @@ class SystemBranchDirectoryTests(unittest.TestCase): self.path = path os.mkdir(self.path) - cliapp.runcmd(['git', 'init', self.path]) + morphlib.git.gitcmd(cliapp.runcmd, 'init', self.path) with open(os.path.join(self.path, 'filename'), 'w') as f: f.write('this is a file\n') - cliapp.runcmd(['git', 'add', 'filename'], cwd=self.path) - cliapp.runcmd( - ['git', 'commit', '-m', 'initial'], cwd=self.path) + morphlib.git.gitcmd(cliapp.runcmd, 'add', 'filename', + cwd=self.path) + morphlib.git.gitcmd(cliapp.runcmd, 'commit', '-m', 'initial', + cwd=self.path) def clone_checkout(self, ref, target_dir): - cliapp.runcmd( - ['git', 'clone', '-b', ref, self.path, target_dir]) + morphlib.git.gitcmd(cliapp.runcmd, 'clone', '-b', ref, + self.path, target_dir) subdir = tempfile.mkdtemp(dir=self.tempdir) path = os.path.join(subdir, 'foo') |