diff options
author | Raman Tenneti <rtenneti@google.com> | 2021-02-07 16:30:27 -0800 |
---|---|---|
committer | Raman Tenneti <rtenneti@google.com> | 2021-02-08 17:34:55 +0000 |
commit | 8d43dea6ea4b7d1664632e555e207f617e54657b (patch) | |
tree | 5632d2a6e5d6e8ccff305e84734665f2f1b4fb04 /git_superproject.py | |
parent | 1fd7bc24386dbba3a9454bb49c702a642f00e34c (diff) | |
download | git-repo-8d43dea6ea4b7d1664632e555e207f617e54657b.tar.gz |
sync: pass --bare option when doing git clone of superproject.v2.12.1
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>
Diffstat (limited to 'git_superproject.py')
-rw-r--r-- | git_superproject.py | 42 |
1 files changed, 26 insertions, 16 deletions
diff --git a/git_superproject.py b/git_superproject.py index 465d1f87..57a3a533 100644 --- a/git_superproject.py +++ b/git_superproject.py | |||
@@ -29,6 +29,9 @@ from error import BUG_REPORT_URL, GitError | |||
29 | from git_command import GitCommand | 29 | from git_command import GitCommand |
30 | import platform_utils | 30 | import platform_utils |
31 | 31 | ||
32 | _SUPERPROJECT_GIT_NAME = 'superproject.git' | ||
33 | _SUPERPROJECT_MANIFEST_NAME = 'superproject_override.xml' | ||
34 | |||
32 | 35 | ||
33 | class Superproject(object): | 36 | class Superproject(object): |
34 | """Get SHAs from superproject. | 37 | """Get SHAs from superproject. |
@@ -48,8 +51,9 @@ class Superproject(object): | |||
48 | self._superproject_dir = superproject_dir | 51 | self._superproject_dir = superproject_dir |
49 | self._superproject_path = os.path.join(self._repodir, superproject_dir) | 52 | self._superproject_path = os.path.join(self._repodir, superproject_dir) |
50 | self._manifest_path = os.path.join(self._superproject_path, | 53 | self._manifest_path = os.path.join(self._superproject_path, |
51 | 'superproject_override.xml') | 54 | _SUPERPROJECT_MANIFEST_NAME) |
52 | self._work_git = os.path.join(self._superproject_path, 'superproject') | 55 | self._work_git = os.path.join(self._superproject_path, |
56 | _SUPERPROJECT_GIT_NAME) | ||
53 | 57 | ||
54 | @property | 58 | @property |
55 | def project_shas(self): | 59 | def project_shas(self): |
@@ -66,8 +70,9 @@ class Superproject(object): | |||
66 | Returns: | 70 | Returns: |
67 | True if 'git clone <url> <branch>' is successful, or False. | 71 | True if 'git clone <url> <branch>' is successful, or False. |
68 | """ | 72 | """ |
69 | os.mkdir(self._superproject_path) | 73 | if not os.path.exists(self._superproject_path): |
70 | cmd = ['clone', url, '--filter', 'blob:none'] | 74 | os.mkdir(self._superproject_path) |
75 | cmd = ['clone', url, '--filter', 'blob:none', '--bare'] | ||
71 | if branch: | 76 | if branch: |
72 | cmd += ['--branch', branch] | 77 | cmd += ['--branch', branch] |
73 | p = GitCommand(None, | 78 | p = GitCommand(None, |
@@ -84,15 +89,17 @@ class Superproject(object): | |||
84 | return False | 89 | return False |
85 | return True | 90 | return True |
86 | 91 | ||
87 | def _Pull(self): | 92 | def _Fetch(self): |
88 | """Do a 'git pull' to to fetch the latest content. | 93 | """Do a 'git fetch' to to fetch the latest content. |
89 | 94 | ||
90 | Returns: | 95 | Returns: |
91 | True if 'git pull <branch>' is successful, or False. | 96 | True if 'git fetch' is successful, or False. |
92 | """ | 97 | """ |
93 | if not os.path.exists(self._work_git): | 98 | if not os.path.exists(self._work_git): |
94 | raise GitError('git pull missing drectory: %s' % self._work_git) | 99 | print('git fetch missing drectory: %s' % self._work_git, |
95 | cmd = ['pull'] | 100 | file=sys.stderr) |
101 | return False | ||
102 | cmd = ['fetch', 'origin', '+refs/heads/*:refs/heads/*', '--prune'] | ||
96 | p = GitCommand(None, | 103 | p = GitCommand(None, |
97 | cmd, | 104 | cmd, |
98 | cwd=self._work_git, | 105 | cwd=self._work_git, |
@@ -100,7 +107,7 @@ class Superproject(object): | |||
100 | capture_stderr=True) | 107 | capture_stderr=True) |
101 | retval = p.Wait() | 108 | retval = p.Wait() |
102 | if retval: | 109 | if retval: |
103 | print('repo: error: git pull call failed with return code: %r, stderr: %r' % | 110 | print('repo: error: git fetch call failed with return code: %r, stderr: %r' % |
104 | (retval, p.stderr), file=sys.stderr) | 111 | (retval, p.stderr), file=sys.stderr) |
105 | return False | 112 | return False |
106 | return True | 113 | return True |
@@ -114,7 +121,9 @@ class Superproject(object): | |||
114 | data: data returned from 'git ls-tree -r HEAD' instead of None. | 121 | data: data returned from 'git ls-tree -r HEAD' instead of None. |
115 | """ | 122 | """ |
116 | if not os.path.exists(self._work_git): | 123 | if not os.path.exists(self._work_git): |
117 | raise GitError('git ls-tree. Missing drectory: %s' % self._work_git) | 124 | print('git ls-tree missing drectory: %s' % self._work_git, |
125 | file=sys.stderr) | ||
126 | return None | ||
118 | data = None | 127 | data = None |
119 | cmd = ['ls-tree', '-z', '-r', 'HEAD'] | 128 | cmd = ['ls-tree', '-z', '-r', 'HEAD'] |
120 | p = GitCommand(None, | 129 | p = GitCommand(None, |
@@ -136,18 +145,19 @@ class Superproject(object): | |||
136 | """Get SHAs for all projects from superproject and save them in _project_shas. | 145 | """Get SHAs for all projects from superproject and save them in _project_shas. |
137 | 146 | ||
138 | Args: | 147 | Args: |
139 | url: superproject's url to be passed to git clone or pull. | 148 | url: superproject's url to be passed to git clone or fetch. |
140 | branch: The branchname to be passed as argument to git clone or pull. | 149 | branch: The branchname to be passed as argument to git clone or fetch. |
141 | 150 | ||
142 | Returns: | 151 | Returns: |
143 | A dictionary with the projects/SHAs instead of None. | 152 | A dictionary with the projects/SHAs instead of None. |
144 | """ | 153 | """ |
145 | if not url: | 154 | if not url: |
146 | raise ValueError('url argument is not supplied.') | 155 | raise ValueError('url argument is not supplied.') |
156 | |||
147 | do_clone = True | 157 | do_clone = True |
148 | if os.path.exists(self._superproject_path): | 158 | if os.path.exists(self._superproject_path): |
149 | if not self._Pull(): | 159 | if not self._Fetch(): |
150 | # If pull fails due to a corrupted git directory, then do a git clone. | 160 | # If fetch fails due to a corrupted git directory, then do a git clone. |
151 | platform_utils.rmtree(self._superproject_path) | 161 | platform_utils.rmtree(self._superproject_path) |
152 | else: | 162 | else: |
153 | do_clone = False | 163 | do_clone = False |
@@ -208,7 +218,7 @@ class Superproject(object): | |||
208 | manifest: A Manifest object that is to be written to a file. | 218 | manifest: A Manifest object that is to be written to a file. |
209 | projects: List of projects whose revisionId needs to be updated. | 219 | projects: List of projects whose revisionId needs to be updated. |
210 | url: superproject's url to be passed to git clone or fetch. | 220 | url: superproject's url to be passed to git clone or fetch. |
211 | branch: The branchname to be passed as argument to git clone or pull. | 221 | branch: The branchname to be passed as argument to git clone or fetch. |
212 | 222 | ||
213 | Returns: | 223 | Returns: |
214 | manifest_path: Path name of the overriding manfiest file instead of None. | 224 | manifest_path: Path name of the overriding manfiest file instead of None. |