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 <rtenneti@google.com>
Change-Id: I7d2b609ac2f927c94701757aa1502ba236afe7c0
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/296342
Reviewed-by: Mike Frysinger <vapier@google.com>
This commit is contained in:
Raman Tenneti 2021-02-08 13:27:41 -08:00
parent 8d43dea6ea
commit ce64e3d47b

View File

@ -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 <branch>'.
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)