Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add vcsh locate to locate repo holding a file #268

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions vcsh.in
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ help() {
list-untracked \\
[<-a>] [<-r>]
[<repo>] List all files not tracked by all or one repositories
locate <file> Find repo tracking a given file
pull Pull from all vcsh remotes
push Push to vcsh remotes
rename <repo> \\
Expand Down Expand Up @@ -325,7 +326,7 @@ list_has_remote() {

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() {
Expand Down Expand Up @@ -529,6 +530,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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This grep feels very superfluous. Did you look into what the return being given are and if they might suffice for this logic?

echo "$VCSH_REPO_NAME"
fi
done
}

# Ignore warnings about VCSH_REPO_NAME being changed in a subshell.
# shellcheck disable=SC2031
write_gitignore() {
Expand Down Expand Up @@ -610,6 +622,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

Expand Down Expand Up @@ -643,11 +656,12 @@ elif [ "$VCSH_COMMAND" = 'version' ]; then
echo "$VCSH_SELF $VCSH_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
elif [ x"$VCSH_COMMAND" = x'delete' ] ||
elif [ x"$VCSH_COMMAND" = x'delete' ] ||
[ x"$VCSH_COMMAND" = x'enter' ] ||
[ x"$VCSH_COMMAND" = x'init' ] ||
[ x"$VCSH_COMMAND" = x'list-tracked-by' ] ||
Expand Down