Kategorie: Open Source

18.05.15

Git pre-push hook to check for bad log pattern

I've just written a pre-push hook for Git that will check for certain patterns in the log messages that would get pushed.

This is meant to prevent you from accidentally pushing anything that starts with "fixup!" or "stash!" to certain branches (master, etc). These log messages are meant to be used with the autostash feature, which would setup your file for `git rebase --interactive` accordingly.

The code can be found in my dotfiles: ~df/config/git/template/hooks/pre-push.

I am using this through my Git template directory, which gets used with `git init` (and `git init` in an existing repo will also install missing hooks).

Here's the current version:

Code:

#!/bin/sh
#
# Git pre-push hook to check for "fixup!" and "squash!" in commit messages,
# which are not meant to get pushed to public/non-PR branches.
#
# It will also prevent fast-forward pushes, because git-log fails for them.
#
# You can use `--no-verify` with git-push to skip this hook.
#
# Args:
# 1: name of the remote
# 2: location of the remote
# stdin: <local ref> SP <local sha1> SP <remote ref> SP <remote sha1> LF
 
remote=$1
 
# Which remote heads/branches to check?
# (a regular expression for "grep -E").
CHECK_REMOTE_HEADS='(master|develop|production|staging)'
 
# The log pattern to check.
# (a regular expression for "git grep")
BAD_LOG_PATTERN='^(fixup!|squash!)'
 
# Uncomment for debugging.
# (the ":" is there so the function can be "empty")
debug() {
  :
  # echo "debug: $@"
}
debug "$0: $1 $2 ($#)"
 
# Return status of the script.
ret=0
 
while read local_ref local_sha remote_ref remote_sha; do
  debug "Pushing: $local_ref ($local_sha) => $remote_ref ($remote_sha)"
 
  # Is this a new remote ref?
  if [ "$remote_sha" = "0000000000000000000000000000000000000000" ]; then
    log_arg="$local_sha"
  else
    log_arg="${remote_sha}..${local_sha}"
  fi
 
  # Skip certain branches, but no other refs (tags).
  remote_head=${remote_ref#refs/heads/}
  if [ "$remote_ref" != "$remote_head" ]; then
    # This is a head/branch (no tag).
 
    # Allow any non-protected branch.
    if ! echo "$remote_head" | grep -qE "$CHECK_REMOTE_HEADS"; then
      debug "Skipping remote head: $remote_ref ($remote_head)"
      continue
    fi
  fi
 
  # Check for the bad log pattern.
  log_cmd="git log --grep $BAD_LOG_PATTERN --color=always $log_arg"
  log="$($log_cmd)"
  log_ret=$?
  if [ "$log_ret" != 0 ]; then
    echo "ERROR: git-log failed (non-fast-forward / forced push?)"
    echo "  cmd: $log_cmd"
    ret=1
  fi
  if [ -n "$log" ]; then
    echo "ERROR (pre-push): there are commits with a bad pattern ($BAD_LOG_PATTERN)!"
    echo "       local_ref: $local_ref => remote_ref: $remote_ref"
    debug "git-log argument: $log_arg"
    echo "$log" | sed 's/^/  /'
    ret=1
  fi
done
 
debug "ret=$ret"
exit $ret
By Daniel in development, Open Source, Snippets05/18/15 English (US) Email
Tags: ,

11.05.10

Flattr: you pay for the web

Micro wird ja gerne mit "u" abgekürzt: möchte man nun einen kurzen Twitter-Hash für "Micropayment" erstellen, und das ganze noch in den Zusammenhang des "man bezahlt" stellen, muss "#upay" dabei herauskommen.

Und genau darum geht es:
Einfach bezahlen, und dadurch geben. Bekommen kommt dann wenn man es verdient.

Man sieht etwas, das einem gefällt und hat die Möglichkeit einfach nur "I Like" zu klicken, und dadurch Geld (ein offizielles Tauschmittel) zu transferieren, spenden und zu verteilen.

In diesem Zusammenhang: Flattr wurde als Beta freigegeben: ein Micro-Payment-Dienst, wo das monatliches Budget (z.B. 2€ oder auch 50€) auf alle Upvotes/Klicks in diesem Zeitraum (Monat) verteilt wird: mag man 4 Sachen in der Zeit gibt es für jeden 50¢ oder 12,5€, mag man 50 Sachen bekommt jeder 4¢ oder 1€).

Kleinvieh macht am meisten Mist und die Intention hierbei ist es, ein einfaches Transferieren zu ermöglichen - allerdings natürlich durch ähnlich umfassende Integration, wie es der Facebook-"I like"-Button verlangt (durch Einbinden des JavaScripts auf den Seiten).

Wer bereits einen Flattr-Zugang hat, darf dies nun gerne in meinem Blog-Sidebar ausprobieren und praktizieren, indem er meinem "Thing" (Blog) einen Teil der monatlichen Tantiemen gibt - (auch diesem Eintrag habe ich nun manuell das Widget hinzugefügt).

Ich bin auch angefangen ein umfassenderes b2evolution-Plugin zu schreiben, allerdings mal wieder sehr von Kleinigkeiten im "evocore" frustriert und abgelenkt worden.

Derzeit ist der Dienst noch nicht frei zugänging, man kann sich aber zur Beta anmelden (was ich wohl vor einigen Wochen/Monaten irgendwann getan habe).

03.02.10

Browsershots-Fabriken

Link: http://browsershots.org/

Ich hatte vor geraumer Zeit schon einmal auf BrowserShots verwiesen und bin vor kurzem wieder darauf gestoßen.

Dabei fiel mir dann auf, dass die Screenshots der Webseiten dort von Freiwilligen erstellt werden: der Hauptserver nimmt die Anfragen entgegen und verteilt sie an die einzelnen Factories/Fabriken. Auch der Code der Server und Factories scheint komplett offen zu liegen.

Also musste ich natürlich auch ein paar Fabriken auf meinem Server einrichten.

Full story »

30.09.09

POPFile

Link: http://getpopfile.org/

POPFile lets you easily handle your POP/IMAP email incoming folders and filters your mails into "buckets".

It allows more than the usual "spam" / "ham" buckets - you can use it to filter by language, too.

I have quite a special email setup, and it says currently:

Messages classified:   108,230
Classification errors: 2,948
Accuracy:              97.27% 

My buckets are: b2evo, backscatter, bugs, jedit, logspam, newsletter, personal, server, spam, traffic-watch, ubuntu, ubuntu-ack

Training messages into new buckets is as easy as moving them into another folder, when using IMAP - the POPFile process will recognize the movement and re-train this message.

If you're still using POP3, POPFile is a nice application anyway (it can be used as a proxy), but please consider switching to IMAP for your own sake.

28.04.09

OpenSource is distracting

Having the possibility to report bugs against tools and applications you are using to report bugs in other applications can lead to a whole stack of browser windows, things and stuff being open.

Especially if there are bugs in the application to report the oh-no-it's-starting-to-recurse bug report (Yes, I'm looking at you, Launchpad).

26.03.09

Vimperator

Link: http://vimperator.org/trac/wiki/Vimperator

Vimperator is a great Firefox addon, which adds Vim-Power to Firefox.

It's a Firefox plugin only, but makes it behave a lot differently - adding vim commands to it. This is not meant for the casual user, but somebody who enjoys Vim, will probably enjoy Firefox a lot more when using this plugin.

Favorite commands include ":hardcopy" for the print dialog or the navigation in general.

If you test want to test it, please start with using the 2.0 betas, which are stable already and provide a lot of improvements since 1.2 (current stable).

I've even written my own command already, which allows me to easily switch between development and live server.

After all, it's really powerful and lets you avoid using the mouse even during surfing.. ^^

The help/tutorial is always available with ":help" - and you can still use the mouse (and normal shortkeys, if you use bypass mode (Ctrl-Z / Ctrl-Y), so there's no real excuse after all.. ;)

Update: Vimperator is available in Debian/Ubuntu as "iceweasel-vimperator", although currently only as 1.2-1 - while a few days ago 2.0 has been released and provides a lot of improvements and fixes.
As great as the Debian/Ubuntu package archive is, for plugins like the ones used with Firefox, I prefer the official repositories to (automatically) get any updates.

17.01.09

ack-grep - a source-aware grep replacement (searching for content in files)

Link: http://petdance.com/ack/

ack (or ack-grep) is a nice "grep" replacement, when searching in a directory with source files.

It does not require any path to start searching and the recursive option is enabled by default. Also, it will exclude directories of version control systems (like .svn, CVS, .bzr, .git) and nicely formats hits.

E.g., "ack-grep foo" will search all (relevant) files in the current directory for "foo". And if the current directory is under source control, it will be much faster than using "grep -R foo .", since it excludes the control directories. (Ye

I haven't tinkered with its options or man page, although I'm using it since quite some time now, since the defaults are so good already and it provides a great out-of-box experience and performance boost.

The man page states when to use the "normal" grep:

WHEN TO USE GREP
ack-grep trumps grep as an everyday tool 99% of the time, but don’t throw grep away, because there are times you’ll still need it.
E.g., searching through huge files looking for regexes that can be expressed with grep syntax should be quicker with grep.

Additionally, "grep" appears to be still more useful when chaining commands, e.g. to find all references of "css" in the file list of "ack-grep" ("dpkg -L ack-grep | xargs grep css"). When using ack-grep here, it will also recursively search in all listed directories (as in "for i in $(dpkg -L ack-grep); do test -d $i && echo $i; done").

On Debian/Ubuntu, ack-grep is only a "sudo apt-get install ack-grep" away.. :)

(The ack homepage has some convincing Testimonials, too)

By Daniel in Open Source, Ubuntu, musthaves, Debian2009-01-17 English (EU) Email
Seitenleiste