aboutsummaryrefslogtreecommitdiff
path: root/project.py
diff options
context:
space:
mode:
authorMike Frysinger <vapier@google.com>2020-09-06 15:51:21 -0400
committerMike Frysinger <vapier@google.com>2020-09-09 05:46:07 +0000
commit50a81de2bc9f2074d56c368f651cf9f50c8d8a87 (patch)
treeb72dbba8f5915686c8c10f6de501949003685164 /project.py
parent0501b29e7ae072e0b10ea9ddd913ec6d5975f690 (diff)
downloadrepo-50a81de2bc9f2074d56c368f651cf9f50c8d8a87.tar.gz
init: use the remote default manifest branch
Instead of hardcoding "master" as our default, use the remote server's default branch instead. For most people, this should be the same as "master" already. For projects moving to "main", it means we'll use the new name automatically rather than forcing people to use -b main. For repositories that never set up a default HEAD, we should still use the historical "master" default. Bug: https://crbug.com/gerrit/13339 Change-Id: I4117c81a760c9495f98dbb1111a3e6c127f45eba Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/280799 Reviewed-by: Michael Mortensen <mmortensen@google.com> Tested-by: Mike Frysinger <vapier@google.com>
Diffstat (limited to 'project.py')
-rw-r--r--project.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/project.py b/project.py
index fdbf9e4..80b0cf8 100644
--- a/project.py
+++ b/project.py
@@ -2311,6 +2311,27 @@ class Project(object):
# Enable the extension!
self.config.SetString('extensions.%s' % (key,), value)
+ def ResolveRemoteHead(self, name=None):
+ """Find out what the default branch (HEAD) points to.
+
+ Normally this points to refs/heads/master, but projects are moving to main.
+ Support whatever the server uses rather than hardcoding "master" ourselves.
+ """
+ if name is None:
+ name = self.remote.name
+
+ # The output will look like (NB: tabs are separators):
+ # ref: refs/heads/master HEAD
+ # 5f6803b100bb3cd0f534e96e88c91373e8ed1c44 HEAD
+ output = self.bare_git.ls_remote('-q', '--symref', '--exit-code', name, 'HEAD')
+
+ for line in output.splitlines():
+ lhs, rhs = line.split('\t', 1)
+ if rhs == 'HEAD' and lhs.startswith('ref:'):
+ return lhs[4:].strip()
+
+ return None
+
def _CheckForImmutableRevision(self):
try:
# if revision (sha or tag) is not present then following function