From dd91eaa6f2aa0a0f9c1403b8bc3680f9836bfade Mon Sep 17 00:00:00 2001 From: "martin f. krafft" Date: Sun, 3 Nov 2019 11:39:26 +1300 Subject: [PATCH 1/2] Add `vcsh locate` to locate repo holding a file This adds the `locate` subcommand, which takes an existing file and returns the repository that's tracking the file. Signed-off-by: martin f. krafft --- vcsh | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/vcsh b/vcsh index d1d26edd..6bca5542 100755 --- a/vcsh +++ b/vcsh @@ -120,6 +120,7 @@ help() { list-untracked \\ [<-a>] [<-r>] [] List all files not tracked by all or one repositories + locate Find repo tracking a given file pull Pull from all vcsh remotes push Push to vcsh remotes rename \\ @@ -279,7 +280,7 @@ list() { get_files() { GIT_DIR=$VCSH_REPO_D/$VCSH_REPO_NAME.git; export GIT_DIR - git ls-files --full-name + git ls-files --full-name "$@" } list_tracked() { @@ -472,6 +473,17 @@ which() { fi } +locate() { + if [ ! -f "$VCSH_COMMAND_PARAMETER" ]; then + fatal "'$VCSH_COMMAND_PARAMETER' does not exist" 1 + fi + for VCSH_REPO_NAME in $(list); do + if get_files "$VCSH_COMMAND_PARAMETER" | grep -q .; then + echo "$VCSH_REPO_NAME" + fi + done +} + write_gitignore() { # Don't do anything if the user does not want to write gitignore if [ "x$VCSH_GITIGNORE" = 'xnone' ]; then @@ -547,6 +559,7 @@ case $VCSH_COMMAND in upgrad|upgra|upgr|up) VCSH_COMMAND=upgrade;; versio|versi|vers|ver|ve) VCSH_COMMAND=version;; which|whi|wh) VCSH_COMMAND=which;; + locat|loc|lo) VCSH_COMMAND=locate;; write|writ|wri|wr) VCSH_COMMAND=write-gitignore;; esac @@ -578,7 +591,8 @@ elif [ "$VCSH_COMMAND" = 'version' ]; then echo "$SELF $VERSION" git version exit -elif [ x"$VCSH_COMMAND" = x'which' ]; then +elif [ x"$VCSH_COMMAND" = x'which' ] || + [ x"$VCSH_COMMAND" = x'locate' ]; then [ -z "$2" ] && fatal "$VCSH_COMMAND: please specify a filename" 1 [ -n "$3" ] && fatal "$VCSH_COMMAND: too many parameters" 1 VCSH_COMMAND_PARAMETER=$2; export VCSH_COMMAND_PARAMETER From 964a4a6094520b2bfdbf362c52b83d7603795f3d Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Tue, 1 Jun 2021 20:58:33 +0300 Subject: [PATCH 2/2] Guard against possible files that begin with dashes --- vcsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vcsh b/vcsh index 6bca5542..aaabab86 100755 --- a/vcsh +++ b/vcsh @@ -280,7 +280,7 @@ list() { get_files() { GIT_DIR=$VCSH_REPO_D/$VCSH_REPO_NAME.git; export GIT_DIR - git ls-files --full-name "$@" + git ls-files --full-name -- "$@" } list_tracked() {