diff options
| author | Louis Burda <dev@sinitax.com> | 2025-10-28 21:35:16 +0100 |
|---|---|---|
| committer | Louis Burda <dev@sinitax.com> | 2025-10-28 21:35:16 +0100 |
| commit | a6d91d21ec6f5dce4ba6ebac1cf86e5338b32ae6 (patch) | |
| tree | d20b56dbd285bb9ef58f3dc6aeab61a8a91e02a9 /src/subgit-root | |
| parent | 0246674aa837e3083ef3cb14be8aaa87492a3dd2 (diff) | |
| download | subgit-a6d91d21ec6f5dce4ba6ebac1cf86e5338b32ae6.tar.gz subgit-a6d91d21ec6f5dce4ba6ebac1cf86e5338b32ae6.zip | |
Add untested rewrite
Diffstat (limited to 'src/subgit-root')
| -rwxr-xr-x | src/subgit-root | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/subgit-root b/src/subgit-root new file mode 100755 index 0000000..1ef9650 --- /dev/null +++ b/src/subgit-root @@ -0,0 +1,27 @@ +#!/bin/bash + +# Returns the longest subpath of the given path +# which includes a .subgitrc file. + +usage() { die "Usage: subgit root [PATH]"; } + +while [ "$1" ]; do + case $1 in + -h) usage;; + --) shift; break;; + -*) die "Invalid option $1";; + *) break;; + esac +done + +[ $# -gt 1 ] && usage +path=$(realpath -m "${1:-.}") + +root=$path +while [ 1 ]; do + [ -f "$root/.subgitrc" ] && break + [ "$root" = "/" ] && die "Not a subgit repository" + root=$(dirname "$root") +done + +echo "$root" |
