1
0
Fork 0

Modifié car git output principalement sur stderr

Modification pour vérifier si c'est bien un dépôt git (Pour les bare, qui n'ont donc pas de .git)
This commit is contained in:
Teo-CD 2019-05-20 02:36:19 +02:00 committed by trotFunky
parent ab71845f55
commit a26a4e5eaa

View file

@ -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