# t5403.1 and adding a file that belongs to a submodule

4 messages from 2011-07-19 to 2011-07-20. Participants: Nguyen Thai Ngoc Duy, Junio C Hamano.
Thread: https://gitlist.dev/t/27853

## Nguyen Thai Ngoc Duy, 2011-07-19 13:57

Subject: t5403.1 and adding a file that belongs to a submodule
Message-ID: <CACsJy8AKMQa2u6Y5qQHGujbjqq0qnM5D1+aEvcfk7POxQBqsVg@mail.gmail.com>
URL: https://gitlist.dev/e/CACsJy8AKMQa2u6Y5qQHGujbjqq0qnM5D1%2BaEvcfk7POxQBqsVg%40mail.gmail.com

```
A part of t5403.1 is like this

touch a b; git commit -am1
git clone ./. clone2
GIT_DIR=clone2/.git git add clone2/b

The last command troubles me because clone2/.git is valid, I don't
think it should add "clone2/b" to clone2/.git/index. This is likely
due to common prefix optimization in read_directory, where it skips
checking .git at the first level (clone2). If we turn that command to
"git add a clone2/b" (common prefix would be ""), the second argument
is silently dropped (seems like a bug to me). Should t5403.1 be
rewritten to avoid that construct?
-- 
Duy

```

## Junio C Hamano, 2011-07-19 16:31

Subject: Re: t5403.1 and adding a file that belongs to a submodule
Message-ID: <7vk4be9qqm.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vk4be9qqm.fsf%40alter.siamese.dyndns.org
In-Reply-To: <CACsJy8AKMQa2u6Y5qQHGujbjqq0qnM5D1+aEvcfk7POxQBqsVg@mail.gmail.com>

```
Nguyen Thai Ngoc Duy <pclouds@gmail.com> writes:

> touch a b; git commit -am1
> git clone ./. clone2
> GIT_DIR=clone2/.git git add clone2/b

The last one has _always_ meant:

    I am telling with GIT_DIR the directory that contains the repository
    metadata, which is at clone2/.git directory.  I am not saying where
    the working tree is (i.e. no GIT_WORK_TREE and no core.worktree in
    clone2/.git/config) so take my $(pwd) as the root of the working tree,
    and add the contents of clone2/b to the index at the same path,
    i.e. "clone2/b".

It should not add contents of the said file at "b", as there is _nothing_
on the command line that tells us "clone2" is the root of the working
tree.

If the test means to do that, it should be more explicit and do something
like:

	( cd clone2 && git add b )

instead.

```

## Nguyen Thai Ngoc Duy, 2011-07-20 00:17

Subject: Re: t5403.1 and adding a file that belongs to a submodule
Message-ID: <CACsJy8AgboAj86PHi6jiSyRFsJJ7hn=mkbt+2UdBva6LmKk4ZQ@mail.gmail.com>
URL: https://gitlist.dev/e/CACsJy8AgboAj86PHi6jiSyRFsJJ7hn%3Dmkbt%2B2UdBva6LmKk4ZQ%40mail.gmail.com
In-Reply-To: <7vk4be9qqm.fsf@alter.siamese.dyndns.org>

```
On Tue, Jul 19, 2011 at 11:31 PM, Junio C Hamano <gitster@pobox.com> wrote:
> Nguyen Thai Ngoc Duy <pclouds@gmail.com> writes:
>
>> touch a b; git commit -am1
>> git clone ./. clone2
>> GIT_DIR=clone2/.git git add clone2/b
>
> The last one has _always_ meant:
>
>    I am telling with GIT_DIR the directory that contains the repository
>    metadata, which is at clone2/.git directory.  I am not saying where
>    the working tree is (i.e. no GIT_WORK_TREE and no core.worktree in
>    clone2/.git/config) so take my $(pwd) as the root of the working tree,
>    and add the contents of clone2/b to the index at the same path,
>    i.e. "clone2/b".
>
> It should not add contents of the said file at "b", as there is _nothing_
> on the command line that tells us "clone2" is the root of the working
> tree.

I see you're distracted by GIT_DIR. Let's take another example without GIT_DIR

git init
mkdir foo
(cd foo; git init; touch abc; git add abc; git ci -m1)
git add foo/abc
git ls-files --stage
# 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0       foo/abc

Because foo is a repository, should we not allow "git add foo/abc"
("git add foo" is ok)? Otherwise "abc" may be managed in two
repositories.

Note that doing "touch abc; git add abc foo/abc" instead will only add "abc".

> If the test means to do that, it should be more explicit and do something
> like:
>
>        ( cd clone2 && git add b )
>
> instead.

I suspect that's what it wants. CC the author, hopefully he still remembers.
-- 
Duy

```

## Junio C Hamano, 2011-07-20 17:50

Subject: Re: t5403.1 and adding a file that belongs to a submodule
Message-ID: <7v1uxk96z9.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7v1uxk96z9.fsf%40alter.siamese.dyndns.org
In-Reply-To: <CACsJy8AgboAj86PHi6jiSyRFsJJ7hn=mkbt+2UdBva6LmKk4ZQ@mail.gmail.com>

```
> git init
> mkdir foo
> (cd foo; git init; touch abc; git add abc; git ci -m1)
> git add foo/abc
> Note that doing "touch abc; git add abc foo/abc" instead will only add "abc".

I think you mean s/ci/commit/, but it is an (perhaps lower priority) bug
in "git add". Good that you spotted it.

```
