Esempio n. 1
0
def main(*args):
    parser = gitboots.argparse_setup(globals())

    parser.add_argument('-n', '--no-rebase', action='store_true', help='commit only, do not rebase')
    parser.add_argument('-a', '--atomic', action='store_true', help='rollback on failure')
    parser.add_argument('commit', nargs='?', metavar='<commit>')
    opts = parser.parse_args(args if args else None)

    commit = tools.git_rev_parse_verify(opts.commit)
    tools.git('commit', '--fixup', commit)

    if opts.no_rebase:
        logging.info('Skipping rebase step.')
        return

    with tools.git_stash() as stashed:
        try:
            tools.git('rebase', '--keep-empty', '--autosquash', '--interactive',
                      '%s^' % commit, _env=dict(GIT_EDITOR=':'))
        except sh.ErrorReturnCode_1:
            if opts.atomic:
                tools.git('rebase', '--abort')
                if stashed:
                    tools.git('stash', 'pop')
                tools.git('reset', 'HEAD^')
                logger.error('Atomic operation failed. Reverted to the original state.')
            else:
                logger.error(REBASE_HELP)
            raise tools.GitRebaseFailed()
Esempio n. 2
0
def main(args=None):
    parser = gitboots.argparse_setup(globals())

    parser.add_argument("-e", metavar="COMMAND", default="rm -f", help="execute command on each found lock")
    opts = parser.parse_args(args)

    path = git_dir()
    for lock in sh.find(path, "-type", "f", "-name", "index.lock"):
        lock = lock.strip()
        if opts.e != "rm -f":
            if "{}" in opts.e:
                cmd = opts.e.replace("{}", lock)
            else:
                cmd = "{cmd} {lock}".format(cmd=opts.e, lock=lock)
            logger.info(cmd)
            if sh.which("sh"):
                sh.sh("-c", cmd)
            elif sh.which("cmd.exe"):
                sh.cmd("\c", cmd)
            else:
                raise ValueError("Do not know how to run this command: %s" % cmd)
        else:
            logger.info("rm -f %s", lock)
            os.remove(lock)