Skip to content

Commit

Permalink
Merge pull request #78 from sriharsha-y/master
Browse files Browse the repository at this point in the history
Fixed installation and uninstallation scripts for pre-push hook.
  • Loading branch information
svishwanath-tw authored Jan 9, 2019
2 parents 0889bbb + 239570a commit 863b867
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,20 @@ You could have chosen to install as a global hook template or at a single reposi
Please follow the steps below based on which option you had chosen at installation.

## Uninstallation from a global hook template
To uninstall talisman globally from your machine, run:
Run the following command on your terminal to uninstall talisman globally from your machine.

For pre-commit hook:

```
curl --silent https://raw.githubusercontent.com/thoughtworks/talisman/master/global_install_scripts/uninstall.bash > /tmp/uninstall_talisman.bash && /bin/bash /tmp/uninstall_talisman.bash
```

For pre-push hook:

```
curl --silent https://raw.githubusercontent.com/thoughtworks/talisman/master/global_install_scripts/uninstall.bash > /tmp/uninstall_talisman.bash && /bin/bash /tmp/uninstall_talisman.bash pre-push
```

This will

1. ask you for the base dir of all your repos, find all git repos inside it and remove talisman hooks
Expand Down
4 changes: 2 additions & 2 deletions global_install_scripts/install.bash
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ function run() {
EXCEPTIONS_FILE=${TEMP_DIR}/pre-existing-hooks.paths
touch ${EXCEPTIONS_FILE}

CMD_STRING="${SUDO_PREFIX} ${SEARCH_CMD} ${SEARCH_ROOT} ${EXTRA_SEARCH_OPTS} -name .git -type d -exec ${REPO_HOOK_SETUP_SCRIPT_PATH} ${TALISMAN_HOOK_SCRIPT_PATH} ${EXCEPTIONS_FILE} {} \;"
CMD_STRING="${SUDO_PREFIX} ${SEARCH_CMD} ${SEARCH_ROOT} ${EXTRA_SEARCH_OPTS} -name .git -type d -exec ${REPO_HOOK_SETUP_SCRIPT_PATH} ${TALISMAN_HOOK_SCRIPT_PATH} ${EXCEPTIONS_FILE} {} ${HOOK_SCRIPT} \;"
echo_debug "EXECUTING: ${CMD_STRING}"
eval "${CMD_STRING}" || true

Expand Down Expand Up @@ -351,7 +351,7 @@ END_OF_SCRIPT
setup_talisman
fi

echo "Setting up pre-commit hook in git template directory"
echo "Setting up ${HOOK_SCRIPT} hook in git template directory"
setup_git_template_talisman_hook
echo
echo "Setting up talisman hook recursively in git repos"
Expand Down
9 changes: 5 additions & 4 deletions global_install_scripts/setup_talisman_hook_in_repo.bash
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ function run() {
TALISMAN_HOOK_SCRIPT_PATH=$1
EXCEPTIONS_FILE=$2
DOT_GIT_DIR=$3
HOOK_SCRIPT=$4

function echo_error() {
echo -ne $(tput setaf 1) >&2
Expand All @@ -26,7 +27,7 @@ function run() {
echo -ne $(tput sgr0)
}

REPO_HOOK_SCRIPT=${DOT_GIT_DIR}/hooks/pre-commit
REPO_HOOK_SCRIPT=${DOT_GIT_DIR}/hooks/${HOOK_SCRIPT}
#check if a hook already exists
if [ -e "${REPO_HOOK_SCRIPT}" ]; then
#check if already hooked up to talisman
Expand All @@ -39,7 +40,7 @@ function run() {
echo ${DOT_GIT_DIR} | sed 's#/.git$##' >> ${EXCEPTIONS_FILE}
fi
else
echo "Setting up pre-commit hook in ${DOT_GIT_DIR}/hooks"
echo "Setting up ${HOOK_SCRIPT} hook in ${DOT_GIT_DIR}/hooks"
mkdir -p ${DOT_GIT_DIR}/hooks || (echo_error "Could not create hooks directory" && return)
LN_FLAGS="-sf"
[ -n "true" ] && LN_FLAGS="${LN_FLAGS}v"
Expand All @@ -48,9 +49,9 @@ function run() {
"MINGW32_NT-10.0-WOW" | "MINGW64_NT-10.0")
DOT_GIT_DIR_WIN=$(sed -e 's/\/\([a-z]\)\//\1:\\/' -e 's/\//\\/g' <<< "$DOT_GIT_DIR")
TALISMAN_HOOK_SCRIPT_PATH_WIN=$(sed -e 's/\/\([a-z]\)\//\1:\\/' -e 's/\//\\/g' <<< "$TALISMAN_HOOK_SCRIPT_PATH")
cmd <<< "mklink /H "${DOT_GIT_DIR_WIN}\\hooks\\pre-commit" "${TALISMAN_HOOK_SCRIPT_PATH_WIN}"" > /dev/null;;
cmd <<< "mklink /H "${DOT_GIT_DIR_WIN}\\hooks\\${HOOK_SCRIPT}" "${TALISMAN_HOOK_SCRIPT_PATH_WIN}"" > /dev/null;;
*)
ln ${LN_FLAGS} ${TALISMAN_HOOK_SCRIPT_PATH} ${DOT_GIT_DIR}/hooks/pre-commit
ln ${LN_FLAGS} ${TALISMAN_HOOK_SCRIPT_PATH} ${DOT_GIT_DIR}/hooks/${HOOK_SCRIPT}
;;
esac

Expand Down
6 changes: 5 additions & 1 deletion global_install_scripts/uninstall.bash
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ shopt -s extglob

DEBUG=${DEBUG:-''}

declare HOOK_SCRIPT='pre-commit' # TODO: need ability to uninstall pre-push hook as well.
declare HOOK_SCRIPT='pre-commit'
if [[ $# -gt 0 && $1 =~ pre-push.* ]] ; then
HOOK_SCRIPT='pre-push'
fi

function run() {
# Arguments: $1 = 'pre-commit' or 'pre-push'. whether to set talisman up as pre-commit or pre-push hook : TODO: not implemented yet
# Environment variables:
Expand Down

0 comments on commit 863b867

Please sign in to comment.