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:
parent
ab71845f55
commit
a26a4e5eaa
1 changed files with 14 additions and 9 deletions
|
@ -1,7 +1,7 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
GIT_REPO="."
|
GIT_REPO="."
|
||||||
WORK_DIR="~/.gitAutoPull"
|
WORK_DIR=$HOME"/.gitAutoPull"
|
||||||
|
|
||||||
if [ $# -gt 0 ]; then
|
if [ $# -gt 0 ]; then
|
||||||
GIT_REPO="$1"
|
GIT_REPO="$1"
|
||||||
|
@ -10,13 +10,20 @@ fi
|
||||||
GIT_REPO_NAME="$(echo '$GIT_REPO' | tr '/' '_' | tr -d '~')"
|
GIT_REPO_NAME="$(echo '$GIT_REPO' | tr '/' '_' | tr -d '~')"
|
||||||
CHECK_TIMER_FILE=$WORK_DIR/localCommitsCheck"$GIT_REPO_NAME"
|
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"
|
echo $GIT_REPO" is not a git repository"
|
||||||
exit -2
|
exit -2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -d $WORK_DIR ]; then
|
if [ ! -d $WORK_DIR ]; then
|
||||||
mkdir $WORK_DIR
|
mkdir $WORK_DIR > /dev/null
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -d $WORK_DIR ]; then
|
if [ ! -d $WORK_DIR ]; then
|
||||||
|
@ -24,8 +31,6 @@ if [ ! -d $WORK_DIR ]; then
|
||||||
exit -4
|
exit -4
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cd $GIT_REPO
|
|
||||||
|
|
||||||
if [ -e $CHECK_TIMER_FILE ]; then
|
if [ -e $CHECK_TIMER_FILE ]; then
|
||||||
read count < $CHECK_TIMER_FILE
|
read count < $CHECK_TIMER_FILE
|
||||||
if [ $cout -ne 0 ]; then
|
if [ $cout -ne 0 ]; then
|
||||||
|
@ -36,13 +41,13 @@ if [ -e $CHECK_TIMER_FILE ]; then
|
||||||
fi
|
fi
|
||||||
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
|
localStatus="$(git push -n --porcelain | grep -e'up to date')" # Empty if there are commits to push
|
||||||
|
|
||||||
if [ -z "$remoteStatus" ]; then
|
if [ -z "$remoteStatus" ]; then
|
||||||
if [ -z "$localStatus" ]; then
|
if [ -z "$localStatus" ]; then
|
||||||
echo "Pushing "$GIT_REPO" updates to origin" | wall
|
echo "Pushing "$GIT_REPO" updates to origin" | wall
|
||||||
git push | wall
|
git push 2>&1 | wall
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
|
@ -51,8 +56,8 @@ else
|
||||||
echo 30 > $WORK_DIR/localCommitsCheck"$GIT_REPO_NAME"
|
echo 30 > $WORK_DIR/localCommitsCheck"$GIT_REPO_NAME"
|
||||||
else
|
else
|
||||||
echo "Updating "$GIT_REPO" with remote commits" | wall
|
echo "Updating "$GIT_REPO" with remote commits" | wall
|
||||||
git fetch --all | wall
|
git fetch --all 2>&1 | wall
|
||||||
git remote update | wall
|
git remote update 2>&1 | wall
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Add table
Reference in a new issue