@contextlib.contextmanager
def _git_stash(env, brew_cmd):
    brew_prefix = env.safe_run_output("{brew_cmd} --prefix".format(**locals()))
    with cd(brew_prefix):
        with quiet():
            with settings(warn_only=True):
                env.safe_run("git config user.email 'stash@brew.sh'")
                check_diff = env.safe_run("git diff --quiet")
                git_version = env.safe_run_output("git --version").strip().split()[-1]
    if git_version and LooseVersion(git_version) < LooseVersion("1.7"):
        if check_diff.return_code > 0:
            with cd(brew_prefix):
                with settings(warn_only=True):
                    env.safe_run("git stash --quiet")
        try:
            yield None
        finally:
            if check_diff.return_code > 0:
                with cd(brew_prefix):
                    with settings(warn_only=True):
                        env.safe_run("git stash pop --quiet")
    else:
        yield None
Perform a safe git stash around an update.
dataset/ETHPy150Open chapmanb/cloudbiolinux/cloudbio/package/brew.py/_git_stash