# Bug: git add with absolute path fails if repo root dir is a symlink

3 messages from 2010-12-27 to 2010-12-27. Participants: Alexander Gladysh, Carlo Marcelo Arenas Belon.
Thread: https://gitlist.dev/t/26141

## Alexander Gladysh, 2010-12-27 06:25

Subject: Bug: git add with absolute path fails if repo root dir is a symlink
Message-ID: <AANLkTi=Mj3AdinC87Ys35fv9DpZqefiZXhPbHMLdmyPh@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTi%3DMj3AdinC87Ys35fv9DpZqefiZXhPbHMLdmyPh%40mail.gmail.com

```
Hi, list.

Yet another issue with Git symlink handling.

I can't run git add with absolute path if the repository's root
directory is a symlink.

Please see the transcript below for details.

Alexander.

$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 10.10
Release:	10.10
Codename:	maverick

$ uname -a
Linux ubuntu 2.6.35-24-generic #42-Ubuntu SMP Thu Dec 2 01:41:57 UTC
2010 i686 GNU/Linux

$ git --version
git version 1.7.3.4

$ mkdir myrepo && cd myrepo
$ git init
$ touch alpha
$ git add alpha
$ git commit -m "initial commit"

$ cd ../
$ ln -s myrepo mysymlink
$ cd mysymlink
$ git status
$ touch beta

$ git add ~/tmp/git-test/mysymlink/beta
fatal: '/home/agladysh/tmp/git-test/mysymlink/beta' is outside repository

$ cd ../myrepo/
$ git add ~/tmp/git-test/myrepo/beta
$ git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#	new file:   beta
#

```

## Alexander Gladysh, 2010-12-27 07:23

Subject: Re: Bug: git add with absolute path fails if repo root dir is a symlink
Message-ID: <AANLkTimPxhqwMebfTw9oHucuvABmSBynpZgG1zp6uwVz@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTimPxhqwMebfTw9oHucuvABmSBynpZgG1zp6uwVz%40mail.gmail.com
In-Reply-To: <AANLkTi=Mj3AdinC87Ys35fv9DpZqefiZXhPbHMLdmyPh@mail.gmail.com>

```
On Mon, Dec 27, 2010 at 09:25, Alexander Gladysh <agladysh@gmail.com> wrote:

> I can't run git add with absolute path if the repository's root
> directory is a symlink.

Note that this issue is also triggered if *any* of the directories in
path above of my repo are symlinks.

This is a show-stopper for my current workflow.

Is there a way to quickly workaround this somehow?

Alexander.

```

## Carlo Marcelo Arenas Belon, 2010-12-27 08:13

Subject: Re: Bug: git add with absolute path fails if repo root dir is a symlink
Message-ID: <20101227081312.GA12735@sajinet.com.pe>
URL: https://gitlist.dev/e/20101227081312.GA12735%40sajinet.com.pe
In-Reply-To: <AANLkTimPxhqwMebfTw9oHucuvABmSBynpZgG1zp6uwVz@mail.gmail.com>

```
On Mon, Dec 27, 2010 at 10:23:12AM +0300, Alexander Gladysh wrote:
> 
> > I can't run git add with absolute path if the repository's root
> > directory is a symlink.
> 
> Note that this issue is also triggered if *any* of the directories in
> path above of my repo are symlinks.

When using absolute path names, git will compare the path given with the
git work tree and any name that is referred through a symlink in that
will trigger a mismatch.

> Is there a way to quickly workaround this somehow?

use relative paths (implemented below through an alias named "myadd") :

[alias]
        myadd = "!sh -c 'cd `dirname \"$1\"` && git add `basename \"$1\"`' -"

so in your workflow you would use "myadd" instead of "add" to convert your
absolute paths (with symlinks) into relative paths

Carlo

```
