progit / progit2

Pro Git 2nd Edition
Other
5.69k stars 1.88k forks source link

Please define some terms in Git - Git Hooks #1911

Open PostalMike opened 8 months ago

PostalMike commented 8 months ago

I'm not new to Git. I'm studying the subject deeper, in the process I've run into some terms I can't find definitions or descriptions for.

From this page "The hooks are all stored in the hooks subdirectory of the Git directory. In most projects, that’s .git/hooks. When you initialize a new repository with git init, Git populates the hooks directory with a bunch of example scripts, many of which are useful by themselves; but they also document the input values of each script. "

What is documenting what, and what input values are being referred to? What does "they" refer to in the phrase "but they also document the input values of each script"?

Further down the page: "The pre-commit hook is run first, before you even type in a commit message. It’s used to inspect the snapshot that’s about to be committed, to see if you’ve forgotten something, to make sure tests run, or to examine whatever you need to inspect in the code. Exiting non-zero from this hook aborts the commit, although you can bypass it with git commit --no-verify. "

What is "exiting non-zero"? I kind of get it -- in TSQL if one gets a message with a non-zero code it means there's a problem. "Zero" in this case would mean one wants the commit to happen, so "non-zero" means there's a problem and one doesn't want the commit to happen? This is a bit of a stretch, obviously.

This may be a silly question -- but what exactly does "hook" mean here? In marketing it's what gets a person's attention. In music, it's what gets and keeps audience members interested. "Hook" in software seems a misnomer. Really, it's a glorified API call, right? I found a good definition here "A hook in software development refers to a mechanism that allows developers to extend or modify an existing application's behavior by injecting custom code." This seems to fit the context of Git Hooks

Sorry if some of this appears nit-ish. But I'd really love to finally "get the hook" , just in a good way :).

yjhn commented 2 months ago

What is documenting what, and what input values are being referred to? What does "they" refer to in the phrase "but they also document the input values of each script"?

"They" refers to the example scripts. These scripts contain documentation of arguments (if any) that are supplied by Git when a specific script is called.

What is "exiting non-zero"?

E. g. exit 1 in a shell script. When any process exits (i. e. terminates), it returns back a single int value. Return value 0 means "everything OK", while any non-zero value (commonly 1) means something went wrong.

what exactly does "hook" mean here?

From the paragraph "Git Hooks": "a way to fire off custom scripts when certain important actions occur", which fits into the definition of "a mechanism that allows developers to extend or modify an existing application's behavior by injecting custom code."

"Hook" in software seems a misnomer. Really, it's a glorified API call, right?

It's an API call in a broad sense, but calling a script isn't commonly referred to as an "API call".