# [BUG?]: unpack-file behavior for blobs corresponding to symlinks

4 messages from 2008-09-19 to 2008-09-19. Participants: Elijah Newren, Mikael Magnusson, Junio C Hamano.
Thread: https://gitlist.dev/t/15595

## Elijah Newren, 2008-09-19 14:31

Subject: [BUG?]: unpack-file behavior for blobs corresponding to symlinks
Message-ID: <51419b2c0809190731j5a77b8ccmba2feecb9c44cc1c@mail.gmail.com>
URL: https://gitlist.dev/e/51419b2c0809190731j5a77b8ccmba2feecb9c44cc1c%40mail.gmail.com

```
Hi,

unpack-file doesn't create symlinks as I'd expect.  I'm not sure if
this is a bug in unpack-file, or in my expectations.

To reproduce:

$ git init
Initialized empty Git repository in /home/newren/testing/.git/
$ echo bla > bar
$ ln -s bar foo
$ git add bar foo
$ git ls-files -s foo
120000 ba0e162e1c47469e3fe4b393a8bf8c569f302116 0       foo
$ git unpack-file ba0e162e1c47469e3fe4b393a8bf8c569f302116
.merge_file_J1hTaV
$ ls -l foo .merge_file_J1hTaV
lrwxrwxrwx  1 enewren enewren 3 Sep 19 08:22 foo -> bar
-rw-------  1 enewren enewren 3 Sep 19 08:23 .merge_file_J1hTaV
$ echo $(cat .merge_file_J1hTaV)
bar

Why is .merge_file_J1hTaV a regular file instead of a symlink?  Is
there an alternative command I can use that would create a symlink to
bar given the information I have from the git ls-files command (and
which also works for creating normal files and other special file
types)?

Thanks,
Elijah

```

## Mikael Magnusson, 2008-09-19 14:51

Subject: Re: [BUG?]: unpack-file behavior for blobs corresponding to symlinks
Message-ID: <237967ef0809190751k38defaabk9efc74711f7c63c4@mail.gmail.com>
URL: https://gitlist.dev/e/237967ef0809190751k38defaabk9efc74711f7c63c4%40mail.gmail.com
In-Reply-To: <51419b2c0809190731j5a77b8ccmba2feecb9c44cc1c@mail.gmail.com>

```
2008/9/19 Elijah Newren <newren@gmail.com>:
> Hi,
>
> unpack-file doesn't create symlinks as I'd expect.  I'm not sure if
> this is a bug in unpack-file, or in my expectations.
>
> To reproduce:
>
> $ git init
> Initialized empty Git repository in /home/newren/testing/.git/
> $ echo bla > bar
> $ ln -s bar foo
> $ git add bar foo
> $ git ls-files -s foo
> 120000 ba0e162e1c47469e3fe4b393a8bf8c569f302116 0       foo
> $ git unpack-file ba0e162e1c47469e3fe4b393a8bf8c569f302116
> .merge_file_J1hTaV
> $ ls -l foo .merge_file_J1hTaV
> lrwxrwxrwx  1 enewren enewren 3 Sep 19 08:22 foo -> bar
> -rw-------  1 enewren enewren 3 Sep 19 08:23 .merge_file_J1hTaV
> $ echo $(cat .merge_file_J1hTaV)
> bar
>
> Why is .merge_file_J1hTaV a regular file instead of a symlink?  Is
> there an alternative command I can use that would create a symlink to
> bar given the information I have from the git ls-files command (and
> which also works for creating normal files and other special file
> types)?

This is not a bug. The type of a file is in the tree, not the blob, see:

% echo -n foo > file
% ln -s foo symlink
% git add file symlink
% git commit
Created initial commit 31ad9b0 on master: file and symlink
 2 files changed, 2 insertions(+), 0 deletions(-)
 create mode 100644 file
 create mode 120000 symlink
% git ls-tree HEAD
100644 blob 19102815663d23f8b75a47e7a01965dcdc96468c	file
120000 blob 19102815663d23f8b75a47e7a01965dcdc96468c	symlink


-- 
Mikael Magnusson

```

## Elijah Newren, 2008-09-19 14:55

Subject: Re: [BUG?]: unpack-file behavior for blobs corresponding to symlinks
Message-ID: <51419b2c0809190755l2aa01558l30e07c4141f8d4e0@mail.gmail.com>
URL: https://gitlist.dev/e/51419b2c0809190755l2aa01558l30e07c4141f8d4e0%40mail.gmail.com
In-Reply-To: <237967ef0809190751k38defaabk9efc74711f7c63c4@mail.gmail.com>

```
On Fri, Sep 19, 2008 at 8:51 AM, Mikael Magnusson <mikachu@gmail.com> wrote:
> This is not a bug. The type of a file is in the tree, not the blob, see:
>
> % echo -n foo > file
> % ln -s foo symlink
> % git add file symlink
> % git commit
> Created initial commit 31ad9b0 on master: file and symlink
>  2 files changed, 2 insertions(+), 0 deletions(-)
>  create mode 100644 file
>  create mode 120000 symlink
> % git ls-tree HEAD
> 100644 blob 19102815663d23f8b75a47e7a01965dcdc96468c    file
> 120000 blob 19102815663d23f8b75a47e7a01965dcdc96468c    symlink

Good to know.  Given the mode (100644 or 120000) and the sha1sum, is
there a git command that will create-my-file for me, or do I need to
just use git unpack-file and add my own extra logic on top?

Thanks,
Elijah

```

## Junio C Hamano, 2008-09-19 15:50

Subject: Re: [BUG?]: unpack-file behavior for blobs corresponding to symlinks
Message-ID: <7v4p4cuocq.fsf@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7v4p4cuocq.fsf%40gitster.siamese.dyndns.org
In-Reply-To: <51419b2c0809190755l2aa01558l30e07c4141f8d4e0@mail.gmail.com>

```
"Elijah Newren" <newren@gmail.com> writes:

> On Fri, Sep 19, 2008 at 8:51 AM, Mikael Magnusson <mikachu@gmail.com> wrote:
>> This is not a bug. The type of a file is in the tree, not the blob, see:
>>
>> % echo -n foo > file
>> % ln -s foo symlink
>> % git add file symlink
>> % git commit
>> Created initial commit 31ad9b0 on master: file and symlink
>>  2 files changed, 2 insertions(+), 0 deletions(-)
>>  create mode 100644 file
>>  create mode 120000 symlink
>> % git ls-tree HEAD
>> 100644 blob 19102815663d23f8b75a47e7a01965dcdc96468c    file
>> 120000 blob 19102815663d23f8b75a47e7a01965dcdc96468c    symlink
>
> Good to know.  Given the mode (100644 or 120000) and the sha1sum, is
> there a git command that will create-my-file for me,...

        git checkout -- that-path      ;# from the index
        git checkout commit that-path  ;# from the commit/tree

```
