Posts Tagged ‘git’

sd : the peer to peer bug tracking system

Tuesday, November 17th, 2009

SD is a peer to peer bug tracking system build on top of Prophet. Prophet is A grounded, semirelational, peer to peer replicated, disconnected, versioned, property database with self-healing conflict resolution. SD can be used alone, on an existing bug tracking system (like RT or redmine or github) and it plays nice with git.

Why should you use SD ? Well, at $work we are using redmine as our ticket tracker. I spend a good part of my time in a terminal, and checking the ticket system, adding a ticket, etc, using the browser, is annoying. I prefer something which I can use in my terminal and edit with my $EDITOR. So if you recognize yourself in this description, you might want to take a look at SD.

In the contrib directory of the SD distribution, you will find a SD ticket syntax file for vim.

how to do some basic stuff with sd

We will start by initializing a database. By default

sd init

will create a .sd directory in your $HOME. If you want to create in a specific path, you will need to set the SD_REPO in your env.

SD_REPO=~/code/myproject/sd sd init

The init command creates an sqlite database and a config file. The config file is in the same format as the one used by git.

Now we can create a ticket:

SD_REPO=~/code/myproject/sd ticket create

This will open your $EDITOR, the part you need to edit are specified. After editing this file, you will get something like this:

Created ticket 11 (437b823c-8f69-46ff-864f-a5f74964a73f)
Created comment 12 (f7f9ee13-76df-49fe-b8b2-9b94f8c37989)

You can view the created ticket:

SD_REPO=~/code/myproject/sd ticket show 11

and the content of your ticket will be displayed.

You can list and filter your tickets:

SD_REPO=~/code/myproject/sd ticket list
SD_REPO=~/code/myproject/sd search --regex foo

You can edit the SD configuration using the config tool or editing directly the file. SD will look for three files : /etc/sdrc, $HOME/.sdrc or the config file in your replica (in our exemple, ~/code/myproject/sd/config).

For changing my email address, I can do it this way:

SD_REPO=~/code/myproject/sd config user.email-address franck@lumberjaph.net

or directly

SD_REPO=~/code/myproject/sd config edit

and update the user section.

sd with git

SD provides a script for git: git-sd.

Let’s start by creating a git repository:

mkdir ~/code/git/myuberproject
cd ~/code/git/myuberproject
git init

SD comes with a git hook named “git-post-commit-close-ticket” (in the contrib directory). We will copy this script to .git/hooks/post-commit.

now we can initialize our sd database

git-sd init

git-sd will try to find which email you have choosen for this project using git config, and use the same address for it’s configuration.

Let’s write some code for our new project

#!/usr/bin/env perl
use strict;
use warnings;
print "hello, world\n";
git add hello.pl
git commit -m "first commit" hello.pl

now we can create a new entry

git-sd ticket create # create a ticket to replace print with say

We note the UUID for the ticket: in my exemple, the following output is produced:

Created ticket 11 (92878841-d764-4ac9-8aae-cd49e84c1ffe)
Created comment 12 (ddb1e56e-87cb-4054-a035-253be4bc5855)

so my UUID is 92878841-d764-4ac9-8aae-cd49e84c1ffe.

Now, I fix my bug

#!/usr/bin/env perl
use strict;
use 5.010;
use warnings;
say "hello, world";

and commit it

git commit -m "Closes 92878841-d764-4ac9-8aae-cd49e84c1ffe" hello.pl

If I do a

git ticket show 92878841-d764-4ac9-8aae-cd49e84c1ffe

The ticket will be marked as closed.

sd with github

Let’s say you want to track issues from a project (I will use Plack for this exemple) that is hosted on github.

git clone git://github.com/miyagawa/Plack.git
git-sd clone --from "github:http://github.com/miyagawa/Plack"
# it's the same as
git-sd clone --from "github:miyagawa/Plack"
# or if you don't want to be prompted for username and password each time
 git-sd clone --from github:http://githubusername:apitoken@github.com/miyagawa/Plack.git

It will ask for you github username and your API token, and clone the database.

Later, you can publish your sd database like this:

git-sd push --to "github:http://github.com/$user/$project"

Now you can code offline with git, and open/close tickets using SD :)

git and prove

Tuesday, April 14th, 2009

A little trick to force you to run your tests before a commit:

in a repositorie, create the following file .git/hooks/pre-commit with this content:

#!/bin/sh
if [ -d t ]; then
    res=`prove t`
    if [ $? -gt 0 ]; then
        echo "tests fails"
        exit 1
    fi
fi
if [ -d xt ]; then
    res=`prove xt`
    if [ $? -gt 0 ]; then
        echo "tests fails"
        exit 1
    fi
fi

and don’t forget to chmod with +x.

Now, when you will do your next commit, your test suit will be executed. If the tests fails, the commit will be rejected.

vim and git

Friday, December 5th, 2008

idea from http://use.perl.org/~Ovid/journal/37966 (ovid is full of really good ideas for vim):

to get a quick git diff in my vim session, put this in your .vimrc


map ,gh   :call SourceDiff() " gh for git history

function! SourceDiff()
    let filename = bufname("%")
    let command = 'git log -5 --pretty=format:"%h - (%ar) %an - %s" "'.filename.'"'
    let result   = split( system(command), "\n" )

    if empty(result)
        echomsg("No past revisions for " . filename)
        return
    endif

    " get the list of files
    let revision = PickFromList('revision', result)

    if strlen(revision)
        let items = split(revision, " ")
         execute '!git diff ' . items[0] . ' -- "' . filename .'" | less'
    endif
endfunction

the output will look like

Choose a revision:
1: ea0bb4d - (3 days ago) franck cuny - fix new_freq
2: a896ac7 - (5 weeks ago) franck cuny - fix typo
3: c9bc5fd - (5 weeks ago) franck cuny - update test
4: e9de4be - (5 weeks ago) franck cuny - change the way we rewrite and check an existing url
5: 3df1fd6 - (7 weeks ago) franck cuny - put id category

You choose the revision you want to check the diff against, and you got a (colorless) diff in your vim buffer.

Dotfiles and SCM

Friday, June 27th, 2008

All my dotfiles are stored in a SCM. Most of the time I’m on my main computer, but I can be working on a server or a different workstation. In this case, I like to have all my configurations for zsh, vim, screen, etc. 

So, instead of copying my files over different computers, I put everything in a private repostiroy, and when I’m on a new computer, I just have to checkout it. If I do a modification on a machine, I just need to commit it, and I can have the modification everywhere else.

I’ve got a $HOME/dotfiles directory, which is versionned (with git in my case). All my configurations file are stored here.

In this directory, as I’m a very lazy person, I’ve created a Makefile. Each time I create a new file, I add it to the makefile at the same time. The content of the Makefile is the following:

DOTFILES := $(shell pwd)
all: shell  code perl plagger web
shell:
ln -fs $(DOTFILES)/zshrc          ${HOME}/.zshrc
ln -fns $(DOTFILES)/zsh.d       ${HOME}/.zsh.d
ln -fs $(DOTFILES)/inputrc      ${HOME}/.inputrc
ln -fs $(DOTFILES)/screenrc     ${HOME}/.screenrc
ln -fns $(DOTFILES)/screen      ${HOME}/.screen
ln -fs $(DOTFILES)/profile      ${HOME}/.profile
ln -fs $(DOTFILES)/gnupg          ${HOME}/.gnupg
code:
ln -fs $(DOTFILES)/vimrc           ${HOME}/.vimrc
ln -fs $(DOTFILES)/gvimrc        ${HOME}/.gvimrc
ln -fns $(DOTFILES)/vim          ${HOME}/.vim
ln -fs $(DOTFILES)/ackrc           ${HOME}/.ackrc
ln -fs $(DOTFILES)/gitignore ${HOME}/.gitignore
ln -fs $(DOTFILES)/gitconfig ${HOME}/.gitconfig
ln -fs $(DOTFILES)/psqlrc        ${HOME}/.psqlrc
perl:
ln -fs $(DOTFILES)/proverc    ${HOME}/.proverc
ln -fs $(DOTFILES)/pause      ${HOME}/.pause
ln -fs $(DOTFILES)/perltidyrc ${HOME}/.perltidyrc
ln -fns $(DOTFILES)/module-starter ${HOME}/.module-starter
plagger:
ln -fns $(DOTFILES)/plagger ${HOME}/.plagger
web:
ln -fns $(DOTFILES)/irssi                 ${HOME}/.irssi
ln -fns $(DOTFILES)/vimperator  ${HOME}/.vimperator
ln -fs $(DOTFILES)/vimperatorrc ${HOME}/.vimperatorrc
ln -fs $(DOTFILES)/flickrrc       ${HOME}/.flickrrc
ln -fs $(DOTFILES)/rtorrent.rc  ${HOME}/.rtorrent.rc

So next time I want to deploy my dotfiles on a new computer, I can do

make all

or

make perl code vim

and I can start coding some perl with vim.

Git branch everywhere

Thursday, June 26th, 2008

The current trend is to have the name of the current git branch everywhere. Personnaly I display it in my vim’s status bar, and in my zsh prompt.

Here is my vimrc configuration for this (I’m not the author of this function, and can’t remember where I saw it first):

set statusline=%<[%n]%m%r%h%w%{'['.(&fenc!=''?&fenc:&enc).':'.&ff}%{g:gitCurrentBranch}%{']'}%y\ %F%=%l,%c%V%8P
autocmd BufEnter * :call CurrentGitBranch()
 
let g:gitCurrentBranch = ''
function! CurrentGitBranch()
let cwd = getcwd()
cd %:p:h
let branch = matchlist(system('/usr/local/git/bin/git  branch -a --no-color'), '\v\* (\w*)\r?\n')
execute 'cd ' . cwd
if (len(branch))
let g:gitCurrentBranch = '][git:' . branch[1] . ''
else
let g:gitCurrentBranch = ''
endif
return g:gitCurrentBranch
endfunction
vim statusbar

vim statusbar

and my zshrc:

local git_b
git_b='$(get_git_prompt_info '%b')'
PROMPT="%(?..%U%?%u:) $git_b %40<...<%/%(#.%U>%u.%B>%b) "

with the following script S55_git

zsh git

zsh git