From a26a4e5eaa7462a97c444570c7c6d3bbfe84877f Mon Sep 17 00:00:00 2001 From: Teo-CD Date: Mon, 20 May 2019 02:36:19 +0200 Subject: [PATCH] =?UTF-8?q?Modifi=C3=A9=20car=20git=20output=20principalem?= =?UTF-8?q?ent=20sur=20stderr=20Modification=20pour=20v=C3=A9rifier=20si?= =?UTF-8?q?=20c'est=20bien=20un=20d=C3=A9p=C3=B4t=20git=20(Pour=20les=20ba?= =?UTF-8?q?re,=20qui=20n'ont=20donc=20pas=20de=20.git)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Perso/INTech/gitUpdate.sh | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/Perso/INTech/gitUpdate.sh b/Perso/INTech/gitUpdate.sh index 4feb0fe..24e9e4f 100755 --- a/Perso/INTech/gitUpdate.sh +++ b/Perso/INTech/gitUpdate.sh @@ -1,7 +1,7 @@ #!/bin/bash GIT_REPO="." -WORK_DIR="~/.gitAutoPull" +WORK_DIR=$HOME"/.gitAutoPull" if [ $# -gt 0 ]; then GIT_REPO="$1" @@ -10,13 +10,20 @@ fi GIT_REPO_NAME="$(echo '$GIT_REPO' | tr '/' '_' | tr -d '~')" CHECK_TIMER_FILE=$WORK_DIR/localCommitsCheck"$GIT_REPO_NAME" -if [ ! -d "$GIT_REPO/.git/" ]; then +cd $GIT_REPO > /dev/null + +if [ $? -ne 0 ]; then + echo $GIT_REPO" Does not exist or is not a directory" + exit -2 +fi + +if [ -z "$(git rev-parse --git-dir 2>/dev/null)" ]; then echo $GIT_REPO" is not a git repository" exit -2 fi if [ ! -d $WORK_DIR ]; then - mkdir $WORK_DIR + mkdir $WORK_DIR > /dev/null fi if [ ! -d $WORK_DIR ]; then @@ -24,8 +31,6 @@ if [ ! -d $WORK_DIR ]; then exit -4 fi -cd $GIT_REPO - if [ -e $CHECK_TIMER_FILE ]; then read count < $CHECK_TIMER_FILE if [ $cout -ne 0 ]; then @@ -36,13 +41,13 @@ if [ -e $CHECK_TIMER_FILE ]; then fi fi -remoteStatus="$(git fetch --all --dry-run)" # Empty if there are no commits to fetch +remoteStatus="$(git fetch --dry-run 2>&1)" # Empty if there are no commits to fetch localStatus="$(git push -n --porcelain | grep -e'up to date')" # Empty if there are commits to push if [ -z "$remoteStatus" ]; then if [ -z "$localStatus" ]; then echo "Pushing "$GIT_REPO" updates to origin" | wall - git push | wall + git push 2>&1 | wall exit 1 fi else @@ -51,8 +56,8 @@ else echo 30 > $WORK_DIR/localCommitsCheck"$GIT_REPO_NAME" else echo "Updating "$GIT_REPO" with remote commits" | wall - git fetch --all | wall - git remote update | wall + git fetch --all 2>&1 | wall + git remote update 2>&1 | wall exit 1 fi fi