summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2022-05-31 14:21:09 +0200
committerThomas Haller <thaller@redhat.com>2022-05-31 18:04:03 +0200
commit3a478b3ec128bac455170ae05bf8b5747aec6402 (patch)
treeadfc0c34e8ae988394ecd9aa0ca48495bc73faae
parentb9af281ac00639769480414f37b477fff3ae182d (diff)
downloadNetworkManager-3a478b3ec128bac455170ae05bf8b5747aec6402.tar.gz
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.
-rwxr-xr-xcontrib/scripts/nm-setup-git.sh115
1 files changed, 115 insertions, 0 deletions
diff --git a/contrib/scripts/nm-setup-git.sh b/contrib/scripts/nm-setup-git.sh
new file mode 100755
index 0000000000..29d1d7e5cc
--- /dev/null
+++ b/contrib/scripts/nm-setup-git.sh
@@ -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