ltworf / ltdata

IRC bot in python
2 stars 2 forks source link

Add !version command #9

Closed salto-edit closed 9 years ago

ltworf commented 9 years ago

The !version command is already handled by the commands module… Why is there a need for a new module just for that?

salto-edit commented 9 years ago

It's not and I didn't look there. Sorry for that. However, undergraduate courses teach us not to have overly long if-elif-else-constructs and disentangle concerns. What logic does commands.py share with the version command?

If you're not convinced, should I create a new PR that adds the __version__ variable with the git format string to commands.py instead? Do you think it would work for you to run git-archive to future releases?

It would be nice to have a more informative output by !version, only to know if patches were applied to the version running in your channel.

ltworf commented 9 years ago

Try typing !version to the bot, it does answer to that. They would be answering to the same command, so at the very least the functionality should be removed from there.

I suppose that what you want is a !version command that returns the HEAD commit. At the moment there are no "releases" as in, nothing is tagged. I don't know if that will ever change, but for the moment it will not.

salto-edit commented 9 years ago

Turns out you don't have to run git-archive to replace format strings, like the one for the HEAD commit hash. Another possibility is to use smudge filters that automatically run after checkout on files specified by a filter. Note that this will make changes to your working copy, which isn't a problem if you're running the bot from a directory that isn't your dev folder (-f can be used with git-checkout to ignore the changes by the previous checkout). In some cases the clean filter can be used to undo the smudge filter changes before the commit, but the git-status will always be cluttered.

Here comes how it should be possible to replace $Format:%h$ in modules/version.py with the HEAD commit hash after each checkout:

$ cat .git/info/attributes
modules/version.py filter=expand_version
$ cat .git/config
[..]
[filter "expand_version"]
    smudge = sed -e \"s/\\\\\\$Format:%h\\\\\\$/`git log --pretty=format:%h -1`/\"

The command line assigned to smudge on the last line was generated by the following command (git-config takes care of the additional escaping)

git config filter.expand_version.smudge 'sed -e "s/\\\$Format:%h\\\$/`git log --pretty=format:%h -1`/"'

Reference: https://git-scm.com/book/en/v2/Customizing-Git-Git-Attributes

ltworf commented 9 years ago

Thank you for the patch!