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 | |
| parent | 0246674aa837e3083ef3cb14be8aaa87492a3dd2 (diff) | |
| download | subgit-a6d91d21ec6f5dce4ba6ebac1cf86e5338b32ae6.tar.gz subgit-a6d91d21ec6f5dce4ba6ebac1cf86e5338b32ae6.zip | |
Add untested rewrite
| -rw-r--r-- | Makefile | 15 | ||||
| -rw-r--r-- | completion.sh | 3 | ||||
| -rwxr-xr-x | install.sh | 48 | ||||
| -rwxr-xr-x | src/subgit | 90 | ||||
| -rwxr-xr-x | src/subgit-add | 67 | ||||
| -rwxr-xr-x | src/subgit-check | 48 | ||||
| -rwxr-xr-x | src/subgit-clone | 29 | ||||
| -rwxr-xr-x | src/subgit-genrc | 12 | ||||
| -rwxr-xr-x | src/subgit-init | 88 | ||||
| -rwxr-xr-x | src/subgit-ls | 10 | ||||
| -rwxr-xr-x | src/subgit-parent | 27 | ||||
| -rwxr-xr-x | src/subgit-relpath | 30 | ||||
| -rwxr-xr-x | src/subgit-root | 27 | ||||
| -rwxr-xr-x | src/subgit-run | 16 | ||||
| -rwxr-xr-x | src/subgit-save | 30 | ||||
| -rwxr-xr-x | src/subgit-subrepo | 34 | ||||
| -rwxr-xr-x | subgit | 34 | ||||
| -rwxr-xr-x | subgit-add | 35 | ||||
| -rwxr-xr-x | subgit-init | 35 | ||||
| -rwxr-xr-x | subgit-run | 20 | ||||
| -rwxr-xr-x | subgit-update | 17 | ||||
| -rwxr-xr-x | subgit-write | 20 |
22 files changed, 559 insertions, 176 deletions
diff --git a/Makefile b/Makefile deleted file mode 100644 index b7cc33e..0000000 --- a/Makefile +++ /dev/null @@ -1,15 +0,0 @@ -DESTDIR ?= -PREFIX ?= /usr/local -BINDIR ?= /bin - -BINS = subgit subgit-run subgit-init subgit-update subgit-write subgit-add - -all: - -uninstall: - echo -e $(BINS) | xargs -d' ' -I{} rm -f "$(DESTDIR)$(PREFIX)$(BINDIR)/{}" - -install: - install -m755 $(BINS) -t "$(DESTDIR)$(PREFIX)$(BINDIR)" - -.PHONY: install uninstall all diff --git a/completion.sh b/completion.sh new file mode 100644 index 0000000..199ddbb --- /dev/null +++ b/completion.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +complete -W "$(ls "$(dirname "$(which subgit)")" | grep subgit- | cut -d- -f2-)" subgit diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..3b2fe10 --- /dev/null +++ b/install.sh @@ -0,0 +1,48 @@ +#!/bin/bash + +die() { echo "$@" 1>&2; exit 1; } +usage() { die "Usage: install.sh [-h] [-d] [-l] [-u]"; } + +link=0 +install=1 +debug=1 +while [ "$1" ]; do + case $1 in + -l) link=1; shift;; + -u) install=0; shift;; + -d) debug=1; shift;; + -h) usage;; + --) shift; break;; + -*) die "Invalid option $1";; + *) break;; + esac +done +[ $# -ne 0 ] && usage + +[ $debug ] && set -x + +PREFIX=${PREFIX:-/usr/local} +BINDIR=${BINDIR:-/bin} + +bins=(subgit) +bins+=(subgit-*) + +if [ $install -eq 1 ]; then + if [ $link -eq 1 ]; then + for bin in "${bins[@]}"; do + ln -sf "$PWD/src/$bin" -t "$HOME/.local/bin" + done + else + install -m755 subgit src/subgit-* -t "$DESTDIR$PREFIX$BINDIR" + fi +else + if [ $link -eq 1 ]; then + for bin in "${bins[@]}"; do + rm "$HOME/.local/bin/$bin" + done + else + for bin in "${bins[@]}"; do + rm -f "$DESTDIR$PREFIX$BINDIR/$bin" + done + fi +fi diff --git a/src/subgit b/src/subgit new file mode 100755 index 0000000..b2dce0d --- /dev/null +++ b/src/subgit @@ -0,0 +1,90 @@ +#!/bin/bash + +set -e + +sg_flags=() +if [ "$1" = "-d" ]; then + sg_flags+=("-d") + set -x + shift +fi + +for a in "$@"; do + if [ "$a" = "-h" -o "$a" = "--help" ]; then + echo "Usage: subgit CMD ARG.." + echo "Available commands:" + bindir=$(dirname $(realpath "$0")) + i=0 + for l in $(ls "$bindir"); do + if [[ $l =~ subgit-.* ]]; then + [ $(($i % 6)) -eq 0 ] && echo -n " " + echo -n "$(echo "$l" | cut -d- -f2), " + i=$(($i+1)) + [ $(($i % 6)) -eq 0 ] && echo + fi + done + [ $(($i % 6)) -ne 0 ] && echo + exit 1 + fi +done + +if [ "$1" = "-C" ]; then + cd "$2" + shift + shift +fi + +warn() { + echo "$@" 1>&2 +} + +die() { + echo "$@" 1>&2 + exit 1 +} + +wd() { + [ $# -lt 2 ] && echo "wd DIR CMD.." + pushd "$1" &>/dev/null + shift + "$@" + popd &>/dev/null +} + +cmd="$1" +shift + +if [ "$cmd" = "--" ]; then + cmd="run" +fi + +if ! type -P "subgit-$cmd" &>/dev/null; then + echo "Unknown cmd subgit-$cmd" 1>&2 + exit 1 +fi + +verbose-err() { + local ss=$? bc="$BASH_COMMAND" ln="$BASH_LINENO" + set +e + echo "$(basename "${BASH_SOURCE[1]}"):$ln ($ss): $bc" >&2 + exit $ss +} + +subgit-source() { + cmd="$1"; shift + source "subgit-$cmd" +} + +subgit-sub() { + (subgit-source "$@") +} + +bindir=$(dirname "$(realpath "$0")") +if ! [[ $PATH =~ $bindir:* ]]; then + export PATH="$bindir:$PATH" +fi + +( + trap verbose-err ERR + source "subgit-$cmd" +) diff --git a/src/subgit-add b/src/subgit-add new file mode 100755 index 0000000..d1082f4 --- /dev/null +++ b/src/subgit-add @@ -0,0 +1,67 @@ +#!/bin/bash + +usage() { + die $(cat <<-EOF + Usage: subgit add [-c COMMIT] [-b BRANCH] [ARG..] REMOTE DEST + + Begin tracking a remote repository, optionally at a specific branch + or commit, as a subgit repo in the current path. Can also be used + to add an existing repos. + EOF +} + +branch= +commit= +initargs=() +while [ "$1" ]; do + case $1 in + -b) [ $# -lt 2 ] && die "Missing branch" || branch="$2"; shift; shift;; + -c) [ $# -lt 2 ] && die "Missing commit" || commit="$2"; shift; shift;; + -h) usage;; + --) shift; break;; + -*) initargs+=("$1"); shift;; + *) break;; + esac +done +[ $# -ne 2 ] && usage +remote=$1 +path=$(realpath -m $2) + +root=$(realpath .) +[ "${path#$root/}" = "$path" ] && die "Not a subdirectory" + +relpath=$(realpath -m --relative-to="$root" "$path") + +alt_root=$(subgit-sub root "$path" &>/dev/null) +if [ ! -z "$alt_root" ]; then + alt_relpath=$(subgit-sub relpath "$alt_root" "$path" &>/dev/null) + if [ ! -z "$alt_relpath" ]; then + if [ "${alt_relpath#$relpath}" != "${alt_relpath}" ]; then + die "Already tracked in $alt_root" + fi + fi +fi + +if [ -d "$path" ]; then + warn "Path $relpath already exists, adding.." + mkdir -p "$(dirname "$root/.subgit/$relpath")" + mv "$path/.git" "$root/.subgit/$relpath" +fi + +if [ -e "$root/.subgitrc" ]; then + source "$root/.subgitrc" + [ ! -z "${subgit[$relpath]}" ] && \ + die "Subrepo $relpath already added" +else + subgit-source genrc > "$root/.subgitrc" + source "$root/.subgitrc" +fi + +subgit[$relpath]=1 +subgitinfo[$relpath/remote]=$remote +subgitinfo[$relpath/branch]=$branch +subgitinfo[$relpath/commit]=$commit + +subgit-source genrc > "$root/.subgitrc" # in case init fails + +subgit-source init -S -u "${initargs[@]}" diff --git a/src/subgit-check b/src/subgit-check new file mode 100755 index 0000000..2ba748b --- /dev/null +++ b/src/subgit-check @@ -0,0 +1,48 @@ +#!/bin/bash + +# Checks whether the branch / commit tracked by subgit for the +# specified repos are up-to-date, and whether the worktree is dirty. + +usage() { die "Usage: subgit check PATH.."; } + +while [ "$1" ]; do + case $1 in + -h) usage;; + --) shift; break;; + -*) die "Invalid option $1";; + *) break;; + esac +done + +subgit-sub subrepo "$@" | while read -r subrepo; do + root=$(subgit-sub parent "$subrepo") + relpath=$(realpath -m --relative-to="$root" "$subrepo") + + source "$root/.subgitrc" + + bare="$root/.subgit/$relpath" + if [ ! -d "$bare" ]; then + warn "Subrepo $relpath uninitialized" + continue + fi + + remote=$(git -C "$bare" remote get-url origin) + if [ "${subgitinfo[$relpath/remote]}" != "$remote" ]; then + echo "$relpath: new remote - '$remote'" + fi + + branch=$(git -C "$bare" branch --show-current) + if [ "${subgitinfo[$relpath/branch]}" != "$branch" ]; then + echo "$relpath: new branch - '$branch'" + fi + + commit=$(git -C "$bare" rev-parse --verify HEAD) + if [ "${subgitinfo[$relpath/commit]}" != "$commit" ]; then + echo "$relpath: new commit - '$commit'" + fi + + dirty=$(git -C "$subrepo" diff --stat 2>/dev/null | head -n1) + if [ ! -z "$dirty" ]; then + echo "$relpath: dirty tree" + fi +done diff --git a/src/subgit-clone b/src/subgit-clone new file mode 100755 index 0000000..7831519 --- /dev/null +++ b/src/subgit-clone @@ -0,0 +1,29 @@ +#!/bin/bash + +# Clones a repository for use in .subgit for tracking worktree changes. + +usage() { die "Usage: subgit clone [-b BRANCH] [CLONE-ARGS..] REMOTE PATH"; } + +while [ "$1" ]; do + case $1 in + -b) [ $# -lt 2 ] && die "Missing branch" || branch="$2"; shift; shift;; + -h) usage;; + --) shift; break;; + -*) die "Invalid option $1";; + *) break;; + esac +done + +[ $# -lt 2 ] && usage + +path="${@: -1}" +[ -d "$path" ] && die "Path already exists" + +args=() +if [ ! -z "$branch" ]; then + args+=(--single-branch -b "$branch") +fi +git clone --bare "${args[@]}" "$@" +git -C "$path" config --local --bool core.bare false +git -C "$path" config --local remote.origin.fetch \ + "+refs/heads/*:refs/remotes/origin/*" diff --git a/src/subgit-genrc b/src/subgit-genrc new file mode 100755 index 0000000..d6c3a75 --- /dev/null +++ b/src/subgit-genrc @@ -0,0 +1,12 @@ +#!/bin/bash + +echo -e "#!/bin/bash\n" +echo -e "declare -A subgit subgitinfo\n" + +for subrepo in ${!subgit[@]}; do + echo "subgit[$subrepo]=1" + echo "subgitinfo[$subrepo/remote]='${subgitinfo[$subrepo/remote]}'" + echo "subgitinfo[$subrepo/branch]='${subgitinfo[$subrepo/branch]}'" + echo "subgitinfo[$subrepo/commit]='${subgitinfo[$subrepo/commit]}'" + echo "" +done diff --git a/src/subgit-init b/src/subgit-init new file mode 100755 index 0000000..3299f76 --- /dev/null +++ b/src/subgit-init @@ -0,0 +1,88 @@ +#!/bin/bash + +# Initializes or updates the bare repository in the subgit container. + +usage() { die "Usage: subgit [init|pull] [-r] [PATH..]"; } + +recursive= +force= +update= +do_source=1 +while [ "$1" ]; do + case $1 in + -h) usage;; + -r) recursive=-r; shift;; + -u) update=-u; shift;; + -f) force=-f; shift;; + -S) do_source=0; shift;; + --) shift; break;; + -*) die "Invalid option $1";; + *) break;; + esac +done + +if [ $do_source -eq 1 ]; then + root=$(subgit-source root .) + source "$root/.subgitrc" +fi + +readarray -t subrepos < <(subgit-sub subrepo "$@") + +for subrepo in "${subrepos[@]}"; do + echo "$subrepo" + + root=$(subgit-sub parent "$subrepo") + relpath=$(realpath -m --relative-to="$root" "$subrepo") + + bare="$root/.subgit/$relpath" + workdir="$root/$relpath" + test "$workdir" = "$subrepo" + + [ ! -d "$workdir" ] && mkdir -p "$workdir" + + clone=0 + commit=${subgitinfo[$relpath/commit]:-HEAD} + branch=${subgitinfo[$relpath/branch]} + if [ ! -d "$bare" ]; then + clone=1 + mkdir -p "$(dirname "$bare")" + clone_args=() + [ ! -z "$branch" ] && clone_args+=(-b "$branch") + subgit-sub clone "${clone_args[@]}" \ + "${subgitinfo[$relpath/remote]}" "$bare" + fi + + link_relpath=$(realpath --relative-to="$workdir" "$bare") + ln -sf "$link_relpath" -T "$workdir/.git" + + if [ ! -z "$branch" ]; then + fetch_spec=(origin "$branch") + else + fetch_spec=(-a) + fi + + if ! git -C "$workdir" cat-file -e "$commit" 2>/dev/null; then + git -C "$workdir" fetch "${fetch_spec[@]}" + fi + + if [ $clone -eq 1 -o ! -z "$force" ]; then + git -C "$workdir" reset --hard + fi + + if [ ! -z "$branch" ]; then + git -C "$workdir" switch "$branch" + fi + + git -C "$workdir" reset --soft "$commit" +done + +if [ ! -z "$update" ]; then + subgitinfo[$relpath/commit]=$(git -C "$workdir" rev-parse HEAD) + subgit-source write +fi + +for subrepo in "${subrepos[@]}"; do + if [ ! -z "$recursive" -a -e "$subrepo/.subgitrc" ]; then + subgit "${sg_flags[@]}" -C "$subrepo" init $force $recursive $update + fi +done diff --git a/src/subgit-ls b/src/subgit-ls new file mode 100755 index 0000000..3f8c6f0 --- /dev/null +++ b/src/subgit-ls @@ -0,0 +1,10 @@ +#!/bin/bash + +[ "$1" = "-h" ] && die "Usage: subgit ls" + +root=$(subgit-source root .) +source "$root/.subgitrc" + +for subrepo in "${!subgit[@]}"; do + echo "$subrepo" +done diff --git a/src/subgit-parent b/src/subgit-parent new file mode 100755 index 0000000..92ac56b --- /dev/null +++ b/src/subgit-parent @@ -0,0 +1,27 @@ +#!/bin/bash + +# Returns the longest subpath of the given path, which +# tracks the current path in its .subgit folder. + +usage() { die "Usage: subgit parent [PATH]"; } + +while [ "$1" ]; do + case $1 in + -h) usage;; + --) shift; break;; + -*) die "Invalid option $1";; + *) break;; + esac +done +[ $# -gt 1 ] && usage +path=$(realpath "${1:-.}") + +root="$path" +while [ 1 ]; do + root=$(subgit-sub root "$(dirname "$root")") + if subgit-sub relpath "$root" "$path" &>/dev/null; then + break + fi +done + +echo "$root" diff --git a/src/subgit-relpath b/src/subgit-relpath new file mode 100755 index 0000000..6e47625 --- /dev/null +++ b/src/subgit-relpath @@ -0,0 +1,30 @@ +#!/bin/bash + +# Finds the relative path at which tracking for a target path +# starts within its subgit parent. + +usage() { die "Usage: subgit relpath ROOT PATH"; } + +while [ "$1" ]; do + case $1 in + -h) usage;; + --) shift; break;; + -*) die "Invalid option $1";; + *) break;; + esac +done + +[ $# -ne 2 ] && usage +root=$1 +path=$2 + +source "$root/.subgitrc" + +relpath=$(realpath -m --relative-to="$root" "$path") +while [ 1 ]; do + [ ! -z "${subgit[$relpath]}" ] && break + [ "$relpath" = "." ] && die "Not tracked" + relpath=$(dirname "$relpath") +done + +echo "$relpath" 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" diff --git a/src/subgit-run b/src/subgit-run new file mode 100755 index 0000000..98f6be7 --- /dev/null +++ b/src/subgit-run @@ -0,0 +1,16 @@ +#!/bin/bash + +[ $# -eq 0 ] && die "Usage: subgit run CMD [ARG..]" + +root="$(subgit-sub root)" +relpath=$(subgit-sub relpath "$root" .) +path="$root/$relpath" +if [ ! -e "$path" ]; then + echo "Subgit for $path not initialized?" + exit 1 +fi + +trap 'unlink "$path/.git"' EXIT +ln -sf "$repo/.subgit/$relpath" "$path/.git" + +"$@" diff --git a/src/subgit-save b/src/subgit-save new file mode 100755 index 0000000..3f6e8d1 --- /dev/null +++ b/src/subgit-save @@ -0,0 +1,30 @@ +#!/bin/bash + +[ "$1" = "-h" ] && die "Usage: subgit update [PATH..]" + +root=$(subgit-sub root .) +source "$root/.subgitrc" + +if [ $# -eq 0 ]; then + subrepos=${!subgit[@]} +else + subrepos=() + for a in "$@"; do + parent=$(dirname "$(realpath "$a")") + [ "$root" != "$(subgit-sub root "$parent")" ] \ + && die "Subgits do not have same parent" + subrepos+=($(subgit-sub relpath "$a")) + done +fi + +for subrepo in $subrepos; do + if [ ! -d "$root/.subgit/$subrepo" -o ! -d "$root/$subrepo" ]; then + die "Subrepo $subrepo uninitialized" + fi + subgit[$subrepo]=1 + subgitinfo[$subrepo/remote]=$(git -C "$root/.subgit/$subrepo" remote get-url origin) + subgitinfo[$subrepo/branch]=$(git -C "$root/.subgit/$subrepo" branch --show-current) + subgitinfo[$subrepo/commit]=$(git -C "$root/.subgit/$subrepo" rev-parse --verify HEAD) +done + +source subgit-write diff --git a/src/subgit-subrepo b/src/subgit-subrepo new file mode 100755 index 0000000..713d32f --- /dev/null +++ b/src/subgit-subrepo @@ -0,0 +1,34 @@ +#!/bin/sh + +# Return either the subrepo path for each path or all +# subrepo paths in the current subgit container. + +usage() { die "Usage: subgit subrepo [PATH..]"; } + +while [ "$1" ]; do + case $1 in + -h) usage;; + --) shift; break;; + -*) die "Invalid option $1";; + *) break;; + esac +done + +subrepos=() +if [ $# -eq 0 ]; then + root=$(subgit-sub root) + source "$root/.subgitrc" + for relpath in "${!subgit[@]}"; do + subrepos+=("$root/$relpath") + done +else + for arg in "$@"; do + root=$(subgit-sub parent "$arg") + relpath=$(subgit-sub relpath "$root" "$arg") + subrepos+=("$root/$relpath") + done +fi + +for subrepo in ${subrepos[@]}; do + echo "$subrepo" +done @@ -1,34 +0,0 @@ -#!/bin/bash - -set -e - -if [ "$1" = "-d" ]; then - set -x - shift -fi - -if [ "$1" = "-C" ]; then - cd "$2" - shift - shift -fi - -die() { - echo "$@" 2>&1 - exit 1 -} - -cmd="$1" -shift - -if [ "$cmd" = "--" ]; then - cmd="run" -fi - -if [ -z "$(which "subgit-$cmd" 2>/dev/null)" ]; then - echo "Unknown command $cmd" 1>&2 - exit 1 -fi - -trap 'echo "Error at during $cmd"' ERR -( source "subgit-$cmd"; ) diff --git a/subgit-add b/subgit-add deleted file mode 100755 index c6b62a2..0000000 --- a/subgit-add +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/bash - -[ $# -lt 2 ] && die "Usage: subgit clone [GIT-OPT..] REMOTE PATH" - -repo=$(realpath "$(git rev-parse --show-toplevel)") -subrepo=$(realpath "${@: -1}") -subrepo=${subrepo#$repo/} - -[ ! -z "$subrepo" -a "$subrepo" != "/" ] - -if [ -e "$repo/.subgitrc" ]; then - source "$repo/.subgitrc" -else - declare -A subgit subgitinfo -fi - -[ -e "$repo/$subrepo" ] && die "Subrepo $subrepo already exists" - -trap '[ ! -z "$repo" -a ! -z "$subrepo" ] && rm -rf "$repo/$subrepo"' exit -git clone "$@" - -[ ! -e "$repo/$subrepo" ] && die "Subrepo $subrepo missing" - -mkdir -p $(dirname "$repo/.subgit/$subrepo") -rm -rf "$repo/.subgit/$subrepo" -mv "$repo/$subrepo/.git" "$repo/.subgit/$subrepo" - -subgit[$subrepo]=1 -subgitinfo[$subrepo/remote]=$(git -C "$repo/.subgit/$subrepo" remote get-url origin) -subgitinfo[$subrepo/branch]=$(git -C "$repo/.subgit/$subrepo" branch --show-current) -subgitinfo[$subrepo/commit]=$(git -C "$repo/.subgit/$subrepo" rev-parse --verify HEAD) - -source subgit-write - -trap - exit diff --git a/subgit-init b/subgit-init deleted file mode 100755 index 3455cfe..0000000 --- a/subgit-init +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/bash - -if [ "$1" = "-r" ]; then - recursive=-r - shift -fi - -[ $# -ne 0 ] && die "Usage: subgit init" - -repo=$(realpath "$(git rev-parse --show-toplevel)") -source "$repo/.subgitrc" - -for subrepo in ${!subgit[@]}; do - path="$repo/.subgit/$subrepo" - [ -d "$repo/$subrepo" ] || mkdir -p "$repo/$subrepo" - if [ ! -d "$path" ]; then - mkdir -p "$(dirname "$path")" - branch_args=() - if [ ! -z "${subgitinfo[$subrepo/branch]}" ]; then - branch_args+=(--single-branch -b "${subgitinfo[$subrepo/branch]}") - fi - git clone --bare "${branch_args[@]}" \ - "${subgitinfo[$subrepo/remote]}" "$path" - git -C "$path" config --local --bool core.bare false - subgit -C "$repo/$subrepo" -- git reset --hard "${subgitinfo[$subrepo/commit]}" - elif [ ! -z "${subgitinfo[$subrepo/branch]}" ]; then - subgit -C "$repo/$subrepo" -- git checkout "${subgitinfo[$subrepo/branch]}" - subgit -C "$repo/$subrepo" -- git reset "${subgitinfo[$subrepo/commit]}" - else - subgit -C "$repo/$subrepo" -- git checkout "${subgitinfo[$subrepo/commit]}" - fi - if [ ! -z "$recursive" -a -e "$repo/$subrepo/.subgitrc" ]; then - subgit -C "$repo/$subrepo" -- subgit init "$recursive" - fi -done diff --git a/subgit-run b/subgit-run deleted file mode 100755 index 8b8e6db..0000000 --- a/subgit-run +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -[ $# -eq 0 ] && die "Usage: subgit run CMD [ARG..]" - -repo=$(realpath "$(git rev-parse --show-toplevel)") -[ "${PWD#$repo/}" != "$PWD" ] || die "Bad path $repo > $PWD" - -path=$PWD -while [ 1 ]; do - relpath=${path#$repo/} - [ -d "$repo/.subgit/$relpath" ] && break - path=$(dirname "$path") - echo "$path" - [ "$path" = "$repo" ] && die "No subgit found" -done - -trap 'unlink "$path/.git"' EXIT -ln -sf "$repo/.subgit/$relpath" "$path/.git" - -"$@" diff --git a/subgit-update b/subgit-update deleted file mode 100755 index 9f1a41e..0000000 --- a/subgit-update +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -[ $# -ne 0 ] && die "Usage: subgit update" - -repo=$(realpath "$(git rev-parse --show-toplevel)") -source "$repo/.subgitrc" - -for subrepo in ${!subgit[@]}; do - if [ ! -d "$repo/.subgit/$subrepo" -o ! -d "$repo/$subrepo" ]; then - die "Subrepo $subrepo uninitialized" - fi - subgitinfo[$subrepo/remote]=$(git -C "$repo/.subgit/$subrepo" remote get-url origin) - subgitinfo[$subrepo/branch]=$(git -C "$repo/.subgit/$subrepo" branch --show-current) - subgitinfo[$subrepo/commit]=$(git -C "$repo/.subgit/$subrepo" rev-parse --verify HEAD) -done - -source subgit-write diff --git a/subgit-write b/subgit-write deleted file mode 100755 index cf3a556..0000000 --- a/subgit-write +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -repo=$(realpath "$(git rev-parse --show-toplevel)") - -echo -e "#!/bin/bash\n" > "$repo/.subgitrc" -echo -e "declare -A subgit subgitinfo\n" >> "$repo/.subgitrc" - -for subrepo in ${!subgit[@]}; do - echo "subgit[$subrepo]=1" - echo "subgitinfo[$subrepo/remote]='${subgitinfo[$subrepo/remote]}'" - echo "subgitinfo[$subrepo/branch]='${subgitinfo[$subrepo/branch]}'" - echo "subgitinfo[$subrepo/commit]='${subgitinfo[$subrepo/commit]}'" - echo "" -done >> "$repo/.subgitrc" - -if [ ! -e "$repo/.gitignore" ]; then - echo "/.gitignore" > "$repo/.gitignore" -fi -cat "$repo/.gitignore" | grep -q "^/.subgit$" \ - || echo "/.subgit" >> "$repo/.gitignore" |
