philips/ghar — pull request #11 by githubaff0 (2013-03-17 15:04:58+00:00)
Title: Print message when sys.argv[0] not reporting full path to ghar

I was playing with the github Boxen project. Unfortunately, it adds a relative path for 'bin' at the start of my PATH. This exposes a problem with ghar because sys.argv[0] returns 'bin/ghar' instead of the full absolute path the code expects.

I'm unsure how to fix properly, so I just add code to detect the issue and notify the user of the problem. I also added a section to the README explaining the issue and giving a couple of workarounds.

Test cases and workaround cases below:

#
# Test case with normal PATH (no issue)
#
$ git checkout philips-ghar/master
Note: checking out 'philips-ghar/master'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

git checkout -b new_branch_name

HEAD is now at 1aea05a... Merge pull request #7 from chiphogg/directories
$ ghar list
dotfiles-git
dotfiles-hg
dotfiles-shell
$ hash
hits	command
1	/Users/aff0/ghar/bin/ghar
1	/opt/boxen/homebrew/bin/git
$ ghar list
dotfiles-git
dotfiles-hg
dotfiles-shell
$ ghar install --status
dotfiles-git
ok	/Users/aff0/.git-completion.bash
ok	/Users/aff0/.git-prompt.sh
ok	/Users/aff0/.gitconfig
ok	/Users/aff0/.gitignore_global
dotfiles-hg
ok	/Users/aff0/.hgignore_global
dotfiles-shell
ok	/Users/aff0/.bash_profile
ok	/Users/aff0/.gmpen
ok	/Users/aff0/.gw
ok	/Users/aff0/.m2/settings.gw.xml
ok	/Users/aff0/.m2/settings.reddisk.xml
ok	/Users/aff0/.mvn-completion.bash
ok	/Users/aff0/.profile
ok	/Users/aff0/.ssh/config
ok	/Users/aff0/.ssh-completion.bash
ok	/Users/aff0/.vimrc

#
# Test case with 'bin' in PATH to show issue
#
PATH=bin:$PATH
$ ghar list
No repos found in
Please read /README
$ hash
hits	command
1	bin/ghar
$ ghar list
We can't yet handle non-ghar symlinks.
We can't yet handle non-ghar symlinks.
We can't yet handle non-ghar symlinks.
We can't yet handle non-ghar symlinks.
We can't yet handle non-ghar symlinks.
We can't yet handle non-ghar symlinks.
We can't yet handle non-ghar symlinks.
We can't yet handle non-ghar symlinks.
We can't yet handle non-ghar symlinks.
We can't yet handle non-ghar symlinks.
We can't yet handle non-ghar symlinks.
We can't yet handle non-ghar symlinks.
We can't yet handle non-ghar symlinks.
We can't yet handle non-ghar symlinks.
We can't yet handle non-ghar symlinks.
dotfiles-git
dotfiles-hg
dotfiles-shell
$ ghar install --status
We can't yet handle non-ghar symlinks.
We can't yet handle non-ghar symlinks.
We can't yet handle non-ghar symlinks.
We can't yet handle non-ghar symlinks.
We can't yet handle non-ghar symlinks.
We can't yet handle non-ghar symlinks.
We can't yet handle non-ghar symlinks.
We can't yet handle non-ghar symlinks.
We can't yet handle non-ghar symlinks.
We can't yet handle non-ghar symlinks.
We can't yet handle non-ghar symlinks.
We can't yet handle non-ghar symlinks.
We can't yet handle non-ghar symlinks.
We can't yet handle non-ghar symlinks.
We can't yet handle non-ghar symlinks.
dotfiles-git: has no dotfiles
dotfiles-hg: has no dotfiles
dotfiles-shell: has no dotfiles

#
# Test case with change to print message about issue
#
$ git checkout report-relative-bin-path-issue
Previous HEAD position was 1aea05a... Merge pull request #7 from chiphogg/directories
Switched to branch 'report-relative-bin-path-issue'
$ hash
hits	command
1	/opt/boxen/homebrew/bin/git
3	bin/ghar
$ ghar list
Unable to determine full path to ghar (relative path 'bin' in your PATH?); ghar may misbehave - sorry
We can't yet handle non-ghar symlinks.
We can't yet handle non-ghar symlinks.
We can't yet handle non-ghar symlinks.
We can't yet handle non-ghar symlinks.
We can't yet handle non-ghar symlinks.
We can't yet handle non-ghar symlinks.
We can't yet handle non-ghar symlinks.
We can't yet handle non-ghar symlinks.
We can't yet handle non-ghar symlinks.
We can't yet handle non-ghar symlinks.
We can't yet handle non-ghar symlinks.
We can't yet handle non-ghar symlinks.
We can't yet handle non-ghar symlinks.
We can't yet handle non-ghar symlinks.
We can't yet handle non-ghar symlinks.
dotfiles-git
dotfiles-hg
dotfiles-shell
$ ghar install --status
Unable to determine full path to ghar (relative path 'bin' in your PATH?); ghar may misbehave - sorry
We can't yet handle non-ghar symlinks.
We can't yet handle non-ghar symlinks.
We can't yet handle non-ghar symlinks.
We can't yet handle non-ghar symlinks.
We can't yet handle non-ghar symlinks.
We can't yet handle non-ghar symlinks.
We can't yet handle non-ghar symlinks.
We can't yet handle non-ghar symlinks.
We can't yet handle non-ghar symlinks.
We can't yet handle non-ghar symlinks.
We can't yet handle non-ghar symlinks.
We can't yet handle non-ghar symlinks.
We can't yet handle non-ghar symlinks.
We can't yet handle non-ghar symlinks.
We can't yet handle non-ghar symlinks.
dotfiles-git: has no dotfiles
dotfiles-hg: has no dotfiles
dotfiles-shell: has no dotfiles

#
# Test case to show workaround
#
$ PATH=$HOME/ghar/bin:$PATH
$ ghar list
dotfiles-git
dotfiles-hg
dotfiles-shell
$ hash
hits	command
1	/Users/aff0/ghar/bin/ghar
$ ghar list
dotfiles-git
dotfiles-hg
dotfiles-shell
$ ghar install --status
dotfiles-git
ok	/Users/aff0/.gitconfig
ok	/Users/aff0/.gitignore_global
dotfiles-hg
ok	/Users/aff0/.hgignore_global
dotfiles-shell
ok	/Users/aff0/.bash_profile
ok	/Users/aff0/.vimrc