def get_context(user=None): return { 'branch': Git.branch(), 'user': user or Settings.USER, 'project_user': Settings.PROJECT_USER, 'project': Settings.PROJECT, }
def get_context(user=None): return { 'branch': Git.branch(), 'dev_branch': DEV_BRANCHES.get(Settings.PROJECT, 'master'), 'user': user or Settings.USER, 'project_user': Settings.PROJECT_USER, 'project': Settings.PROJECT, }
def rename(old, new=None): if not new: old, new = Git.branch(), old if new in Git.branches(): if not ARGS.force: raise Exception('The branch %s already exists.' % new) Delete.delete(new) Fresh.fresh(new, old) Delete.delete(old)
def get_format_string(name, user, context): def get_url(): full_path = os.getcwd() if name: path, f = os.path.split(name) full_path = os.path.join(full_path, path) if not os.path.exists(full_path): raise ValueError("Path %s doesn't exist." % full_path) if f: for p in os.listdir(full_path): if startswith(p, f): full_path = os.path.join(full_path, p) break else: raise ValueError("Can't find file matching " + name) context['path'] = os.path.relpath(full_path, GitRoot.ROOT) return _URL if not name: return get_url() if name.isdigit(): context['number'] = int(name) return PULL if 'commits'.startswith(name): return _COMMIT if 'diffs'.startswith(name): return _DIFF if 'pull'.startswith(name): return _PULL if 'pending'.startswith(name): if user == Settings.PROJECT_USER: return Pulls.pull_urls()[0] if user == Settings.USER: branch_name = '%s:%s' % (user, Git.branch()) for number, pull in Git.pulls().items(): if pull.branch == branch_name: context['number'] = number return PULL else: return _NEW_PULL raise ValueError("Can't pull for user %s." % user) if 'root'.startswith(name): name = GitRoot.root() return get_url()
def get_url(name='', user=''): if not platform.system() in _OPEN_COMMANDS: raise ValueError("Can't open a URL for platform.system() = " + plat) remotes = get_remotes() origin = remotes.get('origin') or remotes.get('upstream') upstream = remotes.get('upstream') or remotes.get('origin') context = { 'branch': Git.branch(), 'dev_branch': DEV_BRANCHES.get(origin[1], 'master'), 'user': origin[0], 'project_user': upstream[0], 'project': origin[1], } fmt = get_format_string(name, user, context) return fmt.format(**context)
def fresh(branch, base_branch=None): base_branch = base_branch or Git.branch() Git.copy_from_remote(base_branch, branch, 'origin')
def SAFE(): print('Current branch is %s.' % Git.branch())