]> git.phdru.name Git - git-scripts.git/commitdiff
Feat: Delete a repository
authorOleg Broytman <phd@phdru.name>
Sun, 24 Dec 2023 09:57:30 +0000 (12:57 +0300)
committerOleg Broytman <phd@phdru.name>
Fri, 29 Dec 2023 16:11:42 +0000 (19:11 +0300)
Mostly for deleting it from `locate-all.list`.

delete [new file with mode: 0755]

diff --git a/delete b/delete
new file mode 100755 (executable)
index 0000000..6002dc4
--- /dev/null
+++ b/delete
@@ -0,0 +1,28 @@
+#! /bin/sh
+
+if [ -z "$1" -o -n "$3" ]; then
+    echo "Usage: $0 /path/to/repo" >&2
+    exit 1
+fi
+
+start_dir="`pwd`" &&
+path_to_repo="$1" &&
+cd "$path_to_repo" &&
+path_to_repo="`pwd`" &&
+cd "$start_dir" &&
+
+cd "`dirname \"$0\"`" &&
+if ! grep -q "^$path_to_repo\$" locate-all.list; then
+    echo "$path_to_repo" is not a known repository >&2
+    exit 1
+fi
+
+rm -rf "$path_to_repo" &&
+
+tmpfile="`mktemp`" &&
+grep -v "^$path_to_repo\$" locate-all.list > "$tmpfile" &&
+if cmp -s mv "$tmpfile" locate-all.list; then
+    exec rm -f "$tmpfile"
+else
+    exec mv "$tmpfile" locate-all.list
+fi