Correction du cas où on a des commits locaux donc le fetch indique quelque chose
Gestion de plusieurs dépôts par un script Changements utilitaires pour le wall
This commit is contained in:
parent
a26a4e5eaa
commit
27776d5a12
1 changed files with 60 additions and 54 deletions
|
@ -1,12 +1,15 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
export LC_ALL=POSIX
|
||||||
GIT_REPO="."
|
|
||||||
WORK_DIR=$HOME"/.gitAutoPull"
|
WORK_DIR=$HOME"/.gitAutoPull"
|
||||||
|
|
||||||
|
work_array="."
|
||||||
|
|
||||||
if [ $# -gt 0 ]; then
|
if [ $# -gt 0 ]; then
|
||||||
GIT_REPO="$1"
|
work_array=$@
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
for GIT_REPO in $work_array ; do
|
||||||
|
|
||||||
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"
|
||||||
|
|
||||||
|
@ -41,25 +44,28 @@ if [ -e $CHECK_TIMER_FILE ]; then
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
remoteStatus="$(git fetch --dry-run 2>&1)" # Empty if there are no commits to fetch
|
remoteStatus="$(git fetch --dry-run 2>&1 | tail -n 1 | grep -v -e'+')" # 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"
|
||||||
git push 2>&1 | wall
|
git push 2>&1
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
if [ -z "localStatus" ]; then
|
if [ -z "localStatus" ]; then
|
||||||
echo "Local and remote diverged, stopping auto-update for 30 iterations..." | wall
|
echo "Local and remote diverged, stopping auto-update for 30 iterations..."
|
||||||
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"
|
||||||
git fetch --all 2>&1 | wall
|
git fetch --all 2>&1
|
||||||
git remote update 2>&1 | wall
|
git remote update 2>&1
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi } | wall
|
||||||
|
|
||||||
|
done
|
||||||
|
|
||||||
exit 0
|
exit 0
|
Loading…
Add table
Reference in a new issue