diff options
-rw-r--r-- | subcmds/sync.py | 68 |
1 files changed, 20 insertions, 48 deletions
diff --git a/subcmds/sync.py b/subcmds/sync.py index bf1369c0..36b1b0ac 100644 --- a/subcmds/sync.py +++ b/subcmds/sync.py | |||
@@ -20,9 +20,7 @@ import multiprocessing | |||
20 | import netrc | 20 | import netrc |
21 | from optparse import SUPPRESS_HELP | 21 | from optparse import SUPPRESS_HELP |
22 | import os | 22 | import os |
23 | import re | ||
24 | import socket | 23 | import socket |
25 | import subprocess | ||
26 | import sys | 24 | import sys |
27 | import tempfile | 25 | import tempfile |
28 | import time | 26 | import time |
@@ -46,7 +44,7 @@ except ImportError: | |||
46 | return (256, 256) | 44 | return (256, 256) |
47 | 45 | ||
48 | import event_log | 46 | import event_log |
49 | from git_command import GIT, git_require | 47 | from git_command import git_require |
50 | from git_config import GetUrlCookieFile | 48 | from git_config import GetUrlCookieFile |
51 | from git_refs import R_HEADS, HEAD | 49 | from git_refs import R_HEADS, HEAD |
52 | import git_superproject | 50 | import git_superproject |
@@ -956,12 +954,25 @@ def _PostRepoUpgrade(manifest, quiet=False): | |||
956 | def _PostRepoFetch(rp, repo_verify=True, verbose=False): | 954 | def _PostRepoFetch(rp, repo_verify=True, verbose=False): |
957 | if rp.HasChanges: | 955 | if rp.HasChanges: |
958 | print('info: A new version of repo is available', file=sys.stderr) | 956 | print('info: A new version of repo is available', file=sys.stderr) |
959 | print(file=sys.stderr) | 957 | wrapper = Wrapper() |
960 | if not repo_verify or _VerifyTag(rp): | 958 | try: |
961 | syncbuf = SyncBuffer(rp.config) | 959 | rev = rp.bare_git.describe(rp.GetRevisionId()) |
962 | rp.Sync_LocalHalf(syncbuf) | 960 | except GitError: |
963 | if not syncbuf.Finish(): | 961 | rev = None |
964 | sys.exit(1) | 962 | _, new_rev = wrapper.check_repo_rev(rp.gitdir, rev, repo_verify=repo_verify) |
963 | # See if we're held back due to missing signed tag. | ||
964 | current_revid = rp.bare_git.rev_parse('HEAD') | ||
965 | new_revid = rp.bare_git.rev_parse('--verify', new_rev) | ||
966 | if current_revid != new_revid: | ||
967 | # We want to switch to the new rev, but also not trash any uncommitted | ||
968 | # changes. This helps with local testing/hacking. | ||
969 | # If a local change has been made, we will throw that away. | ||
970 | # We also have to make sure this will switch to an older commit if that's | ||
971 | # the latest tag in order to support release rollback. | ||
972 | try: | ||
973 | rp.work_git.reset('--keep', new_rev) | ||
974 | except GitError as e: | ||
975 | sys.exit(str(e)) | ||
965 | print('info: Restarting repo with latest version', file=sys.stderr) | 976 | print('info: Restarting repo with latest version', file=sys.stderr) |
966 | raise RepoChangedException(['--repo-upgraded']) | 977 | raise RepoChangedException(['--repo-upgraded']) |
967 | else: | 978 | else: |
@@ -972,45 +983,6 @@ def _PostRepoFetch(rp, repo_verify=True, verbose=False): | |||
972 | file=sys.stderr) | 983 | file=sys.stderr) |
973 | 984 | ||
974 | 985 | ||
975 | def _VerifyTag(project): | ||
976 | gpg_dir = os.path.expanduser('~/.repoconfig/gnupg') | ||
977 | if not os.path.exists(gpg_dir): | ||
978 | print('warning: GnuPG was not available during last "repo init"\n' | ||
979 | 'warning: Cannot automatically authenticate repo."""', | ||
980 | file=sys.stderr) | ||
981 | return True | ||
982 | |||
983 | try: | ||
984 | cur = project.bare_git.describe(project.GetRevisionId()) | ||
985 | except GitError: | ||
986 | cur = None | ||
987 | |||
988 | if not cur \ | ||
989 | or re.compile(r'^.*-[0-9]{1,}-g[0-9a-f]{1,}$').match(cur): | ||
990 | rev = project.revisionExpr | ||
991 | if rev.startswith(R_HEADS): | ||
992 | rev = rev[len(R_HEADS):] | ||
993 | |||
994 | print(file=sys.stderr) | ||
995 | print("warning: project '%s' branch '%s' is not signed" | ||
996 | % (project.name, rev), file=sys.stderr) | ||
997 | return False | ||
998 | |||
999 | env = os.environ.copy() | ||
1000 | env['GIT_DIR'] = project.gitdir | ||
1001 | env['GNUPGHOME'] = gpg_dir | ||
1002 | |||
1003 | cmd = [GIT, 'tag', '-v', cur] | ||
1004 | result = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, | ||
1005 | env=env, check=False) | ||
1006 | if result.returncode: | ||
1007 | print(file=sys.stderr) | ||
1008 | print(result.stdout, file=sys.stderr) | ||
1009 | print(file=sys.stderr) | ||
1010 | return False | ||
1011 | return True | ||
1012 | |||
1013 | |||
1014 | class _FetchTimes(object): | 986 | class _FetchTimes(object): |
1015 | _ALPHA = 0.5 | 987 | _ALPHA = 0.5 |
1016 | 988 | ||