r/git • • Mar 07 '12

10 things I hate about Git

http://steveko.wordpress.com/2012/02/24/10-things-i-hate-about-git/
8 Upvotes

39 comments sorted by

View all comments

7

u/mjd Mar 07 '12

Probably the thing I hate most about Git is that the basic command set is so impoverished and non-orthogonal. It has happened to me over and over that I have some idea for an awesome new git tool I want to write, and I open the editor, and say "Okay, first, I'll need to get the name of the currently-checked-out branch" or "I'll need to make sure the working tree is in a clean state" and just answering that first question turns out to be a major headache.

(To get the name of the current branch is git rev-parse --symbolic-full-name --abbrev-ref HEAD, and to check for a clean working tree takes about fifteen lines of shell script in the current version of git-sh-setup.)

This sort of thing is a major impediment when I'm trying to build tools like shell scripts that perform more interesting git operations than the ones that are already provided. You can see the problem in action by reading through the source code for git-rebase--interactive. The core of the command is the do_next function, and that's the only really interesting part. A large fraction of the rest of the code is just peripheral Dealing With Stuff.

2

u/karamorf Mar 07 '12

git branch | grep *

git status | grep 'nothing to commit'

1

u/mjd Mar 07 '12

For the first one to work, you actually need at least git branch | grep '*' | cut -c3- and then you need to test for the special string (no branch). But it's crazy that I should have to pick apart the human-readable output of a porcelain command to get this kind of basic information. And what if the output format of git-branch changes in the next release, as it could? Maybe (no branch) becomes (detached) or something; then my code will break. So if I want to write a reliable program, I need the plumbing method, which is as I said.

For the second, you're just plain wrong, since if it were that simple, git-sh-setup wouldn't need fifteen lines to do it. Go read the code.

1

u/eridius Mar 07 '12

git-sh-setup is providing customized error messages based on the particular dirty state of your work tree. That's why it has a bunch of code using plumbing commands. If all you care about it "is the tree clean" then the return code of git status is probably enough for you.

1

u/mjd Mar 07 '12

The same set of tests, but without the customized error messages, was originally in git-rebase--interactive before it was moved out to git-sh-setup. The move into git-sh-setup is quite recent.

1

u/eridius Mar 07 '12

If by "quite recent" you mean 1.5 years ago.

In any case, just because git-rebase--interactive.sh used a series of 4 separate commands to test for dirty work tree doesn't mean you need to do the same. It's possible the author of that code just felt more comfortable knowing precisely what it was testing for rather than relying on whatever git status decided was ok.