Feb 16, 2022 git · development · pairing

Add Co-Authored-By to all commits after pairing

TL;DR

Here's the full solution:

shell git filter-branch --msg-filter "ruby -e'puts [$stdin.read,nil,*ARGV].join(%{\\n})' -- 'Co-Authored-By: John Doe <[email protected]>'" origin/master..HEAD

Now let's break it down, piece by piece.

The commits

This will list all commits that are in your branch but not on origin/master

shell origin/master..HEAD

The filter

The simplest ruby script that will:

  1. read the original commit message from $stdin
  2. append any provided argument with a new line

ruby puts [ $stdin.read, nil, # extra empty line, for good measure *ARGV ].join(%{\n})

And we use -- to separate file names to execute from CLI arguments:

shell $ ruby -e 'p ARGV' -- "anything after '--'" "ends up in ARGV" ["anything after '--'", "ends up in ARGV"]

Putting it all together

We're lucky git filter-branch has an option for changing commit messages, we'll use that to append Co-Authored-By: … information to every commit in the current branch.

The --msg-filter option will execute a script that will take the old message as its standard input and use the standard output as the new message.

shell git filter-branch --msg-filter "ruby -e'puts [$stdin.read,nil,*ARGV].join(%{\\n})' -- 'Co-Authored-By: John Doe <[email protected]>'" origin/master..HEAD

The git-rebase option no-one knows that will shock your coworkers!

A few weeks ago, a moment before pushing upstream a glorious bug-fix, I ran the test suite locally, just to discover that I broke it!

Having lost all confidence in the commit history, I was out for blood, looking for the piece of code that ruined the whole PR!

With more than a hundred git aliases I consider myself quite a git nerd, so I reached out for a tool I knew: git rebase.

My plan was:

  1. mark each commit with edit
  2. run the test suite with bin/rake at each stop
  3. identify the offending commit and fix whatever bugs I encountered
  4. amend the commit and call it a day

That didn't feel right tho, it was too clunky, I had a hunch that I could have done better than this! So, after reading once again the git rebase documentation, this little option popped out: git rebase --exec!

What --exec does to git rebase

The magic of --exec is that it will execute a command after each commit in your interactive rebase. If the command fails, it will stop the rebase, allow you to fix whatever needs to be fixed, and move along with git rebase --continue.

This means that I was able to swiftly run this command after each commit and ensure that I had a green suite at every step of the PR.

bash git rebase --interactive --exec "bin/rake" origin/master

Don't forget that this neat trick can be used for all kinds of problems, like, for example, running a linter for every commit of a PR.

Nov 4, 2013 opal · ruby · euruko · lightning · talk · 2013

Euruko 2013 Opal lightining talk

For those who missed it here's the lightning talk I gave in Athens at Euruko 2013 (at minute 17:00):

euruko-talk-poster
Downlaod it here

(beware: the slides in the video have the wrong aspect raito)

Oct 10, 2013 opal · ruby · browser · meh · tabs · spaces

Reading meh's code

jonathan-goldsmith-eyes

I don't always read meh's code
but when I do it, I convert tabs to spaces.

The bookmarklet: ↦ meh` (drag it to your bookmark bar)

UPDATE: Now works with GitHub expanding tabs to non-breaking-spaces (history here)

Aug 21, 2013 opal · ruby · browser · talk · slides · video · rails · javascript · italian

Opal Talk at RubyDay 2013 video availble!

Hey, the talk I gave at this year's (2013) RubyDay is now on youtube!
I'll update the post with the slides soon :)

(LANGUAGE: Italian).

Jul 3, 2013 ruby · rails · rails3 · railsapi · sdoc · documentation · docs · ruby2 · github · api

Past and Future of Ruby and Rails

As a sad orphan of railsapi.com I’m proud to present you valuable links to ruby and rails documentation in SDoc format:

Searchable Ruby 2.0 API documentation

http://elia.github.io/railsapi.com/public/doc/ruby-v2.0/

Searchable Rails 3.2 API documentation

http://elia.github.io/railsapi.com/public/doc/rails-v3.2/

Mar 4, 2013 git · autocomplete · shorthand · shortcuts · bash

Autocomplete "git" as "g"

For all you lazy Git bums, here’s how you can type “g” got “git” and still have autocompletion (paste into your ~/.bash_profile or .dotfiles system):

alias g='git'
complete -o bashdefault -o default -o nospace -F _git g 2>/dev/null \
    || complete -o default -o nospace -F _git g
Feb 12, 2013 pow · jruby · hack · sockets · support

Let jRuby and Pow!™ be happy together

Turns out that Pow! won’t support jRuby anytime soon but the trick described in josh/nack#32 actually works, so rollup your shirt’s sleeves!

Go open node_modules/nack/lib/nack/server.rb inside ~/Library/Application Support/Pow/Current and replace sock.close_read on line 132 with:

# WAS: sock.close_read
begin
  sock.close_read
rescue IOError
  raise unless RUBY_ENGINE == 'jruby'
end

Happy hacking!

Nov 29, 2012

rvm install opal

Sep 29, 2012 safari · backtrace · rails

Get back Rails backtrace links on Safari 6

If you’re back to Safari and want your clickable Rails backtraces here’s the solution: Download RailsnStacktracenlinks.safariextz

Thanks to http://kangoextensions.com that made supereasy transform a userscript into a Safari extension.

Links again!