Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def it_should_fail_on_dirty_repositories(config):
expect(gitman.update(depth=1, lock=False)) == True
shell.rm(os.path.join("deps", "gitman_1", ".project"))
try:
with pytest.raises(UncommittedChanges):
gitman.lock()
expect(config.datafile.text).does_not_contain("")
finally:
shell.rm(os.path.join("deps", "gitman_1"))
yn_input = str(
input("Do you want to overwrite? (Y/N)[Y]: ")
).rstrip('\r\n')
if yn_input.lower() == "y" or not yn_input:
break
if yn_input.lower() == "n":
common.show(
f'Skipped update in {os.getcwd()}', color='git_changes'
)
return
else:
if git.changes(self.type, include_untracked=clean):
raise exceptions.UncommittedChanges(
f'Uncommitted changes in {os.getcwd()}'
)
# Fetch the desired revision
if fetch or git.is_fetch_required(self.type, self.rev):
git.fetch(self.type, self.repo, self.name, rev=self.rev)
# Update the working tree to the desired revision
git.update(
self.type, self.repo, self.name, fetch=fetch, clean=clean, rev=self.rev
)
if allow_dirty:
common.show(self.DIRTY, color='git_dirty', log=False)
common.newline()
return path, url, self.DIRTY
if skip_changes:
msg = ("Skipped lock due to uncommitted changes " "in {}").format(
os.getcwd()
)
common.show(msg, color='git_changes')
common.newline()
return path, url, self.DIRTY
msg = "Uncommitted changes in {}".format(os.getcwd())
raise exceptions.UncommittedChanges(msg)
rev = git.get_hash(self.type, _show=True)
common.show(rev, color='git_rev', log=False)
common.newline()
return path, url, rev
if allow_missing:
return os.getcwd(), '', self.UNKNOWN
raise self._invalid_repository
def _run_command(function, args, kwargs):
success = False
exit_message = None
try:
log.debug("Running %s command...", getattr(function, '__name__', 'a'))
success = function(*args, **kwargs)
except KeyboardInterrupt:
log.debug("Command canceled")
except exceptions.UncommittedChanges as exception:
_show_error(exception)
exit_message = (
"Run again with --force/--force-interactive to discard changes "
"or '--skip-changes' to skip this dependency"
)
except exceptions.ScriptFailure as exception:
_show_error(exception)
exit_message = "Run again with '--force' to ignore script errors"
except exceptions.InvalidConfig as exception:
_show_error(exception)
exit_message = "Adapt config and run again"
finally:
if exit_message:
common.show(exit_message, color='message')
common.newline()
if not self.link:
return
log.info("Creating a symbolic link...")
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)