Skip to content

Instantly share code, notes, and snippets.

@vi
Created November 24, 2015 16:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vi/38dea76113034d898afa to your computer and use it in GitHub Desktop.
Save vi/38dea76113034d898afa to your computer and use it in GitHub Desktop.
Hacky git wrapper to automatically supply --reference for `git clone` based on URL
#!/bin/bash
# git wrapper, to auto-supply --reference to `git clone`
# edit the table below to suit your setup
LOG=/tmp/git.log
echo git: "$@" >> "$LOG"
CLONE=0
for i in "$@"; do
if [[ $i == clone ]]; then
CLONE=1
break
fi
done
if [[ $CLONE == 0 ]]; then
exec /usr/bin/git "$@"
echo "Failed to execute /usr/bin/git" >&2
exit 127
fi
REFERENCE=""
for i in "$@"; do
case "$i" in
https://chromium.googlesource.com/external/webrtc.git)
REFERENCE=/mnt/src/git/webrtc/.git
break
;;
https://chromium.googlesource.com/v8/v8.git)
REFERENCE=/mnt/src/git/chromium/src/v8/.git
break
;;
https://chromium.googlesource.com/chromium/src.git)
REFERENCE=/mnt/src/git/chromium/src/.git
break
;;
https://chromium.googlesource.com/external/github.com/google/open-vcdiff.git)
REFERENCE=/mnt/src/git/chromium/src/sdch/open-vcdiff/.git
break
;;
https://chromium.googlesource.com/chromium/cdm.git)
REFERENCE=/mnt/src/git/chromium/src/media/cdm/api/.git
break
;;
https://chromium.googlesource.com/external/gyp.git)
REFERENCE=/mnt/src/git/chromium/src/tools/gyp/.git
break
;;
https://chromium.googlesource.com/chromium/deps/acid3.git)
REFERENCE=/mnt/src/git/chromium/src/tools/page_cycler/acid3/.git
break
;;
https://chromium.googlesource.com/external/swarming.client.git)
REFERENCE=/mnt/src/git/chromium/src/tools/swarming_client/.git
break
;;
https://chromium.googlesource.com/breakpad/breakpad/src.git)
REFERENCE=/mnt/src/git/chromium/src/breakpad/src/.git
break
;;
https://chromium.googlesource.com/external/googlemock.git)
REFERENCE=/mnt/src/git/chromium/src/testing/gmock/.git
break
;;
https://chromium.googlesource.com/external/github.com/google/googletest.git)
REFERENCE=/mnt/src/git/chromium/src/testing/gtest/.git
break
;;
https://chromium.googlesource.com/chromium/frame_rate/content.git)
REFERENCE=/mnt/src/git/chromium/src/chrome/test/data/perf/frame_rate/content/.git
break
;;
https://chromium.googlesource.com/chromium/canvas_bench.git)
REFERENCE=/mnt/src/git/chromium/src/chrome/test/data/perf/canvas_bench/.git
break
;;
https://chromium.googlesource.com/chromium/reference_builds/chrome_linux64.git)
REFERENCE=/mnt/src/git/chromium/src/chrome/tools/test/reference_build/chrome_linux/.git
break
;;
https://chromium.googlesource.com/chromium/buildtools.git)
REFERENCE=/mnt/src/git/chromium/src/buildtools/.git
break
;;
https://chromium.googlesource.com/chromium/llvm-project/cfe/tools/clang-format.git)
REFERENCE=/mnt/src/git/chromium/src/buildtools/clang_format/script/.git
break
;;
https://chromium.googlesource.com/chromium/llvm-project/libcxx.git)
REFERENCE=/mnt/src/git/chromium/src/buildtools/third_party/libc++/trunk/.git
break
;;
https://chromium.googlesource.com/chromium/llvm-project/libcxxabi.git)
REFERENCE=/mnt/src/git/chromium/src/buildtools/third_party/libc++abi/trunk/.git
break
;;
https://chromium.googlesource.com/native_client/src/native_client.git)
REFERENCE=/mnt/src/git/chromium/src/native_client/.git
break
;;
https://chromium.googlesource.com/chromium/deps/icu.git)
REFERENCE=/mnt/src/git/chromium/src/third_party/icu/.git
break
;;
https://chromium.googlesource.com/external/linux-syscall-support/lss.git)
REFERENCE=/mnt/src/git/chromium/src/third_party/lss/.git
break
;;
https://android.googlesource.com/platform/external/deqp)
REFERENCE=/mnt/src/git/chromium/src/third_party/deqp/src/.git
break
;;
https://chromium.googlesource.com/chromium/deps/flac.git)
REFERENCE=/mnt/src/git/chromium/src/third_party/flac/.git
break
;;
https://chromium.googlesource.com/chromium/deps/mesa.git)
REFERENCE=/mnt/src/git/chromium/src/third_party/mesa/src/.git
break
;;
https://chromium.googlesource.com/chromium/deps/opus.git)
REFERENCE=/mnt/src/git/chromium/src/third_party/opus/src/.git
break
;;
https://chromium.googlesource.com/skia.git)
REFERENCE=/mnt/src/git/chromium/src/third_party/skia/.git
break
;;
https://chromium.googlesource.com/chromium/deps/yasm/patched-yasm.git)
REFERENCE=/mnt/src/git/chromium/src/third_party/yasm/source/patched-yasm/.git
break
;;
https://chromium.googlesource.com/external/github.com/chromium/web-page-replay.git)
REFERENCE=/mnt/src/git/chromium/src/third_party/webpagereplay/.git
break
;;
https://chromium.googlesource.com/external/webrtc/trunk/talk.git)
REFERENCE=/mnt/src/git/chromium/src/third_party/libjingle/source/talk/.git
break
;;
https://chromium.googlesource.com/external/py_trace_event.git)
REFERENCE=/mnt/src/git/chromium/src/third_party/py_trace_event/src/.git
break
;;
https://chromium.googlesource.com/external/leveldb.git)
REFERENCE=/mnt/src/git/chromium/src/third_party/leveldatabase/src/.git
break
;;
https://chromium.googlesource.com/external/github.com/open-source-parsers/jsoncpp.git)
REFERENCE=/mnt/src/git/chromium/src/third_party/jsoncpp/source/.git
break
;;
https://chromium.googlesource.com/angle/angle.git)
REFERENCE=/mnt/src/git/chromium/src/third_party/angle/.git
break
;;
https://chromium.googlesource.com/external/github.com/CLD2Owners/cld2.git)
REFERENCE=/mnt/src/git/chromium/src/third_party/cld_2/src/.git
break
;;
https://chromium.googlesource.com/external/fontconfig.git)
REFERENCE=/mnt/src/git/chromium/src/third_party/fontconfig/src/.git
break
;;
https://chromium.googlesource.com/external/khronosgroup/webgl.git)
REFERENCE=/mnt/src/git/chromium/src/third_party/webgl/src/.git
break
;;
https://chromium.googlesource.com/chromium/deps/libexif/sources.git)
REFERENCE=/mnt/src/git/chromium/src/third_party/libexif/sources/.git
break
;;
https://chromium.googlesource.com/chromium/deps/libsrtp.git)
REFERENCE=/mnt/src/git/chromium/src/third_party/libsrtp/.git
break
;;
https://chromium.googlesource.com/webm/libwebm.git)
REFERENCE=/mnt/src/git/chromium/src/third_party/libwebm/source/.git
break
;;
https://chromium.googlesource.com/native_client/src/third_party/scons-2.0.1.git)
REFERENCE=/mnt/src/git/chromium/src/third_party/scons-2.0.1/.git
break
;;
https://boringssl.googlesource.com/boringssl.git)
REFERENCE=/mnt/src/git/chromium/src/third_party/boringssl/src/.git
break
;;
https://chromium.googlesource.com/chromiumos/platform/system_api.git)
REFERENCE=/mnt/src/git/chromium/src/third_party/cros_system_api/.git
break
;;
https://chromium.googlesource.com/external/google-safe-browsing/testing.git)
REFERENCE=/mnt/src/git/chromium/src/third_party/safe_browsing/testing/.git
break
;;
https://chromium.googlesource.com/chromiumos/platform/minigbm.git)
REFERENCE=/mnt/src/git/chromium/src/third_party/minigbm/src/.git
break
;;
https://chromium.googlesource.com/external/github.com/google/pywebsocket.git)
REFERENCE=/mnt/src/git/chromium/src/third_party/pywebsocket/src/.git
break
;;
https://chromium.googlesource.com/external/libphonenumber/cpp/test.git)
REFERENCE=/mnt/src/git/chromium/src/third_party/libphonenumber/src/test/.git
break
;;
https://chromium.googlesource.com/external/libphonenumber/cpp/src/phonenumbers.git)
REFERENCE=/mnt/src/git/chromium/src/third_party/libphonenumber/src/phonenumbers/.git
break
;;
https://chromium.googlesource.com/external/libphonenumber/resources.git)
REFERENCE=/mnt/src/git/chromium/src/third_party/libphonenumber/src/resources/.git
break
;;
https://chromium.googlesource.com/external/colorama.git)
REFERENCE=/mnt/src/git/chromium/src/third_party/colorama/src/.git
break
;;
https://chromium.googlesource.com/chromium/third_party/ffmpeg.git)
REFERENCE=/mnt/src/git/chromium/src/third_party/ffmpeg/.git
break
;;
https://chromium.googlesource.com/chromium/src/third_party/freetype2.git)
REFERENCE=/mnt/src/git/chromium/src/third_party/freetype2/src/.git
break
;;
https://chromium.googlesource.com/external/github.com/catapult-project/catapult.git)
REFERENCE=/mnt/src/git/chromium/src/third_party/catapult/.git
break
;;
https://chromium.googlesource.com/chromiumos/chromite.git)
REFERENCE=/mnt/src/git/chromium/src/third_party/chromite/.git
break
;;
https://chromium.googlesource.com/webm/libvpx.git)
REFERENCE=/mnt/src/git/chromium/src/third_party/libvpx_new/source/libvpx/.git
break
;;
https://chromium.googlesource.com/libyuv/libyuv.git)
REFERENCE=/mnt/src/git/chromium/src/third_party/libyuv/.git
break
;;
https://pdfium.googlesource.com/pdfium.git)
REFERENCE=/mnt/src/git/chromium/src/third_party/pdfium/.git
break
;;
https://chromium.googlesource.com/external/github.com/googlei18n/sfntly.git)
REFERENCE=/mnt/src/git/chromium/src/third_party/sfntly/src/.git
break
;;
https://chromium.googlesource.com/external/bidichecker/lib.git)
REFERENCE=/mnt/src/git/chromium/src/third_party/bidichecker/.git
break
;;
https://chromium.googlesource.com/external/snappy.git)
REFERENCE=/mnt/src/git/chromium/src/third_party/snappy/src/.git
break
;;
https://chromium.googlesource.com/external/github.com/cisco/openh264)
REFERENCE=/mnt/src/git/chromium/src/third_party/openh264/src/.git
break
;;
https://chromium.googlesource.com/external/github.com/chromium/dom-distiller-dist.git)
REFERENCE=/mnt/src/git/chromium/src/third_party/dom_distiller_js/dist/.git
break
;;
https://chromium.googlesource.com/external/webrtc/trunk/webrtc.git)
REFERENCE=/mnt/src/git/chromium/src/third_party/webrtc/.git
break
;;
https://chromium.googlesource.com/chromium/deps/hunspell_dictionaries.git)
REFERENCE=/mnt/src/git/chromium/src/third_party/hunspell_dictionaries/.git
break
;;
https://chromium.googlesource.com/external/usrsctplib.git)
REFERENCE=/mnt/src/git/chromium/src/third_party/usrsctp/usrsctplib/.git
break
;;
https://chromium.googlesource.com/external/smhasher.git)
REFERENCE=/mnt/src/git/chromium/src/third_party/smhasher/src/.git
break
;;
https://chromium.googlesource.com/crashpad/crashpad.git)
REFERENCE=/mnt/src/git/chromium/src/third_party/crashpad/crashpad/.git
break
;;
https://chromium.googlesource.com/chromium/deps/libjpeg_turbo.git)
REFERENCE=/mnt/src/git/chromium/src/third_party/libjpeg_turbo/.git
break
;;
https://chromium.googlesource.com/external/wayland/wayland.git)
REFERENCE=/mnt/src/git/chromium/src/third_party/wayland/src/.git
break
;;
https://chromium.googlesource.com/external/pyftpdlib.git)
REFERENCE=/mnt/src/git/chromium/src/third_party/pyftpdlib/src/.git
break
;;
https://chromium.googlesource.com/external/liblouis-github.git)
REFERENCE=/mnt/src/git/chromium/src/third_party/liblouis/src/.git
break
;;
https://chromium.googlesource.com/external/webrtc/deps/third_party/openmax.git)
REFERENCE=/mnt/src/git/chromium/src/third_party/openmax_dl/.git
break
;;
https://chromium.googlesource.com/chromium/deps/xdg-utils.git)
REFERENCE=/mnt/src/git/chromium/src/third_party/xdg-utils/.git
break
;;
https://chromium.googlesource.com/external/selenium/py.git)
REFERENCE=/mnt/src/git/chromium/src/third_party/webdriver/pylib/.git
break
;;
https://chromium.googlesource.com/external/libaddressinput.git)
REFERENCE=/mnt/src/git/chromium/src/third_party/libaddressinput/src/.git
break
;;
https://chromium.googlesource.com/chromiumos/third_party/pyelftools.git)
REFERENCE=/mnt/src/git/chromium/src/third_party/pyelftools/.git
break
;;
esac
done
if [[ -z $REFERENCE ]]; then
exec /usr/bin/git "$@"
echo "Failed to execute /usr/bin/git" >&2
exit 127
else
echo reference: "$REFERENCE" >> "$LOG"
exec /usr/bin/git "$@" --reference "$REFERENCE"
echo "Failed to execute /usr/bin/git" >&2
exit 127
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment