Humanity

Edit the world by your favorite way

「gitでサブモジュールを削除する」をgittoolsに追加してみた

元記事: gitでサブモジュールを削除する


まずgittoolsっていうのは自分が~/bin/に入れるようなgitのスクリプトを入れてるリポジトリのことです。
tyru/gittools · GitHub


で、それにgit-subrmっていうシェルスクリプト追加してみた。
ほとんど元記事と一緒なんだけど以下が違う。

  • 自動でgit commitしない
  • .gitmodulesをgit addする

基本それだけなんだけどgit add .gitmodulesするために最初でいろいろチェックしてる。それだけのもの。

#!/bin/sh
# via http://labs.timedia.co.jp/2011/03/git-removing-a-submodule.html

if [ ! -z "`git rev-parse --show-cdup`" ]; then
    echo "error: git-submodule can be run at top level of repository." >&2
    exit 1
fi
if [ ! -z "`git diff HEAD -- .gitmodules`" ]; then
    echo "error: .gitmodules is dirty. please commit or junk its hunk." >&2
    exit 1
fi
if [ $# -eq 0 ]; then
    echo "Usage: $(basename $0) {submodule}" >&2
    exit 1
fi
name="$1"

git rm --cached `git config --file .gitmodules --get submodule.$name.path`
git config --file .gitmodules --remove-section submodule.$name
git add .gitmodules


最新版はここ見てね。
gittools/git-subrm at master · tyru/gittools · GitHub