Skip to content

Commit beccf19

Browse files
committed
Tried to get rid of held references which could keep a filehandle open. In fact, it didn't work, and ... something else keeps them open. Its odd, its weird, its windows, and I give up on it for now
1 parent ca3fdbe commit beccf19

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

lib/git/objects/submodule/base.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import os
2626
import sys
27+
import time
2728

2829
import shutil
2930

@@ -586,16 +587,26 @@ def remove(self, module=True, force=False, configuration=True, dry_run=False):
586587
if num_branches_with_new_commits == len(rrefs):
587588
raise InvalidGitRepositoryError("Cannot delete module at %s as there are new commits" % mod.working_tree_dir)
588589
# END handle new commits
590+
# have to manually delete references as python's scoping is
591+
# not existing, they could keep handles open ( on windows this is a problem )
592+
if len(rrefs):
593+
del(rref)
594+
#END handle remotes
595+
del(rrefs)
596+
del(remote)
589597
# END for each remote
590598

591599
# gently remove all submodule repositories
592600
for sm in self.children():
593601
sm.remove(module=True, force=False, configuration=False, dry_run=dry_run)
602+
del(sm)
594603
# END for each child-submodule
595604

596605
# finally delete our own submodule
597606
if not dry_run:
598-
shutil.rmtree(mod.working_tree_dir)
607+
wtd = mod.working_tree_dir
608+
del(mod) # release file-handles (windows)
609+
shutil.rmtree(wtd)
599610
# END delete tree if possible
600611
# END handle force
601612
# END handle module deletion

test/git/test_submodule.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -172,14 +172,16 @@ def _do_base_tests(self, rwrepo):
172172

173173

174174
# reset both heads to the previous version, verify that to_latest_revision works
175-
for repo in (csm.module(), sm.module()):
175+
smods = (sm.module(), csm.module())
176+
for repo in smods:
176177
repo.head.reset('HEAD~1', working_tree=1)
177178
# END for each repo to reset
178179

179180
sm.update(recursive=True, to_latest_revision=True)
180-
for repo in (sm.module(), csm.module()):
181+
for repo in smods:
181182
assert repo.head.commit == repo.head.ref.tracking_branch().commit
182183
# END for each repo to check
184+
del(smods)
183185

184186
# if the head is detached, it still works ( but warns )
185187
smref = sm.module().head.ref
@@ -356,8 +358,8 @@ def test_root_module(self, rwrepo):
356358
rm.config_writer()
357359

358360
# deep traversal gitdb / async
359-
rsms = list(rm.traverse())
360-
assert len(rsms) == 2 # gitdb and async, async being a child of gitdb
361+
rsmsp = [sm.path for sm in rm.traverse()]
362+
assert len(rsmsp) == 2 # gitdb and async, async being a child of gitdb
361363

362364
# cannot set the parent commit as root module's path didn't exist
363365
self.failUnlessRaises(ValueError, rm.set_parent_commit, 'HEAD')
@@ -406,9 +408,9 @@ def test_root_module(self, rwrepo):
406408
#================
407409
nsmn = "newsubmodule"
408410
nsmp = "submrepo"
409-
async_url = to_native_path_linux(join_path_native(self.rorepo.working_tree_dir, rsms[0].path, rsms[1].path))
411+
async_url = to_native_path_linux(join_path_native(self.rorepo.working_tree_dir, rsmsp[0], rsmsp[1]))
410412
nsm = Submodule.add(rwrepo, nsmn, nsmp, url=async_url)
411-
csmadded = rwrepo.index.commit("Added submodule")
413+
csmadded = rwrepo.index.commit("Added submodule").hexsha # make sure we don't keep the repo reference
412414
nsm.set_parent_commit(csmadded)
413415
assert nsm.module_exists()
414416
# in our case, the module should not exist, which happens if we update a parent
@@ -439,7 +441,7 @@ def test_root_module(self, rwrepo):
439441
# to the first repository, this way we have a fast checkout, and a completely different
440442
# repository at the different url
441443
nsm.set_parent_commit(csmremoved)
442-
nsmurl = to_native_path_linux(join_path_native(self.rorepo.working_tree_dir, rsms[0].path))
444+
nsmurl = to_native_path_linux(join_path_native(self.rorepo.working_tree_dir, rsmsp[0]))
443445
nsm.config_writer().set_value('url', nsmurl)
444446
csmpathchange = rwrepo.index.commit("changed url")
445447
nsm.set_parent_commit(csmpathchange)

0 commit comments

Comments
 (0)