Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions anyvcs/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ def ls(
entry.type = 'l'
if 'target' in report:
entry.target = self._cat(rev, ename).decode(self.encoding, 'replace')
elif mode == 0o160000:
continue
else:
assert False, 'unexpected output: ' + str(line)
results.append(entry)
Expand Down
53 changes: 53 additions & 0 deletions tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,40 @@ def doSvn(self, test):
pass


class AddSubmodule(Action):
"""Add a repository submodule."""

def __init__(self, repository, path, name=None):
self.path = path
self.repository = repository
self.name = name

def doGit(self, test):
cmd = ['git', 'submodule', 'add', self.repository, self.path]
if not self.name is None:
cmd.extend(['--name', self.name])
test.check_call(cmd)
cmd = ['git', 'commit', '-m', 'add submodule %s' % self.path]
test.check_call(cmd)
test.check_call(['git', 'push', '--set-upstream', 'origin', test.working_head])
time.sleep(1) # git has a 1 second granularity, this keeps logs in order

def doHg(self, test):
path = os.path.join(test.working_path, '.hgsub')
with open(path, 'a') as fp:
fp.write('%s = %s\n' % (self.path, self.repository))
test.check_call(['hg', 'add', '.hgsub'])
test.check_call(['hg', 'commit', '-m', 'add submodule %s' % self.path])
test.check_call(['hg', 'push'])

def doSvn(self, test):
externals = test.check_output(['svn', 'propget', 'svn:externals', '.'])
externals = externals.splitlines()
externals.append('%s %s' % (self.path, 'file://' + self.repository))
externals = '\n'.join(externals)
test.check_call(['svn', 'propset', 'svn:externals', externals, '.'])
test.check_call(['svn', 'commit', '-m', 'add submodule %s' % self.path])

### TEST CASE: EmptyTest ###

class EmptyTest(object):
Expand Down Expand Up @@ -1919,6 +1953,25 @@ def test_pdiff(self):
self.assertEqual(expected, result)


### TEST CASE: SubmoduleTest ###


class SubmoduleTest(object):
@classmethod
def setUpWorkingCopy(cls, working_path):
touch(os.path.join(working_path, 'cats.txt'), 'Shadow')
yield Commit('Start a list of cats')
yield AddSubmodule(cls.main_path, 'submodule')
cls.rev1 = cls.getAbsoluteRev()

def test_ls1(self):
result = normalize_ls(self.repo.ls(self.working_head, '/'))
expected = normalize_ls([
{'path': 'cats.txt', 'type': 'f', 'name': 'cats.txt'},
])
self.assertEqual(expected, result)


if __name__ == '__main__':
unittest.main()

Expand Down
10 changes: 10 additions & 0 deletions tests/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,5 +166,15 @@ class GitEmptyCommitTest(GitTest, common.EmptyCommitTest):
pass


class GitSubmoduleTest(GitTest, common.SubmoduleTest):
def test_ls1(self):
result = common.normalize_ls(self.repo.ls(self.working_head, '/'))
expected = common.normalize_ls([
{'path': '.gitmodules', 'type': 'f', 'name': '.gitmodules'},
{'path': 'cats.txt', 'type': 'f', 'name': 'cats.txt'},
])
self.assertEqual(expected, result)


if __name__ == "__main__":
common.unittest.main()
11 changes: 11 additions & 0 deletions tests/test_hg.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,5 +177,16 @@ class HgCopyTest(HgTest, common.CopyTest):
pass


class HgSubmoduleTest(HgTest, common.SubmoduleTest):
def test_ls1(self):
result = common.normalize_ls(self.repo.ls(self.working_head, '/'))
expected = common.normalize_ls([
{'path': '.hgsub', 'type': 'f', 'name': '.hgsub'},
{'path': '.hgsubstate', 'type': 'f', 'name': '.hgsubstate'},
{'path': 'cats.txt', 'type': 'f', 'name': 'cats.txt'},
])
self.assertEqual(expected, result)


if __name__ == "__main__":
common.unittest.main()
7 changes: 7 additions & 0 deletions tests/test_svn.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,5 +533,12 @@ def test_diff1(self):
self.assertTrue(len(diff) > 0)


class SvnSubmoduleTest(SvnTest, common.SubmoduleTest):
def test_propget1(self):
result = self.repo.propget('svn:externals', self.rev1, '/')
expected = 'submodule file://%s\n' % self.main_path
self.assertEqual(expected, result)


if __name__ == "__main__":
common.unittest.main()