philips/ghar — pull request #7 by chiphogg (2012-08-01 18:16:57+00:00)
Title: Improved handling of directories

I frequently want to version *only parts* of a dotfile directory.

For example, my dotfiles repo looks something like:

```
.vimrc
.vim/filetype.vim
.vim/ftplugin/mail.vim
.vim/ftplugin/help.vim
```
etc.

Obviously the directory `~/.vim` already exists (and probably also several subdirectories). But I don't want to symlink the *whole thing*; `vundle` manages my plugins just fine. So I extended `ghar` to be able to recurse into directories.

### Old ghar behavior:

1. Check `~/.vim`; see that it already exists
2. Complain that it can't install `~/.vim`

### New ghar behavior:

1. Check `~/.vim`, see that it already exists
2. **Recurse into `~/.vim` from repo; try linking individual files**

Note that if the directory *didn't* already exist, the new `ghar` will symlink the whole directory just like before.

### Implementation approach

There are two main changes to the code.

1. I wrote a recursive function to process directories for "collection"-type
repos. It only recurses if:
- the target is a directory
- the directory already exists (and is not a non-ghar symlink)

2. The `Link` class constructor now takes an optional `base` argument. This lets us use `os.path.relname` instead of `os.path.basename`; the latter trims off the leading directories (which causes, e.g., `dotfiles/.vim/ftplugin/mail.vim` to get linked to `~/mail.vim` rather than `~/.vim/ftplugin/mail.vim`).