1
0
Fork 1
mirror of https://gitlab.postmarketos.org/postmarketOS/pmbootstrap.git synced 2025-07-13 11:29:46 +03:00

Fix #151: git ambiguous argument error (#531)

We check if origin/HEAD is present. In case that reference is
missing, we show a meaningful error message now, with an explanation
on how to add it. Also moved find_out_of_sync_files_tracked() to
pmb.helpers.git
This commit is contained in:
Oliver Smith 2017-09-25 22:05:29 +00:00 committed by GitHub
parent 1416ce241d
commit e60eee7dfa
3 changed files with 53 additions and 6 deletions

View file

@ -22,6 +22,7 @@ import os
import pmb.build
import pmb.chroot.apk
import pmb.config
import pmb.helpers.run
def clone(args, repo_name):
@ -44,3 +45,34 @@ def rev_parse(args, revision="HEAD"):
logging.warning("WARNING: Failed to determine revision of git repository at " + args.aports)
return ""
return rev.rstrip()
def find_out_of_sync_files_tracked(args, git_root):
"""
Find all files tracked by git, that are are out of sync with origin/HEAD.
In some cases (when you rename a remote or add it manually), origin/HEAD
does not exist. We check for that to provide a meaningful error message
instead of a confusing crash (see #151).
See also: <https://stackoverflow.com/a/17639471>
"""
# Return changed files compared to origin/HEAD when it exists
ret = pmb.helpers.run.user(args, ["git", "show-ref",
"refs/remotes/origin/HEAD"],
working_dir=git_root, return_stdout=True,
check=False)
if ret and "refs/remotes/origin/HEAD" in ret:
return pmb.helpers.run.user(args, ["git", "diff", "--name-only",
"origin"], working_dir=git_root,
return_stdout=True)
# Meaningful error
logging.debug("Output of 'git diff --name-only origin': " + str(ret))
logging.info("See also: <https://github.com/postmarketOS/pmbootstrap/"
"issues/151>")
fix_cmds = ("git symbolic-ref refs/remotes/origin/HEAD refs/remotes/"
"origin/master; git fetch")
raise RuntimeError("Your aports repository does not have the"
" 'origin/HEAD' reference. Please add it by"
" running the following commands inside " +
git_root + ": " + fix_cmds)