summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-x.local/bin/gitrect-fix68
1 files changed, 51 insertions, 17 deletions
diff --git a/.local/bin/gitrect-fix b/.local/bin/gitrect-fix
index 13f105d..de6b498 100755
--- a/.local/bin/gitrect-fix
+++ b/.local/bin/gitrect-fix
@@ -7,21 +7,23 @@
# prefix-trim-directory,remote=URL,...
#
# For all directories found in $WORKDIR
+#
+if [ ! "$(command -v git)" ]; then
+ echo "git command not found. git must be installed and available in \$PATH to continue"
+ exit 1
+fi
# Reset all variables that might be set
DEFAULT_STATE="$HOME/.local/share/git/repolist"
WORKDIR="$HOME/.code"
verbose=0 # Variables to be evaluated as shell arithmetic should be initialized to a default or validated beforehand.
+GITVER="$(git version |cut -d " " -f 3)"
-if [ ! "$(command -v git)" ]; then
- echo "git command not found. git must be installed and available in \$PATH to continue"
- exit 1
-fi
usage="$(basename "$0") [-h] [-v -w WORKDIR -f FILE]
-Set remotes and pull new changes where:
- -w set the working directory (default: ${WORKDIR})
+Set remotes for all git repos and pull new changes where:
+ -w set the (base) working directory (default: ${WORKDIR})
-f set the git list file (default: ${DEFAULT_STATE})
-h show this help text
@@ -76,11 +78,19 @@ while :; do
shift
done
-# If there are input files (for example) that follow the options, they
-# will remain in the "$@" positional parameters.
-
+# No posix-compliant way of getting separator, so leverage OS-specifics
FS_SEPARATOR="/"
-# We aren't going to run on windows.
+if [ "$(uname -s)" = "Darwin" ]; then
+ true # Noop
+elif [ "$(uname -s)" = "Linux" ]; then
+ true # Noop
+else
+ # Windows uses backslash
+ FS_SEPARATOR="\\"
+ if [ $verbose -gt 0 ]; then
+ echo "cannot detect CPU total"
+ fi
+fi
while read -r line; do
dir=$(echo "$line" | cut -d, -f 1)
@@ -96,28 +106,47 @@ while read -r line; do
fi
cd "${WORKDIR}${FS_SEPARATOR}${dir}" || exit
if [ $clone -gt 0 ]; then
- git init
+ if [ ${GITVER} \> "2.45" ]; then
+ git init --ref-format=reftable
+ else
+ git init
+ fi
fi
if [ $verbose -gt 1 ]; then
- echo "Remote list: ${remlist}"
+ echo "Remote url: ${remlist}"
fi
+ localRemotes=$(eval "git remote")
+ len_localRemotes=${#localRemotes}
echo "${remlist}" | awk -F ',' '{for (i = 1; i <= NF; i++) {printf "%s \n", $i}; printf "\n"}' | while read -r r || [ -n "$r" ]; do
remoteName=$(echo "$r" | awk -F'=' '{print $1}') # Just get the remote name
# Allow for blank / newlines during processing
if [ "${remoteName}" = "" ]; then continue; fi
- if [ -d .git/refs/remotes/"$remoteName" ]; then
- if [ $verbose -gt 0 ]; then
- echo "Setting remote ${r}"
+
+ if [ $len_localRemotes -gt 0 ]; then
+ remExistsCheck=$(eval "git config remote.${remoteName}.url")
+ if [ "${remExistsCheck}" = "" ] ; then
+ if [ $verbose -gt 0 ]; then
+ echo "Adding remote ${r}"
+ fi
+ echo "$r" | awk -F'=' '{ print $1, $2; }' | xargs -n 2 git remote add
+ else
+ if [ $verbose -gt 0 ]; then
+ echo "Setting remote ${r}"
+ fi
+ echo "$r" | awk -F'=' '{ print $1, $2; }' | xargs -n 2 git remote set-url
fi
- echo "$r" | awk -F'=' '{ print $1, $2; }' | xargs -n 2 git remote set-url
else
-
+ # Remotes not set locally
if [ $verbose -gt 0 ]; then
echo "Adding remote ${r}"
fi
echo "$r" | awk -F'=' '{ print $1, $2; }' | xargs -n 2 git remote add
fi
done
+ if [ $verbose -gt 1 ]; then
+ echo "Listed remotes for ${dir} are:"
+ git remote -v ;
+ fi
if [ $clone -gt 0 ]; then
git fetch --all
rev=$(git ls-remote origin | grep HEAD | cut -f 1)
@@ -132,6 +161,11 @@ while read -r line; do
fi
done <"$DEFAULT_STATE"
+# Re-run confgit if it exists
+if [ "$(command -v confgit.sh)" ]; then
+ confgit.sh
+fi
+
# Update all remotes if we have the fetchgit command
if [ "$(command -v fetchgit)" ]; then
find "$WORKDIR" -name ".git" -exec fetchgit {} \;