def _branch_and_checkout(fs, branch_name=None): """Create and check out a new Disdat branch. :param fs: A Disdat file system handle. :param branch_name: A fully-qualified branch name. """ if branch_name is None: _logger.error("Got an invalid branch name '{}'".format(branch_name)) return False if len(branch_name.split('/')) <= 1: _logger.error( "Got a partial branch name: Expected <context>/<branch-name>, got branch name '{}' with no context" .format(branch_name)) return False # These operations are idempotent, so if the context and branch already # exist these become no-ops. fs.branch(branch_name) fs.checkout(branch_name) return True
def context(context_name): """ Create a new context Args: context_name(str): <remote context>/<local context> or <local context> Returns: (int) : 0 if successfully created branch, 1 if branch exists """ fs = _get_fs() return fs.branch(context_name)