Code.Art.Web

Code.Art.Web

Profile Picture

Lorefnon

Commit messages from generator outputs


A practise I always follow while working with tools that generate code is that any code that is generated and not written by me is committed in isolation. This makes skimming through commit logs later easier because generators often generate many files upfront that wouldn't be edited until much later. So the subsequent commit wouldn't be littered with changes that aren't directly related to the actual operation mentioned in the commit message. Also while browsing through commit diffs keeping generated code in their own commits speeds up the reviewing process - because in most cases we already have an idea of what the generated could be, so it can be skipped.

Now, if you use well designed frameworks with elegant command line interfaces, like Rails then the actual command typed along with the command output eg.

rails generate model post title:string body:text

invoke  active_record
create    db/migrate/20140913191020_create_posts.rb
create    app/models/post.rb
invoke    rspec
create      spec/models/post_spec.rb

is expressive enough for a commit message. A person familiar enough with the framework can instantly see the above and know what happened there. In such case, spending time writing an explanatory commit message for a auto-generated code is pretty much a waste of time.

So I have created a simple zsh function which does exactly the above:

GC ()
{
  cmd="$@"
  output=$("$@")
  git add .
  git commit -m "$cmd" -m "$output"
}

Add it to your zshrc, and next time you can simply type :

GC rails g model comment body:text commenter:string

GC will add all the generated code (please ensure you have a clean state before running the generator - GC will not help you that) and committing it with the message as the command combined with the output of generator in separate paragraphs.

commit 029cb2e60187a196d918a08563d95775d73f5100
Author: Lorefnon <[email protected]>
Date:   Sun Sep 14 00:58:03 2014 +0530

    rails g model comment body:text commenter:string

          invoke  active_record
          create    db/migrate/20140913192803_create_comments.rb
          create    app/models/comment.rb
          invoke    rspec
          create      spec/models/comment_spec.rb

comments powered by Disqus
Separator line
Separator line
Lorefnon

Full stack web developer and polyglot programmer with strong interest in dynamic languages, web application development and user experience design.


Strong believer in agile methodologies, behaviour driven development and efficacy of open source technologies.


© 2013 - 2015 Gaurab Paul


Code licensed under the The MIT License. Content and Artwork licensed under CC BY-NC-SA.


The opinions expressed herein are my personal viewpoints and may not be taken as professional recommendations from any of my previous or current employers.


Site is powered by Jekyll and graciously hosted by Github