- get_git_repo_type()
- {
- if [ -d "$1"/.git ] && [ -d "$1"/.git/refs/heads ] &&
- [ -d "$1"/.git/objects ] && [ -f "$1"/.git/config ];
- then
- echo non-bare
- elif [ -d "$1"/refs/heads ] && [ -d "$1"/refs/tags ] &&
- [ -d "$1"/objects ] && [ -f "$1"/config ]; then
- local bare
- bare="$(GIT_CONFIG="$1"/config git-config --get core.bare)"
- case "$bare" in
- true) echo bare;;
- false) echo fake-bare;;
- *) return 255;;
- esac
- else
- return 1
- fi
- }
- is_git_repo() {
- get_git_repo_type "$1" >/dev/null
- }
- get_repo_type() {
- if [ -d "$1"/.svn ]; then
- echo svn
- elif is_git_repo "$1"; then
- echo git
- elif [ -d "$1"/.bzr ]; then
- echo bzr
- elif [ -d "$1"/CVS ]; then
- echo CVS
- elif [ -d "$1"/.hg ]; then
- echo hg
- elif [ -d "$1"/_darcs ]; then
- echo darcs
- else
- echo unknown
- fi
- }
-
-update =
- case "$(get_repo_type "$MR_REPO")" in
- svn) svn update "$@";;
- git)
- # all this is because of a bug in git-fetch, which requires GIT_DIR set
- local git_dir_override; git_dir_override=.git
- case "$(get_git_repo_type "$MR_REPO")" in
- fake-bare) git_dir_override="$MR_REPO";;
- esac
- args="$@"
- [ -z "$args" ] && args="-t origin master"
- eval GIT_DIR="$git_dir_override" git pull "$args"
- ;;
- bzr) bzr merge "$@";;
- CVS) cvs update "$@";;
- hg) hg pull "$@" && hg update "$@";;
- darcs) darcs pull -a "$@";;
- *) error "unknown repo type";;
- esac
-
-status =
- case "$(get_repo_type "$MR_REPO")" in
- svn) svn status "$@";;
- git) git status "$@" || :;;
- bzr) bzr status "$@";;
- CVS) cvs status "$@";;
- hg) hg status "$@";;
- darcs) darcs whatsnew -ls "$@";;
- *) error "unknown repo type";;
- esac
-
-commit =
- case "$(get_repo_type "$MR_REPO")" in
- svn) svn commit "$@";;
- git)
- case "$(get_git_repo_type "$MR_REPO")" in
- bare) error "cannot commit to bare git repositories";;
- fake-bare) error "commit does not work for fake bare git repositories (yet).";;
- esac
- git commit -a "$@" && git push --all
- ;;
- bzr) bzr commit "$@" && bzr push;;
- CVS) cvs commit "$@";;
- hg) hg commit -m "$@" && hg push;;
- darcs) darcs commit -a -m "$@" && darcs push -a;;
- *) error "unknown repo type";;
- esac
-
-diff =
- case "$(get_repo_type "$MR_REPO")" in
- svn) svn diff "$@";;
- git)
- case "$(get_git_repo_type "$MR_REPO")" in
- bare) error "cannot diff in bare git repositories";;
- fake-bare) error "diff does not work for fake bare git repositories (yet).";;
- esac
- git diff "$@"
- ;;
- bzr) bzr diff "$@";;
- CVS) cvs diff "$@";;
- hg) hg diff "$@";;
- darcs) darcs diff "$@";;
- *) error "unknown repo type";;
- esac