contrib: add script "nm-setup-git.sh" for setting up NetworkManager git repository

You can of course just clone NetworkManager repository and start hacking
as you like. However, there are a few things like git-notest which are
interesting to setup.

Add a script to do this.

The script is supposed to be idempotent and do nothing, unless
necessary. By default it also only prints what it would do.
This commit is contained in:
Thomas Haller 2022-05-31 14:21:09 +02:00
parent b9af281ac0
commit 3a478b3ec1
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728

115
contrib/scripts/nm-setup-git.sh Executable file
View file

@ -0,0 +1,115 @@
#!/bin/bash
set -e
usage() {
printf "%s [--no-test]\n" "$CMD_NAME"
printf "\n"
printf " --no-test: by default, the script only prints what it\n"
printf " would do. You can also set NO_TEST=1 environment variable.\n"
printf "\n"
}
get_bool() {
local name="$1"
local val="${!name}"
case "$val" in
1|y|yes|Yes|YES|true|True|TRUE|on|On|ON)
echo -n 1
return 0
;;
0|n|no|No|NO|false|False|FALSE|off|Off|OFF)
echo -n 0
return 0
;;
*)
printf "%s" "$2"
;;
esac
}
die() {
echo "ERROR: $*"
exit 1
}
call() {
local m=""
[ "$SKIP" = 1 ] && m="SKIP: "
if [ "$NO_TEST" != 1 ]; then
printf "WOULD: %s%s\n" "$m" "$*"
return 0
fi
printf "CALL: %s%s\n" "$m" "$*"
[ "$SKIP" = 1 ] || "$@"
}
git_config_reset() {
local key="$1"
local val="$2"
local c=(git config --replace-all "$key" "$val")
test "$#" == 2 || die "invalid arguments to git_config_add(): $@"
if [ "$(git config --get-all "$key")" = "$val" ]; then
SKIP=1 call "${c[@]}"
return 0
fi
call "${c[@]}"
}
git_config_add() {
local key="$1"
local val="$2"
local c=(git config --add "$key" "$val")
test "$#" == 2 || die "invalid arguments to git_config_add(): $@"
if git config --get-all "$key" | grep -qFx "$val"; then
SKIP=1 call "${c[@]}"
return 0
fi
call "${c[@]}"
}
CMD_NAME="$0"
NO_TEST="$(get_bool NO_TEST 0)"
for a; do
case "$a" in
--no-test)
NO_TEST=1
;;
-h|--help)
usage
exit 0
;;
*)
usage
die "Invalid argument \"$a\""
;;
esac
done
case "$(git config --get-all remote.origin.url)" in
"https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git"| \
"git@gitlab.freedesktop.org:NetworkManager/NetworkManager.git")
;;
*)
die "unexpected git repository. Expected that remote.origin.url is set to \"https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git\""
;;
esac
git_config_add blame.ignoreRevsFile '.git-blame-ignore-revs'
git_config_add notes.displayref 'refs/notes/bugs'
git_config_add remote.origin.fetch 'refs/notes/bugs:refs/notes/bugs'
git_config_reset remote.origin.pushurl 'git@gitlab.freedesktop.org:NetworkManager/NetworkManager.git'
if [ "$NO_TEST" != 1 ]; then
printf "Run with \"--no-test\" or see \"-h\"\n" >&2
printf "\n" >&2
printf " \"%s\" --no-test\n" "$CMD_NAME" >&2
fi