All of lore.kernel.org
 help / color / mirror / Atom feed
* Gitignore file exceptions are not applied to untarcked files
@ 2016-01-29 15:25 Assen Totin
  2016-01-29 18:31 ` Junio C Hamano
  0 siblings, 1 reply; 3+ messages in thread
From: Assen Totin @ 2016-01-29 15:25 UTC (permalink / raw)
  To: git

Hi,

I'm not sure if the described issue is a bug or a feature; if it is the
latter, please, excuse the report.

I'm dealing with git 1.7.12.4. If this has been addressed in the later
issue, please, point me so.

The problem: I have a directory tree with lots of files and dirs, of which
I only track certain files in subdirs of a specific subdir. It goes like
this:

/untracted_file1
/untracked_file2
/untracked_dir1/...
/untracked_dir2/...
/tracked_dir/subdir1/config
/tracked_dir/subdir1/another_untracked_file
/tracked_dir/subdir2/config
/tracked_dir/subdir2/another_untracked_file

I'm only interested in /tracked_dir/.../config files. My .gitignore is as
follows:

# Ignore everything first
*
# Do not ignore tracked files
!/tracked_dir/*/config
# Don't ignore .gitignore
!.gitignore

This works fine until a new directory with a config file is created inside
/tracked_dir:

/tracked_dir/new_subdir/config

This config file is not seen by git at all (git status returns no changes
to add), although it matches the exclusion pattern.

While I can use various workarounds, I'm interested whether this actual
phenomenon occurs - why does the exclusion pattern not match an untracked
file in untracked directory? Is it because the exclusion pattern is never
applied to untracked files? Or is it because the directory new_subdir is
itself untracked?

WWell,

Assen Totin

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Gitignore file exceptions are not applied to untarcked files
  2016-01-29 15:25 Gitignore file exceptions are not applied to untarcked files Assen Totin
@ 2016-01-29 18:31 ` Junio C Hamano
  2016-01-29 20:54   ` Anatoly Borodin
  0 siblings, 1 reply; 3+ messages in thread
From: Junio C Hamano @ 2016-01-29 18:31 UTC (permalink / raw)
  To: Assen Totin; +Cc: git

Assen Totin <assen.totin@gmail.com> writes:

> I'm not sure if the described issue is a bug or a feature; if it is the
> latter, please, excuse the report.
>
> I'm dealing with git 1.7.12.4. If this has been addressed in the later
> issue, please, point me so.

That is a bit too ancient version, so I am not sure how it behaved
back then.

> I'm only interested in /tracked_dir/.../config files. My .gitignore is as
> follows:
>
> # Ignore everything first
> *
> # Do not ignore tracked files
> !/tracked_dir/*/config
> # Don't ignore .gitignore
> !.gitignore
>
> This works fine until a new directory with a config file is created inside
> /tracked_dir:

I am not sure if that is "working fine".  First, aren't these 'config'
files tracked?  "!/tracked_dir/*/config" or whatever you have in the
gitignore files have no effect on what is already tracked.

That is, if you replace your .gitignore with a single line,

	# ignore everything
        *

your /tracked_dir/foo/config that is already in the index (i.e. "git
ls-files tracked_dir/foo/config" would show it) would not be ignored.

> Is it because the exclusion pattern is never
> applied to untracked files? Or is it because the directory new_subdir is
> itself untracked?

So my suspicion is that (1) you do see tracked_dir/subdir1/config is
not ignored not because of any of your !tracked_dir/*/config lines
but because tracked_dir/subdir1/config is already in the index, and
(2) your tracked_dir/new_subdir/config is shown as ignored because
it is not tracked yet, and '*' tells Git that new_subdir is ignored.

By the way, this area did have a recent regression at v2.7.0, to
which a fix is percolating down to the v2.7.x maintenance track.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Gitignore file exceptions are not applied to untarcked files
  2016-01-29 18:31 ` Junio C Hamano
@ 2016-01-29 20:54   ` Anatoly Borodin
  0 siblings, 0 replies; 3+ messages in thread
From: Anatoly Borodin @ 2016-01-29 20:54 UTC (permalink / raw)
  To: git

Hi Junio,


I've tested it with many older versions of git, as well as with the recent
v2.7.0 - it seems like this feature has been never working properly.

The script https://gist.github.com/anatolyborodin/9c581b50c584534fff28

#!/bin/sh

set -e

# a
# b
# c
# D/a
# D/b
# D/c
# E/F/a
# E/F/b
# E/F/c

mkdir -p D E/F
touch a b c D/a D/b D/c E/F/a E/F/b E/F/c

echo && echo '.gitignore' && echo '----------'
echo '*\n!b\n!D/b\n!/D/b\n!/E/*/b' > .gitignore
cat .gitignore

echo && echo 'With `--ignored`' && echo '----------'
git status --ignored

echo && echo 'Without `--ignored`' && echo '----------'
git status


The output:


.gitignore
----------
*
!b
/D/b
!/D/b
!/E/*/b

With `--ignored`
----------
On branch master
Your branch is up-to-date with 'origin/master'.
Untracked files:
  (use "git add <file>..." to include in what will be committed)

        b

Ignored files:
  (use "git add -f <file>..." to include in what will be committed)

        .gitignore
        D/
        E/
        a
        c

nothing added to commit but untracked files present (use "git add" to track)

Without `--ignored`
----------
On branch master
Your branch is up-to-date with 'origin/master'.
Untracked files:
  (use "git add <file>..." to include in what will be committed)

        b

nothing added to commit but untracked files present (use "git add" to track)



All files in the subdirectories are ignored, no matter what.


-- 
Mit freundlichen Grüßen,
Anatoly Borodin

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-01-29 20:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-29 15:25 Gitignore file exceptions are not applied to untarcked files Assen Totin
2016-01-29 18:31 ` Junio C Hamano
2016-01-29 20:54   ` Anatoly Borodin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.