Coverage for gitman/models/source.py : 39%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
"""Wrappers for the dependency configuration files."""
"""A dictionary of `git` and `ln` arguments."""
"""Ensure the source matches the specified revision.""" log.info("Updating source files...")
# Clone the repository if needed if not os.path.exists(self.name): git.clone(self.repo, self.name)
# Enter the working tree shell.cd(self.name) if not git.valid(): raise self._invalid_repository
# Check for uncommitted changes if not force: log.debug("Confirming there are no uncommitted changes...") if git.changes(include_untracked=clean): msg = "Uncommitted changes in {}".format(os.getcwd()) raise exceptions.UncommittedChanges(msg)
# Fetch the desired revision if fetch or self.rev not in (git.get_branch(), git.get_hash(), git.get_tag()): git.fetch(self.repo, self.rev)
# Update the working tree to the desired revision git.update(self.rev, fetch=fetch, clean=clean)
"""Create a link from the target name to the current directory.""" if not self.link: return
log.info("Creating a symbolic link...")
if os.name == 'nt': warnings.warn("Symbolic links are not supported on Windows") return
target = os.path.join(root, self.link) source = os.path.relpath(os.getcwd(), os.path.dirname(target))
if os.path.islink(target): os.remove(target) elif os.path.exists(target): if force: shell.rm(target) else: msg = "Preexisting link location at {}".format(target) raise exceptions.UncommittedChanges(msg)
shell.ln(source, target)
log.info("Running install scripts...")
# Enter the working tree shell.cd(self.name) if not git.valid(): raise self._invalid_repository
# Check for scripts if not self.scripts: common.show("(no scripts to run)", color='shell_info') common.newline() return
# Run all scripts for script in self.scripts: try: lines = shell.call(script, _shell=True) except exceptions.ShellError as exc: common.show(*exc.output, color='shell_error') cmd = exc.program if force: log.debug("Ignored error from call to '%s'", cmd) else: msg = "Command '{}' failed in {}".format(cmd, os.getcwd()) raise exceptions.ScriptFailure(msg) else: common.show(*lines, color='shell_output') common.newline()
"""Get the path and current repository URL and hash."""
shell.cd(self.name) if not git.valid(): raise self._invalid_repository
path = os.getcwd() url = git.get_url() if git.changes(display_status=not allow_dirty, _show=True): if not allow_dirty: msg = "Uncommitted changes in {}".format(os.getcwd()) raise exceptions.UncommittedChanges(msg)
common.show(self.DIRTY, color='git_dirty', log=False) common.newline() return path, url, self.DIRTY else: rev = git.get_hash(_show=True) common.show(rev, color='git_rev', log=False) common.newline() return path, url, rev
else:
raise self._invalid_repository
"""Return a locked version of the current source.""" self.link, self.scripts)
def _invalid_repository(self): path = os.path.join(os.getcwd(), self.name) msg = "Not a valid repository: {}".format(path) return exceptions.InvalidRepository(msg)
def _infer_name(repo): |