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

Enable vcsh ls-file to take an option '-p' #285

Merged
merged 5 commits into from
Apr 3, 2021
Merged
Changes from 1 commit
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
12 changes: 8 additions & 4 deletions vcsh
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ help() {
delete <repo> Delete an existing repository
enter <repo> Enter repository; spawn new instance of \$SHELL
with \$GIT_DIR set.
foreach [<-g>]
foreach \\
[<-g>] [<-p>] \\
<git command> Execute a command for every repository
help Display this help text
init <repo> Initialize a new repository
Expand Down Expand Up @@ -234,17 +235,20 @@ foreach() {
# We default to prefixing `git` to all commands passed to foreach, but
# allow running in general context with -g
command_prefix=git
while getopts "g" flag; do
command_suffix='cat'
while getopts "gp" flag; do
if [ x"$1" = x'-g' ]; then
unset command_prefix
fi
if [ x"$1" = x'-p' ]; then
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This method of option parsing just doesn't work right at all, you can't use -g -p or -p -g because the manual shift is eating the argument and throwing getopts() off. Speaking of which, this isn't how getopts() is supposed to work at all, and the flag variable it sets is being ignored. I don't know how the top level option parsing got away with this for so long, but I don't think it's correct either....

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

See also #286 for a PR that fixes the getopts() usage for the main script.

command_suffix='sed "s/^/$VCSH_REPO_NAME: /"'
fi
shift 1
done
for VCSH_REPO_NAME in $(list); do
echo "$VCSH_REPO_NAME:"
GIT_DIR=$VCSH_REPO_D/$VCSH_REPO_NAME.git; export GIT_DIR
use
$command_prefix "$@"
$command_prefix "$@" | eval $command_suffix
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This doesn't feel right to me, I think we can probably do better with an exec call before running the command to setup the output stream processing. That would avoid piping everything through cat even when this option is not active, hence not potentially breaking existing possibilities.

done
hook post-foreach
}
Expand Down