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

Sort plugin exec order #41

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion PLUGINS.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Location | Contains
`./.git-semver/plugins` | Project plugins (added and committed) which run on just the current git project
`${HOME}/.git-semver/plugins/` | User plugins which run on all git projects

Plugin can stop a tag being generated (for example if a version file does not exist).
Plugins are executed orderedly, so you can number-prefix them to ensure execution order. Number prefixed plugins will run before anything else, and they will be executed from lower to higher. Plugins can also stop a tag being generated (for example if a version file does not exist).

See [Contributing](#contributing) for detail on creating a plugin or take a look at the [example plugin] or any of the [real plugins](#plugins).

Expand Down
10 changes: 9 additions & 1 deletion git-semver.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,15 @@ plugin-list() {
plugin_dir="${dirs[${i}]}/.git-semver/plugins"
if [ -d "${plugin_dir}" ]
then
find "${plugin_dir}" -maxdepth 1 -type f -exec echo "${plugin_type},{}" \;
plugins=()
Copy link
Owner

Choose a reason for hiding this comment

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

Is this variable needed? I can't see it being referenced in the following code.

Copy link
Owner

Choose a reason for hiding this comment

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

Actually I realise this may have been to cache the result of the find. That would save a command.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that might actually be a mistake. I don't see it in the master branch of this repo, and I added it on the Fixed MacOS compatibility commit for no apparent reason. And, if it actually does any caching, I can't see how, but I'm happy to leave it there if it's useful.

for plugin in $(find "${plugin_dir}" -maxdepth 1 -type f -exec basename {} \; | grep "^[0-9]" | LC_ALL="C" sort -g)
Copy link
Owner

Choose a reason for hiding this comment

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

Probably worth a quick comment here as to why the loop is run twice.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That loop is ran twice to first echo the numeric prefixed plugins (note that the output is piped to a grep) and then echo the not numeric ones. This is basically what you suggested doing in this comment.

As you also said, it's hacky, but I really couldn't come with a better solution :/

do
echo "${plugin_type},${plugin_dir}/${plugin}"
done
for plugin in $(find "${plugin_dir}" -maxdepth 1 -type f -exec basename {} \; | grep "^[^0-9]" | LC_ALL="C" sort -g)
do
echo "${plugin_type},${plugin_dir}/${plugin}"
done
fi
done
}
Expand Down