Commit 0703ea2c authored by iannucci@chromium.org's avatar iannucci@chromium.org

Multiple improvements to windows bash integration.

  * `git bash` helper now will either:
    * launch an interactive bash prompt in the MinGW Terminal Emulator
    * launch a non-interactive bash shell if arguments are provided
  * `git bash` now includes python, python/Scripts and svn binaries in
    the PATH.
  * depot_tools' colorization now works in MinGW Terminal Emulator
  * batch scripts are now regenerated if any of them is missing.

R=agable@chromium.org, dnj@chromium.org, mmoss@chromium.org
BUG=598956

Review URL: https://codereview.chromium.org/1847783002 .

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@299616 0039d316-1c4b-4281-b951-d872f2087c98
parent c0f86421
......@@ -2,6 +2,7 @@
*.pyc
# Ignore the batch files produced by the Windows bootstrapping.
/git-bash
/git.bat
/gitk.bat
/pylint.bat
......
#!/usr/bin/env bash
export EDITOR=${EDITOR:=notepad}
WIN_BASE=`dirname $0`
UNIX_BASE=`cygpath "$WIN_BASE"`
export PATH=$PATH:$UNIX_BASE/SVN_BIN_DIR:$UNIX_BASE/PYTHON_BIN_DIR:$UNIX_BASE/PYTHON_BIN_DIR/Scripts
export PYTHON_DIRECT=1
export PYTHONUNBUFFERED=1
if [[ $# > 1 ]]; then
$UNIX_BASE/GIT_BIN_DIR/bin/bash.exe "$@"
else
$UNIX_BASE/GIT_BIN_DIR/git-bash.exe &
fi
......@@ -89,15 +89,18 @@ for /d %%i in ("%WIN_TOOLS_ROOT_DIR%\git-*_bin") do (
if "%WIN_TOOLS_FORCE%" == "1" goto :GIT_INSTALL
if exist "%GIT_EXE_PATH%" (
call "%GIT_EXE_PATH%" --version 2>nul 1>nul
if errorlevel 1 goto :GIT_INSTALL
rem Several git versions can live side-by-side; check the top-level
rem batch script to make sure it points to the desired version.
find "%GIT_BIN_DIR%" "%WIN_TOOLS_ROOT_DIR%\git.bat" 2>nul 1>nul
if not exist "%GIT_EXE_PATH%" goto :GIT_INSTALL
call "%GIT_EXE_PATH%" --version 2>nul 1>nul
if errorlevel 1 goto :GIT_INSTALL
:: Several git versions can live side-by-side; check the top-level
:: batch script to make sure it points to the desired version.
for %%f in (git.bat gitk.bat ssh.bat ssh-keygen.bat git-bash) do (
find "%GIT_BIN_DIR%" "%WIN_TOOLS_ROOT_DIR%\%%f" 2>nul 1>nul
if errorlevel 1 goto :GIT_MAKE_BATCH_FILES
goto :SYNC_GIT_HELP_FILES
)
goto :SYNC_GIT_HELP_FILES
:GIT_INSTALL
echo Installing git %GIT_VERSION% (avg 1-2 min download) ...
......@@ -128,10 +131,11 @@ if not exist "%GIT_INST_DIR%\." goto :GIT_FAIL
:: Create the batch files.
set GIT_TEMPL=%~dp0git.template.bat
set SED=%GIT_INST_DIR%\usr\bin\sed.exe
call "%SED%" -e "s/GIT_BIN_DIR/%GIT_BIN_DIR%/" -e "s/GIT_PROGRAM/cmd\\\\git.exe/" < %GIT_TEMPL% > "%WIN_TOOLS_ROOT_DIR%\git.bat"
call "%SED%" -e "s/GIT_BIN_DIR/%GIT_BIN_DIR%/" -e "s/GIT_PROGRAM/cmd\\\\gitk.exe/" < %GIT_TEMPL% > "%WIN_TOOLS_ROOT_DIR%\gitk.bat"
call "%SED%" -e "s/GIT_BIN_DIR/%GIT_BIN_DIR%/" -e "s/GIT_PROGRAM/usr\\\\bin\\\\ssh.exe/" < %GIT_TEMPL% > "%WIN_TOOLS_ROOT_DIR%\ssh.bat"
call "%SED%" -e "s/GIT_BIN_DIR/%GIT_BIN_DIR%/" -e "s/GIT_PROGRAM/usr\\\\bin\\\\ssh-keygen.exe/" < %GIT_TEMPL% > "%WIN_TOOLS_ROOT_DIR%\ssh-keygen.bat"
call "%SED%" -e "s/GIT_BIN_DIR/%GIT_BIN_DIR%/g" -e "s/GIT_PROGRAM/cmd\\\\git.exe/g" < %GIT_TEMPL% > "%WIN_TOOLS_ROOT_DIR%\git.bat"
call "%SED%" -e "s/GIT_BIN_DIR/%GIT_BIN_DIR%/g" -e "s/GIT_PROGRAM/cmd\\\\gitk.exe/g" < %GIT_TEMPL% > "%WIN_TOOLS_ROOT_DIR%\gitk.bat"
call "%SED%" -e "s/GIT_BIN_DIR/%GIT_BIN_DIR%/g" -e "s/GIT_PROGRAM/usr\\\\bin\\\\ssh.exe/g" < %GIT_TEMPL% > "%WIN_TOOLS_ROOT_DIR%\ssh.bat"
call "%SED%" -e "s/GIT_BIN_DIR/%GIT_BIN_DIR%/g" -e "s/GIT_PROGRAM/usr\\\\bin\\\\ssh-keygen.exe/g" < %GIT_TEMPL% > "%WIN_TOOLS_ROOT_DIR%\ssh-keygen.bat"
call "%SED%" -e "s/GIT_BIN_DIR/%GIT_BIN_DIR%/g" -e "s/PYTHON_BIN_DIR/python276_bin/g" -e "s/SVN_BIN_DIR/svn_bin/g" < %~dp0git-bash.template.sh > "%WIN_TOOLS_ROOT_DIR%\git-bash"
:: Ensure various git configurations are set correctly at they system level.
call "%WIN_TOOLS_ROOT_DIR%\git.bat" config --system core.autocrlf false
......
......@@ -14,6 +14,7 @@ Usage:
import logging
import optparse
import sys
import os
from third_party import colorama
......@@ -94,7 +95,7 @@ def main(argv):
if __name__ == '__main__':
colorama.init()
colorama.init(wrap="TERM" not in os.environ)
try:
sys.exit(main(sys.argv[1:]))
except KeyboardInterrupt:
......
......@@ -2303,7 +2303,7 @@ def main(argv):
return 2
fix_encoding.fix_encoding()
disable_buffering()
colorama.init()
colorama.init(wrap="TERM" not in os.environ)
dispatcher = subcommand.CommandDispatcher(__name__)
try:
return dispatcher.execute(OptionParser(), argv)
......
#!/usr/bin/env bash
# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# This apparently useless file enables windows users to get access to
# depot_tools' built-in bash.exe. When git executes this file as in `git bash`,
# it has bash and related tools pre-installed in the environment. Therefore even
# though 'bash' from cmd.exe doesn't work, bash here does work as you'd expect.
bash "$@"
......@@ -4478,7 +4478,7 @@ if __name__ == '__main__':
# These affect sys.stdout so do it outside of main() to simplify mocks in
# unit testing.
fix_encoding.fix_encoding()
colorama.init()
colorama.init(wrap="TERM" not in os.environ)
try:
sys.exit(main(sys.argv[1:]))
except KeyboardInterrupt:
......
......@@ -27,6 +27,7 @@ Branches are colorized as follows:
import argparse
import collections
import os
import sys
import subprocess2
......@@ -271,7 +272,7 @@ class BranchMapper(object):
def main(argv):
colorama.init()
colorama.init(wrap="TERM" not in os.environ)
if get_git_version() < MIN_UPSTREAM_TRACK_GIT_VERSION:
print >> sys.stderr, (
'This tool will not show all tracking information for git version '
......
......@@ -41,10 +41,15 @@ if [[ "$DEPOT_TOOLS" = "$0" ]]; then
else
BASENAME="${0##*\\}"
fi
SCRIPT="${SCRIPT-${BASENAME//-/_}.py}"
if [[ -e "$DEPOT_TOOLS/python.bat" && $OSTYPE = msys ]]; then
cmd.exe //c "$DEPOT_TOOLS\\python.bat" "$DEPOT_TOOLS\\$SCRIPT" "$@"
if [[ $PYTHON_DIRECT = 1 ]]; then
python.exe "$DEPOT_TOOLS\\$SCRIPT" "$@"
else
exec "$DEPOT_TOOLS/$SCRIPT" "$@"
if [[ -e "$DEPOT_TOOLS/python.bat" && $OSTYPE = msys ]]; then
cmd.exe //c "$DEPOT_TOOLS\\python.bat" "$DEPOT_TOOLS\\$SCRIPT" "$@"
else
exec "$DEPOT_TOOLS/$SCRIPT" "$@"
fi
fi
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment