things i want to remember, things i want to share

Développeur Python et adepte Linux depuis 2005, Core développeur Kivy, passionné par beaucoup trop de choses.
Profil Github gpg signature bitcoin address

Entries tagged “hooks”

git, show stash list after checkout.

written by tshirtman, on 2/4/14 12:13 AM.

Sometime you start doing something in your codebase, and then you have to go do something else on another branch, so you stash them, later you come back, and you may not remember you started, them, and you forget to check your stash list.

Git has a very general solution for these kind of things: hooks

hooks are actions that you can “hook” (heh!) to events, it’s common to use the pre-commit hook to check for various errors before validating it, or to update refs after a fetch. Here, we want to display the list of stashes done on the current branch, after you checkout it.

first, we need to take the current branch.

 branch=$(git branch | grep "^\*"|sed -s s/'* '//)

then, we get the list of stash, and filter it on this branch:

 git stash list | grep "WIP on $branch"

put that in .git/hooks/post-checkout of your repository, and make it executable.

 chmod +x .git/hooks/post-checkout

But now, you have to do that in all your git repositories, but then there is this nice trick that allow you to easily use that hook in all your repositories, with just an unintrusive git init each time.

edit 2014-03-13: adding the exit 0 at the end of the script, because it prevented rebase. the code is now:

#!/usr/bin/env sh
branch=$(git branch | grep "^\*"|sed -s s/'* '//)
git stash list | grep "WIP on $branch"
exit 0


#FIXME 3G absurd ad_sense alterway aléatoire android animation anonymity atheism bach backlog bash bitcoins blog blogging boldness book books boulot bricolage bépo C canvas captcha captures carte SD censure christianity chroot CI CLI cli cloudwatt code colors comfort zone command line community company life conferences contest copwatch copwatchnord-idf core-devs cours ct705 culture deb debian debug deformation dehors dessin dev distribute distribution docker débutant déploiement développement ebooks eeepad eeepc effect ego empty en escher event firefly flappy bird flask fosdem foss fr fun game garden gdb geek culture git github goals graphics grrr gödel hack hackathon hacked hacking health hooks i3 images IMAP inspirational install isync java jenkins jeu jeu video jinja2 jni keyboard keynav kivy kv lame learning lib libre life linux lol macosx magnet mail mailing-list mails maths mbsync meetings memory leak mesh meta mint mirroir MIT module motivational mouse museomix mutt nexus7 no-mouse notmuch nottoomuch offlineimap onycroit opencourseware osc packaging paris passphrase password patch pentacatyl people perte de données ping pip planning plugin positioning pr procrastination programmation progress project projet property proudhon proxy psf publisher/consumer pull-down pygame pyjnius pypi python pythonar qtile raid rapsberry pi reading recorder references release religion responsive review reviews réseau réseaux sociaux résurection salon screenshots script self service shows shutil shyness sizing solib sortie sousous!!! spam spritz stash status systeme système templating terminal texture texture coordinates Thomas Paine thread thème tiling time time management. tip tips tools transformer tutorial tv twitter typematrix typing ubuntu ubuntu-fr ultimate-smash-friends unity update upload images useless usf utils value VDM video vie/mort vim virtualenv visite widget windows wm wmii work workflow workflow. zine études