Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 83 lines (72 sloc) 1.97 KB
#!/bin/bash -e
## Check for updates, does a bfetch (dry-run) and reports
## the changes. This is just for convenience.
## Argument --dry-run just runs fetch --dry-run
## read input, display help if necessary
if [[ "$@" == *--help* ]]; then
cat<<EOF
Recursive fetch
This command recursively fetches changes from origin.
Usage:
git rfetch [--dry-run]
--dry-run: show what would be done without making
any changes.
EOF
exit 0;
fi
if [[ "$1" ]]; then
if [[ "$1" == "--dry-run" ]]; then
dryrun="--dry-run"
else
echo >&2 "Error: rfetch does only accept the argument --dry-run,
nothing else."
fi
fi
## ensure we are in the toplevel directory
cdup=$(git rev-parse --show-toplevel) &&
cd "$cdup" || {
echo >&2 "Cannot chdir to $cdup, the toplevel of the working tree"
exit 1
}
## check the super repository
if [[ $(git fetch $dryrun 2>&1) != '' ]]; then
output="There are updates available for the current repository.
"
fi
## check the submodules
if [ -f .gitmodules ]; then
tmp=`git submodule foreach --recursive git bfetch $dryrun 2>&1`
while read line; do
## Ok, just check line by line
## This looks like...
## Entering 'r-tutorial'
## Entering 'serie1'
## Entering 'serie1/aufgabe1'
## Entering 'serie1/aufgabe2'
## ...if there is nothing to fetch
if [[ "${line:0:10}" == "Entering '" ]]; then
lline=${line:10:$((${#line}-11))}
printed=0
##echo "$lline"
else
if [[ $printed -eq 0 ]]; then
output="${output}There are updates available for $lline.
"
printed=1
fi
fi
done <<< "$tmp"
fi
if [[ "$output" ]]; then
if [[ "$dryrun" == "--dry-run" ]]; then
cat<<EOF
${output}Use "git rfetch" to fetch updates.
Then go to the innermost submodules and use "git rpull" to merge the updates.
EOF
else
cat<<EOF
${output}Fetched updates. Now use "git rdiff" to show the differing files.
Then "git rpull" in the correct folder to merge updates.
EOF
fi
fi