blob: f8153445df045cff73ab8163d69cc61debf4721e [file] [log] [blame]
Antoine Mussobfd8f2a2014-09-23 15:31:40 +02001#!/usr/bin/env python
2
3# Copyright 2012 Hewlett-Packard Development Company, L.P.
4# Copyright 2014 Wikimedia Foundation Inc.
5#
6# Licensed under the Apache License, Version 2.0 (the "License"); you may
7# not use this file except in compliance with the License. You may obtain
8# a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15# License for the specific language governing permissions and limitations
16# under the License.
17
18import logging
19import os
20
21import git
22
23from zuul.merger.merger import Repo
24from tests.base import ZuulTestCase
25
Antoine Mussobfd8f2a2014-09-23 15:31:40 +020026
27class TestMergerRepo(ZuulTestCase):
28
29 log = logging.getLogger("zuul.test.merger.repo")
Paul Belanger83481b32016-11-13 19:00:23 -050030 tenant_config_file = 'config/single-tenant/main.yaml'
Antoine Mussobfd8f2a2014-09-23 15:31:40 +020031 workspace_root = None
32
33 def setUp(self):
Paul Belanger83481b32016-11-13 19:00:23 -050034 super(TestMergerRepo, self).setUp()
35 self.workspace_root = os.path.join(self.test_root, 'workspace')
Antoine Mussobfd8f2a2014-09-23 15:31:40 +020036
37 def test_ensure_cloned(self):
38 parent_path = os.path.join(self.upstream_root, 'org/project1')
39
40 # Forge a repo having a submodule
41 parent_repo = git.Repo(parent_path)
42 parent_repo.git.submodule('add', os.path.join(
43 self.upstream_root, 'org/project2'), 'subdir')
44 parent_repo.index.commit('Adding project2 as a submodule in subdir')
45 # git 1.7.8 changed .git from being a directory to a file pointing
46 # to the parent repository /.git/modules/*
47 self.assertTrue(os.path.exists(
48 os.path.join(parent_path, 'subdir', '.git')),
49 msg='.git file in submodule should be a file')
50
51 work_repo = Repo(parent_path, self.workspace_root,
52 'none@example.org', 'User Name')
53 self.assertTrue(
54 os.path.isdir(os.path.join(self.workspace_root, 'subdir')),
55 msg='Cloned repository has a submodule placeholder directory')
56 self.assertFalse(os.path.exists(
57 os.path.join(self.workspace_root, 'subdir', '.git')),
58 msg='Submodule is not initialized')
59
60 sub_repo = Repo(
61 os.path.join(self.upstream_root, 'org/project2'),
62 os.path.join(self.workspace_root, 'subdir'),
63 'none@example.org', 'User Name')
64 self.assertTrue(os.path.exists(
65 os.path.join(self.workspace_root, 'subdir', '.git')),
66 msg='Cloned over the submodule placeholder')
67
68 self.assertEquals(
69 os.path.join(self.upstream_root, 'org/project1'),
70 work_repo.createRepoObject().remotes[0].url,
71 message="Parent clone still point to upstream project1")
72
73 self.assertEquals(
74 os.path.join(self.upstream_root, 'org/project2'),
75 sub_repo.createRepoObject().remotes[0].url,
76 message="Sub repository points to upstream project2")