Uma Lição de VIM #15.3: Plugins – Fugitive

(Essa é a parte que só faz sentido se você usa Git.)

O terceiro plugin que eu vou comentar é Fugitive, que adiciona comandos para gerenciar seu repositório Git dentro do VIM.

Para instalar, ou você baixa a versão do Github (no link acima) ou usa o Vundle:

Bundle ‘tpope/vim-fugitive’

(E, de novo: depois de adicionar essa linha no seu vimrc, você deve sair do VIM — ou, se não quiser fazer tudo isso, basta usar o comando acima em modo de comando — e usar :BundleInstall para instalar o plugin.)

A princípio, nada de diferente deve aparecer. Mas você agora pode usar qualquer comando do Git com :Git {comando}, como faria no shell.

Mas só adicionar um comando não é o que o Fugitive faz. Ele também adiciona outros comandos:

  • :Gwrite (ou :Gw): salva o arquivo atual e já adiciona no index para o próximo commit.
  • :Gblame: Faz um split da tela, mostrando do lado direito o fonte que já estava aberto e do lado esquerdo, o último commit (SHA1) e o autor do commit.
  • :Gread: Descarta as alterações locais e recupera o arquivo atual na sua última revisão dentro do repositório do Git (ou seja, revert).
  • :Gdiff: Mostra um diff da versão atual com a versão no repositório, com splits.
  • :Gcommit: Faz o commit dos arquivos que estão no index.
  • :Gstatus: Faz um “git status”, mas deixa que você altere os arquivos no index (usando “-” para adicionar ou remover o arquivo — leia o texto com atenção) e faça commit dos selecionados (usando “cc“) [Note que ambos os comandos devem ser usados em modo normal dentro do split aberto por :Gstatus.]

Existem outros, mas você vai usar principalmente estes. E cuide para que você esteja dentro de um repositório Git antes de tentar usar os comandos; se o VIM não estiver num diretório com um repositório válido, nenhum dos comandos do Fugitive ficarão disponíveis[1].

E, como última dica: Se você estiver usando o Airline (comentado no capítulo anterior), adicione

let g:airline_enable_branch = 1

… no seu vimrc e o branch atual será apresentando dentro do status do Airline, logo após o indicador de modo.

[1] Eu só preciso adimitir que não testei para ver o que acontece se você abrir o VIM fora de um repositório e depois usar :cd para mudar para um diretório que tem um repositório ou tentar abrir um arquivo que está dentro de um repositório para verificar se os comandos se tornam disponíveis.

Mitter public annoucement: Mitter is going git

Just to let everybody know: Mitter will not use Google Code SVN repositories anymore. The source is still available for those that know the URLs but the information is not available to the public anymore. Other things like Wiki, issues and downloads will still be available in the Google Code space.

Mitter source code is not being hosted with Gitorious and it’s available for everyone to clone it. Also, Gitorious offers options for automatic cloning so all you need is a Gitorius account.

Small PQA (Possibile Questions and Answers):

  • Why Git?
    For one thing, I’m feeling comfortable with Git workflow and tools. Second, I prefer the way Git does “in-place” branching, so you don’t have a lot of directories laying around your disk.
  • Why Gitorius and not GitHub?
    I know how GitHub is everybody and their mum’s favourite git repository and interface. But, as an open source supporter, I chose Gitorious exactly ’cause they provide the source code of their project for everyone. I’m not saying that GitHub is wrong charging people for their project, it’s just that I prefer to support open source.
  • What about the other branches that were laying around in the SVN repository?
    They are still there, but I didn’t import them into Gitorious. Most of them were not being used anymore but, if something is needed, the source is still there.

If you have any other questions, feel free to ask.

More fights with Gitweb and Dreamhost

Time to setup gitweb on a Dreamhost hosted domain. Incredible number of headaches:

First, I didn’t had a copy of gitweb on my $HOME there, so I decided to download the latest version and install it, following most of my previous install.

Git worked fine on Dreamhost, so I created the repository directory, initialized the git repo there and tried to push from my local repo to the server repo. That’s when I got my first “couldn’t find libcurl.so.4”. At first, I thought the problem was happening ’cause I was running Git 1.5 on my laptop and 1.6 on Dreamhost, but upgrading my local install didn’t solve the problem. Even, I have “libcurl.so.4” on my local files directory there. That’s when I found out that .bash_profile is not sourced when using SSH. Copying the contents of .bash_profile to .bashrc made git push happy again.

Just dropping gitweb.cgi on the domain directory didn’t work: I got a “404 – No projects found”. Hunting in the web I found that you need to add a gitweb-config.pl with the gitweb.cgi. The contents should look something like this:
# where's the git binary?
$GIT = "/home/slowsloth/packages/bin/git";
# where's our projects?
$projectroot = "/home/slowsloth/git.deadbraincells.org/";
# what do we call our projects in the ui?
$home_link_str = "home";
# where are the files we need for web display?
@stylesheets = ("/gitweb.css");
$logo = "/git-logo.png";
$favicon = "/favicon.png";
# what do we call this site
$site_name = "DeadBrainCells' Git Repository";
# these variables should be empty
$site_header = "";
$home_text = "";
$site_footer = "";
$projects_list = "";
$export_ok = "";
$strict_export = "";

# some other config variables I found around
$projects_list_description_width = 50;
$project_maxdepth = 10;

Well, thing is, it didn’t work (and I still got “404 – No projects found”. Then I decided to read the gitweb.cgi source and found that the name for the config file is, actually, gitweb_config.perl. Renaming it removed the “404”s, but it won’t display any projects.

After changing a few values with no result, I decided to check the apache error logs to see if there was something there. And there was. Again, the message about not finding the “libcurl.so.4”. I tried to add an .htaccess with SetEnv LD_LIBRARY_PATH "/home/slowsloth/packages/lib", which didn’t work. Then, change the $GIT on the config file to $GIT = "LD_LIBRARY_PATH=/home/slowsloth/packages/lib /home/slowsloth/packages/bin/git", but it also didn’t work (now complaining about not finding the command.) The last resort was create a small wrapper around git, which I called gitwrap.sh:
#!/bin/sh
export LD_LIBRARY_PATH=/home/slowsloth/packages/lib
/home/slowsloth/packages/bin/git $*

The final step was replace the $GIT to call gitwrap.sh instead of git and voilà, gitweb running.

Mitter and Git

For a while, I tried to keep a Git repository of Mitter. It looked all nice and dandy, but it was a pain to keep it up-to-date with everything, not to mention that Git-Svn apparently doesn’t convert SubVersion branches to Git branches (or GoogleCode is broken — anyway, branches doesn’t work for Mitter.)

But, for those who still want to play with Mitter code using Git, there is one solution: I set up a git repository to myself, following just the trunk, which is updated hourly (fetches the trunk from GoogleCode and updates the Git repositories.) The project can be seen here: http://git.juliobiason.net/?p=mitter. Just note that I’m not keeping this as the main repository, just a nice thing for people who want to play with Mitter (or Git.)

Useful Git config

Here are some useful configuration option for Git (thanks to Nathan and Simon for the tips.):

git config --global color.ui true  # Colours for git status and git diff
git config --global alias.st "status"   # Make git st work as git status
git config --global color.diff auto   # Try to use colours on git diff
git config --global color.status auto   # Try to use colours on git status
git config --global color.branch auto  # Try to use colours on git branch

Also, using git config --global core.excludesfile ~/.gitignore and then editing a ~/.gitignore with the files that should be ignored will make all files ignore those files (easily to ignore *.pyc and *.sw?)

Git repositories on Dreamhost via SSH

After some mucking around, I managed to create a remote repository for Git projects on my Dreamhost account, without the need of WebDav. Here are the steps:

  1. First, you’ll need to install Git on the server side. But git also requires Curl, so the first step is compiling Curl.
    Get curl here and Git here.

  2. Install Curl using the default process of ./configure && make && make install. Just remember that you are working on your own home directory, so you’ll need to run ./configure with a --prefix like $HOME/software or something (just a suggestion, thought. But the prefix must be somewhere in your home directory.
  3. Now, to install Git, you need to configure it with ./configure --with-curl --includedir=$HOME/software/include/. Why? Because your curl headers are in $HOME/software and, without that, Git won’t compile with Curl and SSL (required for SSH). After the configure, you need to run make NO_MMAP=1 (as pointed by the Dreamhost Wiki, I haven’t tried without it but there they say it makes bad things like rape small children or kill Git processes or something.). Once it finishes compiling, install it with make NO_MMPAP=1 install (again, I’m not sure if the NO_MMAP=1 flag is required here, but I used it just to be sure.)
  4. Next step is to make Git accessible. Edit your .bash_profile and add $HOME/software/bin to your PATH. Note that changing it on your .bashrc doesn’t work — You have to add it on your .bash_profile. You’ll probably want to disconnect and connect again just to be sure that it will work (call git after logging again; if it complains about unknown command, your PATH is not right.)
  5. Almost done with the server side. Now you need to create the repository for your projects. Putting it into your “host directory” (the directory with your webpage) will make it easier to someone clone it. So go there and mkdir project && cd project && git --bare init-db. That will create a bunch of directories needed by Git.

Now you’re done with the server side. This step assumes that you already have a local Git repository (e.g., you did a git init and committed at least one revision on it.) On your computer you’ll need to change your Git config inside your project to have the following:

[remote "hostname"]
    url = ssh://username@server.dreamhost.com/~username/hostname/project
	fetch = +refs/heads/*:refs/remotes/dreamhost/*
	push = refs/heads/*

Just be sure to change username to your Dreamhost username (twice in that row), server to the Dreamhost server you are allocated (or you can replace the whole thing with your own hostname, but you’ll still need to put it on the path), hostname is your hostname directory and project is the name of the project you created in the server. Once you updated your config, do:

  • git-update-server-info
  • git push hostname master

It should work at this point. Note that I have changed my SSH to be passwordless, so you may find an issue if you don’t.