예제 #1
0
def main(oldname, newname):
    status = Status()
    if status:
        sys.exit(colors.red('Uncommitted changes, aborting'))
    btree = Branches()
    if newname in btree:
        sys.exit(colors.red(f'"{newname}" already exists'))
    if oldname not in btree:
        os.system('git branch -l')
        sys.exit(colors.red(f'"{oldname}" doesnt exist'))

    shell.run(f'git branch -m {newname}',
              f'git push origin :{oldname} {newname}',
              f'git push origin -u {newname}')
예제 #2
0
def main():
    status = Status()
    if status:
        sys.exit(colors.red('Uncommitted changes, aborting'))
    btree = Branches()
    versionbranch = btree.version
    if not versionbranch:
        print(colors.yellow("Couldn't find version branch"))
        if not prompt.confirm('Checkout master?'):
            sys.exit()
        branch = 'master'
    else:
        branch = versionbranch

    currbranch = btree.current

    if currbranch == branch:
        print(colors.yellow(f'Already on version branch: {branch}'))
        if not prompt.confirm('Pull?'):
            sys.exit()
        if git.pull() == 1:
            print(colors.yellow(f"git pull failed"))

    shell.run(f'git checkout {branch}')
    if git.pull() == 1:
        print(colors.yellow(f"git pull failed"))
예제 #3
0
def main(paths):
    print(f'main({", ".join(paths)})')
    # TODO: see if exists in status
    if not paths:
        sys.exit(colors.red('no values! exiting'))

    cmds = []
    gitignore = Gitignore()
    status = Status()
    existing_paths = []
    for p in paths:
        breakpoint()
        path = status.search(p, noprompt=False)
        if not path:
            yellowprint(f"status.search({p}) return None, skipping")
            continue
        if not path.exists():
            yellowprint(f"{p} does not exist, skipping")
            continue

        # exists
        if path.is_dir():
            cmds.append(f'git rm -r --cached {path}')
        else:
            cmds.append(f'git rm --cached {path}')

        existing_paths.append(path)

    if not cmds:
        sys.exit(colors.red('no values to rm, exiting'))

    shell.run(*cmds, raiseexc=False)
    if prompt.confirm(f'try to ignore {len(existing_paths)} values?'):
        gitignore.write(existing_paths)

    commitmsg = f'Removed from cache: ' + ', '.join(map(str, paths))
    answer = prompt.generic(f'commit and push?',
                            f'yes, commit with "{commitmsg}"',
                            'custom commit message',
                            flowopts='quit')
    if answer is not True:
        commitmsg = prompt.generic('commit msg:', free_input=True)[1]
    shell.run(f'git commit -am "{commitmsg}"')
    git.push()
예제 #4
0
파일: repo.py 프로젝트: giladbarnea/IGit
 def name(self) -> str:
     if not self._name:
         regex = r'(?<=/)[\w\d.-]*(?=\.git)'
         match = re.search(regex, self.url)
         if not match:
             sys.exit(
                 colors.red(
                     f"regex: {regex} no match to self.url: '{self.url}'"))
         self._name = match.group()
     return self._name
예제 #5
0
def main(name):
    btree = Branches()
    if name not in btree:
        print(colors.yellow(f"didn't find {name} in branches"))
        name = btree.search(name)
    if name == btree.current:
        # TODO: gco - then continue
        sys.exit(colors.red(f'"{name}" is current branch'))
    if name == btree.version:
        if not prompt.confirm(f'{name} is version branch, continue?'):
            sys.exit()
    shell.run(f'git branch -D {name}', f'git push origin --delete {name}')
예제 #6
0
    def search(self, keyword: Union[str, ExPath], *, noprompt=True) -> ExPath:
        """Tries to return an ExPath in status.
         First assumes `keyword` is an exact file (str or ExPath), and if fails, uses `search` module.
         @param noprompt: specify False to allow using search_and_prompt(keyword, file) in case nothing matched earlier.
         """
        darkprint(f'Status.search({repr(keyword)}) |')
        path = ExPath(keyword)
        for file in self.files:
            if file == path:
                return file
        has_suffix = path.has_file_suffix()
        has_slash = '/' in keyword
        has_regex = regex.has_regex(keyword)
        darkprint(f'\t{has_suffix = }, {has_slash = }, {has_regex = }')
        if has_suffix:
            files = self.files
        else:
            files = [f.with_suffix('') for f in self.files]

        if has_regex:
            for expath in files:
                if re.search(keyword, str(expath)):
                    return expath
        if has_slash:
            darkprint(
                f"looking for the nearest match among status paths for: '{keyword}'"
            )
            return ExPath(search.nearest(keyword, files))
        darkprint(
            f"looking for a matching part among status paths ({'with' if has_suffix else 'without'} suffixes...) for: '{keyword}'"
        )
        for f in files:
            # TODO: integrate into git.search somehow
            for i, part in enumerate(f.parts):
                if part == keyword:
                    ret = ExPath(os.path.join(*f.parts[0:i + 1]))
                    return ret
        if noprompt:
            return None
        darkprint(
            f"didn't find a matching part, calling search_and_prompt()...")
        choice = search_and_prompt(keyword, [str(f) for f in files],
                                   criterion='substring')
        if choice:
            return ExPath(choice)

        prompt.generic(colors.red(f"'{keyword}' didn't match anything"),
                       flowopts=True)
예제 #7
0
def main(src_hash_or_index, target_hash_or_index):
    # TODO: support a4af4e7..0c6dd4a
    if src_hash_or_index:
        if not target_hash_or_index:
            ctree = Commits()
            src = ctree.current
            target = src_hash_or_index
        else:
            src = src_hash_or_index
            target = target_hash_or_index
    else:
        # TODO: compare current to one before
        sys.exit(colors.red(f'current commit is {Commits().current}'))
    repo = Repo()
    webbrowser.open(
        f"https://{repo.weburl}/branches/compare/{src}%0D{target}#diff")
예제 #8
0
def compare(a, b):
    darkprint(f'compare({repr(a)}, {repr(b)})')
    if a == b:
        sys.exit(colors.red(f'trying to compare a branch to itself: {a}'))
    if a not in btree:
        yellowprint(f'"{a}" not in branches, searching...')
        a = btree.search(a)
    if b not in btree:
        yellowprint(f'"{b}" not in branches, searching...')
        b = btree.search(b)

    repo = Repo()
    if repo.host == 'bitbucket':
        url = f"https://{repo.weburl}/branches/compare/{a}%0D{b}#diff"
    else:
        url = f"https://{repo.weburl}/compare/{a}..{b}"
    webbrowser.open(url)
예제 #9
0
파일: repo.py 프로젝트: giladbarnea/IGit
    def weburl(self) -> str:
        """bitbucket.org/cashdash/reconciliation-testing-tools"""
        if not self._weburl:

            isbitbucket = self.host == 'bitbucket'
            if isbitbucket:
                regex = r'bitbucket.org.*(?=\.git)\b'
            elif self.host == 'github':
                regex = r'github.com.*(?=\.git)\b'
            else:
                print(
                    colors.yellow(
                        f'repo.weburl unspecific self.host: {self.host}'))
                regex = fr'{self.host}.com.*(?=\.git)\b'
            match = re.search(regex, self.url)
            if not match:
                sys.exit(
                    colors.red(
                        f"regex: {regex} no match to self.url: '{self.url}'"))
            weburl = match.group()
            if isbitbucket and ':cashdash' in self.url:
                weburl = weburl.replace(':cashdash', '/cashdash')
            self._weburl = weburl
        return self._weburl