From ce64e3d47b97e54cc7fac3d7577cd53f1857de26 Mon Sep 17 00:00:00 2001 From: Raman Tenneti Date: Mon, 8 Feb 2021 13:27:41 -0800 Subject: [PATCH] superproject: Pass branch to git ls-tree. Tested the code with the following commands. $ ./run_tests -v Bug: [google internal] b/179702819 Bug: https://crbug.com/gerrit/13709 Bug: https://crbug.com/gerrit/13707 Tested-by: Raman Tenneti Change-Id: I7d2b609ac2f927c94701757aa1502ba236afe7c0 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/296342 Reviewed-by: Mike Frysinger --- git_superproject.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/git_superproject.py b/git_superproject.py index 57a3a533..378ede25 100644 --- a/git_superproject.py +++ b/git_superproject.py @@ -112,11 +112,14 @@ class Superproject(object): return False return True - def _LsTree(self): - """Returns the data from 'git ls-tree -r HEAD'. + def _LsTree(self, branch='HEAD'): + """Returns the data from 'git ls-tree -r '. Works only in git repositories. + Args: + branch: The branchname to be passed as argument to git ls-tree. + Returns: data: data returned from 'git ls-tree -r HEAD' instead of None. """ @@ -125,7 +128,8 @@ class Superproject(object): file=sys.stderr) return None data = None - cmd = ['ls-tree', '-z', '-r', 'HEAD'] + cmd = ['ls-tree', '-z', '-r', branch] + p = GitCommand(None, cmd, cwd=self._work_git, @@ -165,7 +169,7 @@ class Superproject(object): if not self._Clone(url, branch): raise GitError('git clone failed for url: %s' % url) - data = self._LsTree() + data = self._LsTree(branch) if not data: raise GitError('git ls-tree failed for url: %s' % url)