Exemple #1
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"))
Exemple #2
0
def main(name):
    btree = Branches()
    if name in btree:
        if not prompt.confirm(f'"{name}" already exists, check it out?'):
            sys.exit()
        shell.run(f'git checkout {name}')
        return git.pull()

    status = Status()
    stash = False
    if status:
        os.system('git status')
        answer = prompt.action('Uncommitted changes',
                               'stash → apply',
                               'just checkout',
                               'reset --hard',
                               flowopts=True)
        if answer == 's':
            stash = True
            shell.run('git stash')
        elif answer == 'r':
            shell.run('git reset --hard')
        else:
            stash = False
    shell.run(f'git checkout -b {name}',
              f'git push --set-upstream origin {name}')
    if stash:
        shell.run('git stash apply')
        from .addcommitpush import main as addcommitpush
        addcommitpush(f'new branch: {name}')
Exemple #3
0
def main(branch):
    btree = Branches()
    if branch:
        if prompt.confirm('search?'):
            branch = btree.search(branch)
    else:
        branch = btree.current
    clip_copy(branch)
Exemple #4
0
 def backup(self, confirm: bool):
     if confirm and not prompt.confirm(f'Backup .gitignore to .gitignore.backup?'):
         print('aborting')
         return False
     absolute = self.file.absolute()
     
     try:
         shell.run(f'cp {absolute} {absolute}.backup', raiseexc='summary')
     except Exception as e:
         if not prompt.confirm('Backup failed, overwrite .gitignore anyway?', flowopts='debug'):
             print('aborting')
             return False
         return True
     else:
         backup = ExPath(f'{absolute}.backup')
         if not backup.exists() and not prompt.confirm(f'Backup command completed without error, but {backup} doesnt exist. overwrite .gitignore anyway?', flowopts='debug'):
             print('aborting')
             return False
         return True
Exemple #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}')
Exemple #6
0
def main(branch):
    status = Status()
    if status:
        if not prompt.confirm('Uncommitted changes, checkout anyway?'):
            print('aborting')
            return
    btree = Branches()
    
    if branch not in btree:
        yellowprint(f'"{branch}" not in branches, searching...')
        branch = btree.search(branch)
    if btree.current == branch:
        yellowprint(f'Already on {branch}')
        return
    if not branch:
        redprint(f"Couldn't find branch")
        return
    shell.run(f'git checkout {branch}')
    if not prompt.confirm('git pull?'):
        print('aborting')
        return
    if git.pull() == 1:
        brightyellowprint(f"git pull failed")
Exemple #7
0
 def unignore(self, path, *, confirm=False, dry_run=False, backup=True):
     path = ExPath(path)
     newvals = []
     found = False
     for ignored in self:
         if ignored == path:
             breakpoint()
             found = True
             continue
         newvals.append(ignored)
     if not found:
         logging.warning(f'Gitignore.unignore(path={path}): not in self. returning')
         return
     
     if confirm and not prompt.confirm(f'Remove {path} from .gitignore?'):
         print('aborting')
         return
     self.write(newvals, verify_paths=False, dry_run=dry_run, backup=backup)
Exemple #8
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()
Exemple #9
0
def main(branch):
    repo = Repo()
    btree = Branches()
    subdomain = url_subdomain(repo)
    url = f'https://{repo.weburl}/{subdomain}'
    if branch:
        # res = requests.get(f'{url}/{branch}')
        # if not res.ok:
        if branch not in btree:
            if prompt.confirm(f'"{branch}" not in branches, search?',
                              flowopts=True):
                branch = btree.search(branch)
            else:
                branch = btree.current
    else:
        branch = btree.current

    url += f'/{branch}'
    return webbrowser.open(url)
Exemple #10
0
def _choose_from_many(collection, *promptargs,
                      **promptkwargs) -> Optional[str]:
    if collection:
        # *  many
        if len(collection) > 1:
            i, choice = prompt.choose(
                f"found {len(collection)} choices, please choose:",
                *collection,
                *promptargs,
                flowopts=True,
                **promptkwargs)
            if choice == Flow.CONTINUE:
                return None
            return collection[i]
        # *  single
        if prompt.confirm(f'found: {collection[0]}. proceed with this?',
                          no='try harder',
                          flowopts=('debug', 'quit')):
            return collection[0]
        return None
    return None
Exemple #11
0
def main(commitmsg: str, dry_run: bool = False):
    status = Status()
    if not status.files:
        if prompt.confirm('No files in status, just push?'):
            if dry_run:
                misc.whiteprint('dry run, not pushing. returning')
                return
            return git.push()

    cwd = ExPath(os.getcwd())

    largefiles: Dict[ExPath, float] = get_large_files_from_status(cwd, status)
    if largefiles:
        handle_large_files(cwd, largefiles, dry_run)

    if '.zsh_history' in status:
        pwd = misc.getsecret('general')
        with open('/home/gilad/.zsh_history', errors='backslashreplace') as f:
            history = f.readlines()
            for i, line in enumerate(history):
                if pwd in line:
                    misc.redprint(
                        f"password found in .zsh_history in line {i}. exiting")
                    return

    if not commitmsg:
        if len(status.files) == 1:
            commitmsg = status.files[0]
        elif len(status.files) < 3:
            commitmsg = ', '.join([f.name for f in status.files])
        else:
            os.system('git status -s')
            commitmsg = input('commit msg:\t')
    commitmsg = misc.unquote(commitmsg)
    if dry_run:
        misc.whiteprint('dry run. exiting')
        return
    shell.run('git add .', f'git commit -am "{commitmsg}"')
    git.push()
Exemple #12
0
 def write(self, paths, *, verify_paths=True, confirm=False, dry_run=False, backup=True):
     logging.debug(f'paths:', paths, 'verify_paths:', verify_paths, 'confirm:', confirm, 'dry_run:', dry_run, 'backup:', backup)
     writelines = []
     if verify_paths:
         should_add_to_gitignore = self.should_add_to_gitignore
     else:
         should_add_to_gitignore = lambda _p: True
     for p in filter(should_add_to_gitignore, paths):
         to_write = f'\n{p}'
         if confirm and not prompt.confirm(f'Add {p} to .gitignore?'):
             continue
         logging.info(f'Adding {p} to .gitignore. dry_run={dry_run}, backup={backup}, confirm={confirm}')
         writelines.append(to_write)
     if dry_run:
         print('dry_run, returning')
         return
     if backup:
         backup_ok = self.backup(confirm)
         if not backup_ok:
             return
     
     with self.file.open(mode='a') as file:
         file.write(''.join(sorted(writelines)))
     Gitignore.values.fget.clear_cache()
Exemple #13
0
def test__choose():
    with common.assert_raises(
            ValueError, 'At least one option is required when using Choice'):
        prompt.choose('foo')
        prompt.confirm('foo', n='confirm')
Exemple #14
0
def test__confirm():
    with common.assert_raises(ValueError,
                              'Confirmation cannot have free input'):
        prompt.confirm('foo', free_input=True)
    with common.assert_raises(ValueError, "'n' in kw_opts but was already in"):
        prompt.confirm('foo', n='confirm')