@task
def commit():
    message = 'Update Documentation'
    yes_ans = ('y', 'yes')

    with settings(warn_only=True):
        # Changes in the work tree to add
        add_file = '--update .'  # include tracked files
        # hack of res.return_code without warning info
        res = local('git diff --quiet --exit-code; echo $?', capture=True)
        if int(res.strip()):
            if False:  # future feature?
                # TODO: there use diff to uniform with below, and the
                # output can be formatted like `git add --dry-run --update .`
                test_res = local('git diff --name-status', capture=True)
                try:
                    _ans = raw_input('\n{0}\nAdd these files to index? (y/N) '
                                     .format(test_res.strip()))
                    if _ans.lower() in yes_ans:
                        local("git add {0}".format(add_file))
                except (KeyboardInterrupt, SystemExit):
                    pass
            else:
                local("git add {0}".format(add_file))

        # Changes in the index to commit
        res = local('git diff --cached --quiet --exit-code; echo $?',
                    capture=True)
        if int(res.strip()):
            test_res = local('git diff --cached --name-status', capture=True)
            try:
                _ans = raw_input('\n{0}\nCommit these files? (y/N) '
                                 .format(test_res.strip()))
                if _ans.lower() in yes_ans:
                    local("git commit -m '{0}'".format(message))
            except (KeyboardInterrupt, SystemExit):
                pass
        else:
            print('Nothing to commit.')
git commit source changes from all tracked files
dataset/ETHPy150Open tankywoo/simiki/simiki/conf_templates/fabfile.py/commit