sync: pass --bare option when doing git clone of superproject.

Changed "git pull" to "git fetch" as we are using --bare option. Used the
following command to fetch:
  git fetch origin +refs/heads/*:refs/heads/* --prune

Pass --branch argument to Superproject's UpdateProjectsRevisionId function.

Returned False/None when directories don't exist instead of raise
GitError exception from _Fetch and _LsTree functions. The caller of Fetch
does Clone if Fetch fails.

Tested the code with the following commands.

$ ./run_tests -v

Tested the init and sync code by copying all the repo changes into my Android
AOSP checkout and running repo sync with --use-superproject option.

Bug: https://crbug.com/gerrit/13709
Bug: https://crbug.com/gerrit/13707
Tested-by: Raman Tenneti <rtenneti@google.com>
Change-Id: I3e441ecdfc87c735f46eff0eb98efa63cc2eb22a
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/296222
Reviewed-by: Mike Frysinger <vapier@google.com>
This commit is contained in:
Raman Tenneti
2021-02-07 16:30:27 -08:00
parent 1fd7bc2438
commit 8d43dea6ea
3 changed files with 43 additions and 26 deletions

View File

@@ -78,11 +78,11 @@ class SuperprojectTestCase(unittest.TestCase):
with mock.patch.object(self._superproject, '_Clone', return_value=False):
self._superproject._GetAllProjectsSHAs(url='localhost')
def test_superproject_get_project_shas_mock_pull(self):
"""Test with _Pull failing."""
def test_superproject_get_project_shas_mock_fetch(self):
"""Test with _Fetch failing."""
with self.assertRaises(GitError):
with mock.patch.object(self._superproject, '_Clone', return_value=True):
with mock.patch.object(self._superproject, '_Pull', return_value=False):
with mock.patch.object(self._superproject, '_Fetch', return_value=False):
self._superproject._GetAllProjectsSHAs(url='localhost')
def test_superproject_get_project_shas_mock_ls_tree(self):
@@ -141,7 +141,7 @@ class SuperprojectTestCase(unittest.TestCase):
data = ('160000 commit 2c2724cb36cd5a9cec6c852c681efc3b7c6b86ea\tart\x00'
'160000 commit e9d25da64d8d365dbba7c8ee00fe8c4473fe9a06\tbootable/recovery\x00')
with mock.patch.object(self._superproject, '_Clone', return_value=True):
with mock.patch.object(self._superproject, '_Pull', return_value=True):
with mock.patch.object(self._superproject, '_Fetch', return_value=True):
with mock.patch.object(self._superproject, '_LsTree', return_value=data):
# Create temporary directory so that it can write the file.
os.mkdir(self._superproject._superproject_path)