Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if retcode != 0 and not args.continue_on_error:
print('')
info("Stopping branching, to continue pass '--continue-on-error'")
except CalledProcessError as err:
# No need for a trackback here, a git call probably failed
print_exc(traceback.format_exc())
error(str(err))
retcode = 1
except Exception as err:
# Unhandled exception, print traceback
print_exc(traceback.format_exc())
error(str(err))
retcode = 2
if retcode == 0:
info("Working branch: " + ansi('boldon') + \
str(get_current_branch()) + ansi('reset'))
sys.exit(retcode)
def get_upstream_meta(upstream_dir, ros_distro):
meta = None
directory = os.getcwd()
with change_directory(upstream_dir):
if get_root() is not None: # If in a git repo
current_branch = get_current_branch()
else:
current_branch = None
name, version, packages = get_package_data(current_branch, quiet=False, release_directory=directory)
meta = {
'name': name,
'version': version,
'type': 'package.xml'
}
return meta
def _trim(config, force, directory):
debug("_trim(" + str(config) + ", " + str(force) + ", " +
str(directory) + ")")
if config['trimbase'] != '':
warning("It looks like the trim operation has already been done, "
"nested trimming is not supported.")
if force:
warning("Proceeding anyways because of '--force'")
else:
warning("If you would like to continue anyways use '--force'")
return None
current_branch = get_current_branch(directory)
if current_branch is None:
error("Could not determine current branch.", exit=True)
config['trimbase'] = get_commit_hash(current_branch)
tmp_dir = tempfile.mkdtemp()
try:
# Buckup trim sub directory
git_root = get_root()
sub_dir = os.path.join(git_root, config['trim'])
storage = os.path.join(tmp_dir, config['trim'])
shutil.copytree(sub_dir, storage)
# Clear out any untracked files
execute_command('git clean -fdx', cwd=directory)
# Collect al files (excluding .git)
items = []
for item in os.listdir(git_root):
if item in ['.git', '..', '.']:
def trim(sub_dir=None, force=False, undo=False, directory=None):
# Get the current branch
current_branch = get_current_branch(directory)
# Ensure the current branch is valid
if current_branch is None:
error("Could not determine current branch, are you in a git repo?",
exit=True)
# Construct the patches branch
patches_branch = 'patches/' + current_branch
try:
# See if the patches branch exists
if branch_exists(patches_branch, False, directory=directory):
if not branch_exists(patches_branch, True, directory=directory):
track_branches(patches_branch, directory)
else:
error("No patches branch (" + patches_branch + ") found, cannot "
"perform trim.", exit=True)
# Get the parent branch from the patches branch
config = get_patch_config(patches_branch, directory=directory)
if create_dst_branch:
info(" " * 22 + "- The specified destination branch, " +
ansi('boldon') + dst + ansi('reset') +
", does not exist; it will be created from the source "
"branch " + ansi('boldon') + src + ansi('reset'))
if create_dst_patches_branch:
info(" " * 22 + "- The destination patches branch, " +
ansi('boldon') + dst_patches + ansi('reset') +
", does not exist; it will be created")
info(" " * 22 + "- The working branch will be set to " +
ansi('boldon') + dst + ansi('reset'))
if not maybe_continue():
error("Answered no to continue, aborting.", exit=True)
# Make changes to the layout
current_branch = get_current_branch(directory)
try:
# Change to the src branch
checkout(src, directory=directory)
# Create the dst branch if needed
if create_dst_branch:
create_branch(dst, changeto=True, directory=directory)
else:
checkout(dst, directory=directory)
# Create the dst patches branch if needed
if create_dst_patches_branch:
create_branch(dst_patches, orphaned=True, directory=directory)
# Create the starting config data if it does not exist
patches_ls = ls_tree(dst_patches, directory=directory)
if 'patches.conf' not in patches_ls:
# Patches config not setup, set it up
config = {
def get_releaser_history(self):
# Assumes that this is called in the target branch
patches_branch = 'patches/' + get_current_branch()
raw = show(patches_branch, 'releaser_history.json')
return None if raw is None else json.loads(raw)
def handle_arguments(self, args):
self.interactive = args.interactive
self.prefix = args.prefix
if args.src is None:
current_branch = get_current_branch()
if current_branch is None:
error("Could not determine current branch.", exit=True)
self.src = current_branch
else:
self.src = args.src
self.name = args.name
self.release_inc = args.release_increment
def get_releaser_history(self):
# Assumes that this is called in the target branch
patches_branch = 'patches/' + get_current_branch()
raw = show(patches_branch, 'releaser_history.json')
return None if raw is None else json.loads(raw)
def remove_patches(directory=None):
# Get the current branch
current_branch = get_current_branch(directory)
if current_branch is None:
error("Could not determine current branch.", exit=True)
# Ensure the current branch is valid
if current_branch is None:
error("Could not determine current branch, are you in a git repo?",
exit=True)
# Construct the patches branch
patches_branch = 'patches/' + current_branch
try:
# See if the patches branch exists
if branch_exists(patches_branch, False, directory=directory):
if not branch_exists(patches_branch, True, directory=directory):
track_branches(patches_branch, directory)
else:
error("No patches branch (" + patches_branch + ") found, cannot "
"remove patches.", exit=True)