r/badcode • • Nov 05 '19

other language I hate that this works. (git tracking)

Post image
761 Upvotes

29 comments sorted by

57

u/tcpukl Nov 05 '19

Why do you need the middle 2?

51

u/Bear_Forge Nov 05 '19 edited Nov 05 '19

The way I understand it, you used to need them because gitignore couldn't recursively make exceptions to track directories if one of their grandparent directories was ignored.

I wrote this code as a workaround following advice here: https://stackoverflow.com/questions/5533050/gitignore-exclude-folder-but-include-specific-subfolder

But this answer (https://stackoverflow.com/a/18702826) offers a way to use /**/* recursive syntax to simplify and remove the middle lines.

Edit: Nvm the recursive attempt failed. It only appeared to be working because my files were already tracked.

22

u/primitive_screwhead Nov 05 '19

Because (from the man-page), "git doesn't list excluded directories for performance reasons", so you need to un-exclude specific sub-folder matches to re-match them again (and then exclude some again if you want better performance, etc.).

It's confusing if you haven't grokked the docs, but it can cut down on a lot of unwanted stat() calls.

3

u/threeys Nov 06 '19

Why don’t you version control your static assets?

14

u/Bear_Forge Nov 06 '19

This isn't our actual gitignore. It's dumbed down just to distill the essence of the problem.

We don't version control most of our `css` folder, since we use sass. That said, we needed an exception on a few of the css subdirectories like a `css/lib` folder and a `css/globals/fonts` folder.

Rather than pull some of those grandchild folders up to the `css` root for a single-line gitignore exception, the above exception logic came into existence.

1

u/theboxislost Nov 06 '19

Meh, as long as it's documented, it's not that bad.

179

u/_PM_ME_PANGOLINS_ Nov 05 '19

git blame then punish

78

u/w3_ar3_l3g10n Nov 05 '19

git: ‘punish’ is not a git command. See ‘git —help’.

37

u/[deleted] Nov 05 '19 edited Nov 05 '19

Looks like you forgot the second dash.

git: 'punish' is not a git command. See 'git --help'.

Edit: Turns out what you used is called an "em dash".. Never heard of it.

37

u/daveysprockett Nov 05 '19

Em dash is what things like autocorrect does in word when you type -- (and is a PITA when documenting stuff or explaining in an outlook email).

It is a dash the width of a letter "m" (assuming you have a proportional font, not Courier).

5

u/PC__LOAD__LETTER Nov 06 '19 edited Nov 07 '19

Anyone know how to disable em dashes on iPhone and Mac? It’s the bane of my existence.

edit: System Preferences > Keyboard > Text > uncheck the box for “smart dashes and quotes”

13

u/sintos-compa Nov 05 '19

what is this? r/goodcode?

5

u/shuozhe Nov 05 '19

Is this a new sub or just another r/germanhumor?

2

u/w3_ar3_l3g10n Nov 05 '19

Nah. iOS automatically turns ② dashes into a wide dash. But point taken.

9

u/SirFireball Nov 06 '19

Punish: runs blame, then remotely runs :(){ :|:& };: on their computer

4

u/Gydo194 Nov 06 '19

We need that command though

2

u/jlamothe Nov 05 '19 edited Nov 05 '19

Couldn't you just use:

static
!static/css/views

?

Edit: formatting

3

u/Bear_Forge Nov 07 '19

Git won't let you except subdirectories that are more than one layer below an ignored directory. Someone above linked the man page for it.

2

u/jlamothe Nov 07 '19

TIL.

I'm still unsure as to why I would want to do this in the first place, though.

1

u/Bear_Forge Nov 07 '19

CSS is the closest I've come to needing it. I use sass and consequently don't track my CSS directory. I regularly find myself needing vendor provided CSS files, but generally those just go one layer down in a css/lib folder. I wouldn't be surprised if there was another case where I'd legitimately want exceptions for lower generation descendants.

-2

u/AutoModerator Nov 05 '19

Hello jlamothe,

It looks like this comment contains a code block delimited with triple backticks. Unfortunately reddit does not not have universal support for this syntax and your comment will render as broken gibberish on old reddit and some mobile apps.

Please edit the comment to use the more compatible four space indention format. For single lines or inline code you can use single backticks.

You can find some examples in the reddit help documentation.


I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

5

u/Plus_Cryptographer Nov 06 '19

So if those middle two lines work, does that mean that gitignore itself is cascading?

3

u/Rajarshi1993 Nov 06 '19

Some people just want to watch the world burn.

16

u/[deleted] Nov 05 '19

[removed] — view removed comment

20

u/awettree Nov 05 '19

One would typically expect a recursive action to take place so that only lines 2 & 8 are necessary.

12

u/Astrokiwi Nov 06 '19

It's about the best possible code that works. It's just that the language logic is weird enough that even the best code you can write is still kind of bad.

2

u/Tr0user_Snake Nov 05 '19

It's not bad in the same way that spaghetti code is. But it stinks. There's a real code smell about this. It suggests that the codebase is very poorly organized.

6

u/F54280 Nov 06 '19

It also suggests that this part of git is poorly designed, as OP has to rely on a completely non-obvious trick to get its directory managed.

0

u/[deleted] Nov 07 '19

[deleted]

1

u/Bear_Forge Nov 07 '19

It turns out that it wasn't an optimal directory layout, and I have already fixed it to flatten out the things that need to be excepted from git.

That said, the purpose of source control such as git is just that--source control. Where possible, it shouldn't be making demands of a development team's directory structures. It's one thing if git legitimately can't recursively except a descendant directory because of some real limitation, but it still sucks and represents an instance where the tool is demanding us to conform to it where we ideally shouldn't have to.

I still have a hard time imagining that excepting explicitly specified descendant directories is that big of a performance issue, but I'm not Linus Torvalds. I'm not nearly as smart, or as cantankerous, as him.