Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git hooks doesn't work on Source Tree

Via Terminal everything works correctly but in Source Tree doesn't work

This is my pre-commit hook

#!/bin/bash
#
# hook script for swiftlint. It will triggered when you make a commit.
#
# If you want to use, type commands in your console.
# $ ln -s ../../pre-commit-swiftlint.sh .git/hooks/pre-commit
# $ chmod +x .git/hooks/pre-commit

LINT=$(which swiftlint)

if [[ -e "${LINT}" ]]; then
   echo "SwiftLint Start..."
else
echo "SwiftLint does not exist, download from https://github.com/realm/SwiftLint"
exit 1
fi

RESULT=$($LINT lint --quiet)

if [ "$RESULT" == '' ]; then
printf "\e[32mSwiftLint Finished.\e[39m\n"
else
echo ""
printf "\e[41mSwiftLint Failed.\e[49m Please check below:\n"

while read -r line; do

    FILEPATH=$(echo $line | cut -d : -f 1)
    L=$(echo $line | cut -d : -f 2)
    C=$(echo $line | cut -d : -f 3)
    TYPE=$(echo $line | cut -d : -f 4 | cut -c 2-)
    MESSAGE=$(echo $line | cut -d : -f 5 | cut -c 2-)
    DESCRIPTION=$(echo $line | cut -d : -f 6 | cut -c 2-)
    if [ "$TYPE" == 'error' ]; then
        printf "\n  \e[31m$TYPE\e[39m\n"
    else
        printf "\n  \e[33m$TYPE\e[39m\n"
    fi
    printf "    \e[90m$FILEPATH:$L:$C\e[39m\n"
    printf "    $MESSAGE - $DESCRIPTION\n"
done <<< "$RESULT"

printf "\nCOMMIT ABORTED. Please fix them before commiting.\n"

exit 1
fi
like image 834
Islam Temirbek Avatar asked Jun 28 '18 04:06

Islam Temirbek


People also ask

How do I enable Git hooks?

Implementing Git Hooks Upon initializing a new project, Git populates the hooks folder with template files. To enable the hook scripts, simply remove the . sample extension from the file name. Git will automatically execute the scripts based on the naming.

Can I push Git hooks to remote?

You can import a remote Git repository in to Business Central and configure a post-commit Git hook to automatically push changes to that remote repository.

Do Git hooks get cloned?

Hooks are local to any given Git repository, and they are not copied over to the new repository when you run git clone . And, since hooks are local, they can be altered by anybody with access to the repository. This has an important impact when configuring hooks for a team of developers.

Are Git hooks synced?

Git hooks let developers automate expectations and workflows–terrific news for supporting ease-of-use and consistency across a development team. Unfortunately, git doesn't automatically synchronize hooks between project contributors.


3 Answers

Fixed by adding export PATH=/usr/local/bin:$PATH

Source Tree issue

like image 58
Islam Temirbek Avatar answered Nov 10 '22 22:11

Islam Temirbek


For me I had to open Sourcetree through command line

open /Applications/Sourcetree.app

from here (SourceTree-Hook-failing-because-paths-don-t-seem-to-be-set)

like image 14
svkaka Avatar answered Nov 10 '22 20:11

svkaka


This works on OSX, update ~/.bash_profile with

export PATH="/usr/local/bin:$PATH"
like image 1
cannin Avatar answered Nov 10 '22 22:11

cannin