#!/bin/sh # ---------------------------------------------------------------------- # In a git "working copy" checkout the given entity (branch, tag, # changeset). In case of a branch pull the latest changes, in every # other case leave it in detached HEAD state. This script performs no # directory changes, so start it in the target directory! # # Authors: Alexander Dahl # # Copyright 2011,2013 Alexander Dahl # ---------------------------------------------------------------------- ENTITY="$1" BRANCH_EXISTS="no" print_usage() { echo "Usage: $0 checkoutentity" } if [ -z "$1" ] then print_usage exit 1 fi if git fetch then echo 'Git fetch successful!' else exit $? fi if git checkout "$1" then echo 'Git checkout successful!' else exit $? fi for branch in $(git branch | cut -c3-) do if [ "${ENTITY}" = "${branch}" ] then BRANCH_EXISTS="yes" fi done if [ "${BRANCH_EXISTS}" = "yes" ] then git pull fi if git submodule update --init --recursive then echo 'Git submodule update successful!' else exit $? fi exit 0