Informatique

Git checkout and stash list

Monday, 21 May 2012
|
Écrit par
Grégory Soutadé

Git is great, it's true. I don't wanna enhance this scm but introduce a little tip. In git, local branches are cheap, thus a common work flow is to create branches for everything. But you cannot switch from one branch to another if there are some modifications on your code and the first thing you does when a colleague ask you to test quickly something is to stash your work and do a checkout. The problem appears when you come back to your original branch two days later (because this silly bug was hard to fix) and you've forgotten that there is something in the stash list !

The tip of the day is a post-checkout's hook script that will show stashes pending to current branch after a checkout. Here I used a hook script because stashes are implemented by a bash script, so there is no API to properly access in C language. Plus, a modification in internals git code must be maintained by hand.

The first thing is to create a template repository. As described in this question on stack overflow, we'll create a global hook directory in our home, so every git repository will have access to it :

git config --global init.templatedir '~/.git_template' mkdir -p ~/.git_template/hooks touch ~/.git_template/hooks/post-checkout chmod a+x ~/.git_template/hooks/post-checkout

Then you can edit post-checkout with :

#!/bin/sh # # Git post checkout hook # Parameters # cur_branch=`git branch | grep '\*' | awk '{print $2}'` git stash list | GREP_OPTIONS="" \grep "[oO]n $cur_branch:"

Now after each "git checkout" you'll be noticed if there are pending stashes in the current branch !

nohup

Saturday, 10 March 2012
|
Écrit par
Grégory Soutadé

Petit zoom sur une commande peu connue mais qui peut être très utile (surtout lorsqu'on administre un serveur) : nohup.

Pour la partie technique, nohup exécute un processus en ignorant au préalable le signal hup child. Signal qui est envoyé aux processus fils lorsque le processus père meurt et, comme tout le monde le sait, lorsqu'un processus reçoit un signal auquel il n'est pas préparé, il meurt (à ce niveau c'est un génocide !!). La principale utilité est donc de ne pas tuer un processus après fermeture du terminal, ce qui se révèle particulièrement utile lorsqu'on accède à une machine par SSH.

Petite subtilité : nohup redirige le flux de sortie standard dans le fichier "nohup.out", mais pas le flux d'erreur. Donc si l'on veut conserver l'affichage sur la sortie standard on lancera un autre terminal avec un "tail -f nohup.out". C'est un inconvénient, mais surtout un avantage lorsque l'on veut accéder à posteriori au log du processus (que l'on peut toujours rediriger, si on le souhaite, dans un fichier).

Script AWStats 2

Saturday, 18 February 2012
|
Écrit par
Grégory Soutadé

Il y a presque 5 mois, j'avais mis à disposition un script permettant de voir les dernières phrases clé d'Awstats en les comparant à la fois précédente, ce qui est plus pratique que de voir tout d'un bloc. Le petit problème du script était qu'on ne pouvait pas rafraîchir deux fois dans la journée sinon la différence se faisait sur des données serveur à jour.

 

Voilà donc une version légèrement améliorée qui n'écrase plus les données si elles ont été rafraîchies dans la journée.

Enlever les droits d'exécution d'un fichier PHP

Wednesday, 01 February 2012
|
Écrit par
Grégory Soutadé

Depuis quelque temps on trouve dans le fichier mods-enabled/php5.conf la mention :

<FilesMatch "\.ph(p3?|tml)$"> SetHandler application/x-httpd-php </FilesMatch>

Résultat, même un fichier n'ayant pas les droits d'exécution (mode 444) se retrouve exécuté... Pour parer à ce problème la seule solution que j'ai trouvé est de rajouter dans la configuration du répertoire cible (sites-enabled/default) :

<Directory "xxx"> <FilesMatch "\.ph(p3?|tml)$"> SetHandler application/x-httpd-php-source </FilesMatch> </Directory>