# Some strange behavior of git

6 messages from 2016-02-24 to 2016-02-25. Participants: Olga Pshenichnikova, Stefan Beller, Randall S. Becker, Thomas Gummerer.
Thread: https://gitlist.dev/t/41504

## Olga Pshenichnikova, 2016-02-24 22:43

Subject: Some strange behavior of git
Message-ID: <56CE31F8.7090706@ip-5.ru>
URL: https://gitlist.dev/e/56CE31F8.7090706%40ip-5.ru

```
Hello,
we use git in our project.
What can be cause for further confusing behavior?

     git@ip5server:~$ git status
     On branch master
     Untracked files:
       (use "git add <file>..." to include in what will be committed)

         app/addons/arliteks/

     nothing added to commit but untracked files present (use "git add" 
to track)
     git@ip5server:~$ git clean -dn
     Would remove app/addons/arliteks/
     Would remove design/
     Would remove js/
     Would remove var/langs/en/

Why I don't see all 4 directories in first command?

```

## Stefan Beller, 2016-02-24 22:57

Subject: Re: Some strange behavior of git
Message-ID: <CAGZ79kYGusB_hF6mgbpC3HAiWUUVOZHnEcS+hJiE1PMaehcw8A@mail.gmail.com>
URL: https://gitlist.dev/e/CAGZ79kYGusB_hF6mgbpC3HAiWUUVOZHnEcS%2BhJiE1PMaehcw8A%40mail.gmail.com
In-Reply-To: <56CE31F8.7090706@ip-5.ru>

```
On Wed, Feb 24, 2016 at 2:43 PM, Olga Pshenichnikova <olga@ip-5.ru> wrote:
> Hello,
> we use git in our project.
> What can be cause for further confusing behavior?
>
>     git@ip5server:~$ git status
>     On branch master
>     Untracked files:
>       (use "git add <file>..." to include in what will be committed)
>
>         app/addons/arliteks/
>
>     nothing added to commit but untracked files present (use "git add" to
> track)
>     git@ip5server:~$ git clean -dn
>     Would remove app/addons/arliteks/
>     Would remove design/
>     Would remove js/
>     Would remove var/langs/en/
>
> Why I don't see all 4 directories in first command?

Look at the effects of the .gitignore file

https://git-scm.com/docs/gitignore

> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

```

## Randall S. Becker, 2016-02-24 23:10

Subject: RE: Some strange behavior of git
Message-ID: <002a01d16f58$7fe9f7e0$7fbde7a0$@nexbridge.com>
URL: https://gitlist.dev/e/002a01d16f58%247fe9f7e0%247fbde7a0%24%40nexbridge.com
In-Reply-To: <56CE31F8.7090706@ip-5.ru>

```
On February 24, 2016 5:43 PM, Olga Pshenichnikova wrote
> What can be cause for further confusing behavior?
> 
>      git@ip5server:~$ git status
>      On branch master
>      Untracked files:
>        (use "git add <file>..." to include in what will be committed)
> 
>          app/addons/arliteks/
> 
>      nothing added to commit but untracked files present (use "git add"
> to track)
>      git@ip5server:~$ git clean -dn
>      Would remove app/addons/arliteks/
>      Would remove design/
>      Would remove js/
>      Would remove var/langs/en/
> 
> Why I don't see all 4 directories in first command?

What do your .gitignore files contain in this project?

Cheers,
Randall
-- Brief whoami: NonStop&UNIX developer since approximately UNIX(421664400)/NonStop(211288444200000000)
-- In my real life, I talk too much.

```

## Thomas Gummerer, 2016-02-25 09:57

Subject: Re: Some strange behavior of git
Message-ID: <20160225095755.GJ1831@hank>
URL: https://gitlist.dev/e/20160225095755.GJ1831%40hank
In-Reply-To: <56CE31F8.7090706@ip-5.ru>

```
On 02/25, Olga Pshenichnikova wrote:
> Hello,
> we use git in our project.
> What can be cause for further confusing behavior?
>
>     git@ip5server:~$ git status
>     On branch master
>     Untracked files:
>       (use "git add <file>..." to include in what will be committed)
>
>         app/addons/arliteks/
>
>     nothing added to commit but untracked files present (use "git add" to
> track)
>     git@ip5server:~$ git clean -dn
>     Would remove app/addons/arliteks/
>     Would remove design/
>     Would remove js/
>     Would remove var/langs/en/
>
> Why I don't see all 4 directories in first command?

Are the design/, js/ and var/langs/en/ directories empty?  Git doesn't
track empty directories, so they won't show up in git status, but with
git clean -d you specify that Git should also remove untracked
directories, which is why you see them here.

> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

--
Thomas

```

## Thomas Gummerer, 2016-02-25 16:14

Subject: Re: Some strange behavior of git
Message-ID: <20160225161409.GK1831@hank>
URL: https://gitlist.dev/e/20160225161409.GK1831%40hank
In-Reply-To: <56CED1F8.60601@ip-5.ru>

```
[Please keep everyone cc'd in the conversation, especially the mailing
list.  I added it back for now.
Also please don't top post on the list]

On 02/25, Olga Pshenichnikova wrote:
> No, it isn't empty, but I found the problem.
> Problem was that I handled subdirectories structure in exclude file:
>
> design/dir1
> design/dir2
>
> But
>
> design/dir3 wasn't ignored and wasn't controlled.
>
> So, my problem take place when some sub directory both isn't ignored AND
> isn't controlled even if it isn't empty.

I think that's a bug, I think this directory should only be removed if
-x is given.  I haven't come up with a patch yet, but here's a test
demonstrating the failure.

diff --git a/t/t7300-clean.sh b/t/t7300-clean.sh
index 86ceb38..0961007 100755
--- a/t/t7300-clean.sh
+++ b/t/t7300-clean.sh
@@ -653,4 +653,13 @@ test_expect_success 'git clean -d respects pathspecs (pathspec is prefix of dir)
 	test_path_is_dir foobar
 '

+test_expect_failure 'git clean -d does not clean ignored files in subdir' '
+	mkdir -p sub/dir &&
+	>sub/dir/file &&
+	test_when_finished rm .gitignore &&
+	echo sub/dir/ >.gitignore &&
+	git clean -df sub &&
+	test_path_is_file sub/dir/file
+'
+
 test_done


> Thank you for response!

```

## Olga Pshenichnikova, 2016-02-25 16:43

Subject: Re: Some strange behavior of git
Message-ID: <56CF2F1C.9070803@ip-5.ru>
URL: https://gitlist.dev/e/56CF2F1C.9070803%40ip-5.ru
In-Reply-To: <20160225161409.GK1831@hank>

```
Thanx )

On 02/25/2016 07:14 PM, Thomas Gummerer wrote:
> [Please keep everyone cc'd in the conversation, especially the mailing
> list.  I added it back for now.
> Also please don't top post on the list]
>
> On 02/25, Olga Pshenichnikova wrote:
>> No, it isn't empty, but I found the problem.
>> Problem was that I handled subdirectories structure in exclude file:
>>
>> design/dir1
>> design/dir2
>>
>> But
>>
>> design/dir3 wasn't ignored and wasn't controlled.
>>
>> So, my problem take place when some sub directory both isn't ignored AND
>> isn't controlled even if it isn't empty.
> I think that's a bug, I think this directory should only be removed if
> -x is given.  I haven't come up with a patch yet, but here's a test
> demonstrating the failure.
>
> diff --git a/t/t7300-clean.sh b/t/t7300-clean.sh
> index 86ceb38..0961007 100755
> --- a/t/t7300-clean.sh
> +++ b/t/t7300-clean.sh
> @@ -653,4 +653,13 @@ test_expect_success 'git clean -d respects pathspecs (pathspec is prefix of dir)
>   	test_path_is_dir foobar
>   '
>
> +test_expect_failure 'git clean -d does not clean ignored files in subdir' '
> +	mkdir -p sub/dir &&
> +	>sub/dir/file &&
> +	test_when_finished rm .gitignore &&
> +	echo sub/dir/ >.gitignore &&
> +	git clean -df sub &&
> +	test_path_is_file sub/dir/file
> +'
> +
>   test_done
>
>
>> Thank you for response!

```
