Git hook output - where to see/find - windows

I'm trying to get a git commit email hook running using Git on Windows. I'm sure I've got my copy of contrib/hooks/post-receive-email (placed in the project's .git/hooks/post-commit) script messed up, or I'm missing an important node in my config, but I don't know where I would see any error messages.
Would they be echoed to stdout when I commit using a shell? Is there some flag I would need to set or pass to git commit to see them (I tried -v with no apparent effect)?
EDIT
Here are the repo-specific config vals I've added:
sendemail.smtpserver=smtp.mycompany.com
hooks.mailinglist=me#domain.com
UPDATE
The overall problem is that git's built-in mail doesn't work on windows (which makes perfect sense, of course), but at least now I know where to look for output from my hacking attempts.

Are you sure the hook is actually being executed? (Make sure it's executable!) The post-commit hook is run in the same way as git-commit, so if you commit from a shell, you should see the output of all the commit-related hooks along with the output of git-commit itself in that terminal.

Related

Write Git commit message in different editor than default

I'd like to be able to occasionally use a different editor when writing commit messages. I've found plenty of answers on how to change the default editor, but I don't want to change that - VIM is normally fine. What I'd like is some option like git commit --editor=<editor_name> where <editor_name> is the editor I want to use when writing the commit message for that commit only.
The only thing I've found that is similar to what I'd like is opening a new file with <editor_name> <newcommitfilename>, write message, save and close file, then use git commit -F <newcommitfilename>.
Is there an easier way to achieve this?
Thanks!
All Git commands use the form:
git <verb>
You may insert options before the verb, e.g.,
git -c core.pager=cat show
The -c option in particular takes a configuration item name, such as core.pager, core.editor, user.name, and so on, and a value, joined with an equals sign = like this.
Since your goal is to use a particular editor, git -c core.editor=whatever commit does the trick.
As several commenters noted, there are other ways to do this. For the editor in particular, the environment variable $GIT_EDITOR overrides core.editor, so:
GIT_EDITOR=nano git commit
runs git commit with GIT_EDTIOR set to nano for the duration of the one command (assuming POSIX-style shell).

Cygwin: Git stash -> Cannot save the current index state

I'm using cygwin under Windows to do some command line stuff. One of the commands I use sometimes is git stash. Since few weeks I always get this error when I use it: Cannot save the current index state
I also tried it in other projects, so it is no project related issue. The history is not broken or something like that. I don't use it often so I don't know when the issue started.
The error is thrown on line 110 of the git-stash file. That's why I debugged the two lines before.
$(printf 'index on %s\n' "$msg" |
git commit-tree $i_tree -p $b_commit)
When I echo the first command it outputs my last commit. This seems ok. When I output both commands piped it is empty, so maybe something is wrong with "git commit-tree $i_tree -p $b_commit". I google a long time but was not able to find a solution to this issue.
Cygwin Git version: 2.14.1
Cygwin x64 version: 2.8.2(0.313/5/3)
First, check if the issue persists with bash (the bash packaged with Git). Make sure to set your PATH in order to:
no include cygwin
include git/bin, git/usr/bin, git/mingw64/bin: see this example.
Working with a simplified path (for testing purposes) is important to make sure there is no side-effect from any other software.
Second, try and add a git status in the git stash critical lines, to see if the Git repo status reveal anything suspicious.

Git for windows paging

Whenever I execute git log command it cannot be terminated. If I do Ctrl + C it exits paging environment but if I start to type anything it starts git log command again.
as mentioned already, git log -X will limit your output to the last X commits.
Git log and other git commands invoke the less command. This is the pager. To get help with the pager, type ? or h when looking at the output. You will now see the help for the less command. Quitting less is easy, just type q.
If you don't want log to use a pager utility, you can instruct git not to use it with:
git --no-pager log
Git log has a lot of options. To get a quick overview of what has happened, I use
git log --graph --oneline --decorate --all
Decorate can be set to be enabled by default through config so you don't have to issue it.
If you think that's a lot to write on the command line, you're right! Bash has a quick remedy for that: CTRL-R. Press that and start typing 'graph'. You should get the last time that you typed that long command. This is one reason I don't bother with git aliases; it's easy to search your command history which persists from session to session.
Further, you can limit the output of git log to a particular author or particular date range, etc.
Have fun exploring and stick to the command line. It's what git was meant to be used on. You will also be introduced to a lot of excellent bash techniques that will help you a ton as you get going further with git.
You can limit the number of commits to be shown with:
git log -n 10
To limit only to the last 10 commits.
You can use also some kind of graphic interface for git, like gitk or tig or git-cola.
Check for other gui clients here.

Why does git diff on Windows warn that the "terminal is not fully functional"?

I'm using msysgit 1.7.7.1 on Windows. I get an error when using git diff. What is causing this? Is there no diff tool included in msysgit? What should I do?
WARNING: terminal is not fully functional
If you are having issues in cmd.exe, for instance, see the warning here:
Then simply set your environment variables and include TERM=msys. After that, each time you open a cmd.exe, your variable will be set correctly.
NOW YOU MUST RESTART YOUR SHELL (CMD.EXE). Just run a new one. And from there, you should have no more issues. Again:
For Git Bash, this can be fixed by adding the following line to ~/.bashrc:
export TERM=cygwin
-or-
export TERM=msys
The first seems to be the original by git for windows, the second a popular known form to "heal" as well.
The problem can be caused if some other program (like for example Strawberry Perl) sets the TERM system environment variables.
http://code.google.com/p/msysgit/issues/detail?id=184
Above answers was not fully worked for me, so I did:
Add
export TERM=msys
to "[githome]/etc/profile" at the top but it made changes only for git bash. Then I added
#set TERM=msys
to "[githome]/cmd/git.cmd" after #setlocal (I installed only git run from command line). May be this decision not truly good but it works for me and there are not any terminal warnings. (I use git version 1.7.10.msysgit.1).
The answer can be found here, in which the author of the solution claims that:
the environment variable TERM was set to dumb
that was instead of
TERM=cygwin
You can change that to
TERM=msys
to solve the problem at hand.
I work in powershell and I have the git executable directly in my path.
None of the suggested answers worked, but I found a solution that works for me.
I added a line in my powershell profile:
$env:TERM="msys"
Which fixed the problem for me.
A quick & dirty solution in my case turned out to be to use the --no-pager option.
By default, some git commands (like log) will use a pager like less if they expect the output to be long. Pagers require things like scrolling text up and down with the arrow keys, which sometimes doesn't work if the assumptions about what kind of terminal you're on are wrong (this is what the "not fully functional" means).
If you know ahead of time that your output will be short, or you just want it to dump output to the terminal and leave the scrolling up to your terminal program, you can override this and not use a pager at all, e.g.:
git --no-pager log
In case someone gets this launching bash from Git Extensions, check the setting for Path to linux tools.... Mine was set to C:\cygwin. Changing it to C:\Program Files (x86)\Git\bin\ fixed it for me. I didn't have to set the TERM variable to launch bash this way.

Git Windows Command Prompt gets stuck during Git commands with (END)

I've got Git for Windows setup (msysgit) and it was working fine for the last few days and today I've encountered an odd error.
When issuing a Git command in the Windows Command Prompt or in the Git Bash that comes bundled with msysgit, I get a strange '(END)' line appear and then I cannot issue any other comamnds.
At this point all I get are system beeps.
Any ideas?
Thanks, P.
Git want to show more than one screen of information to you, to do so it call the standard unix pager program less. Just type q to return to the prompt when you no longer want to navigate in the output.
j move one line down
k move one line up
<space> move one page down
b move one page up
h show the help
If you want to use git efficiently you should learn the basic unix tools. Even if git build and run on windows it's pretty much an alien software on the platform.
If you don't want less just replace it with another pager in the configuration. If you don't want a pager at all just use cat :
git config --global --add core.pager cat
Press q to exit the pager (which is less in git by default).
I first came across this question when I was looking for the same thing; to not have to exit out of the log command. I have since found the answer I like, so even though it is well after the original asking I will add this answer to provide an additional solution that I didn't find quickly in my own search.
Others have stated why the (END) is present -- the results are being piped thru a pager, one that can be configured for a different pager.
However, I sometimes don't want it to stop at all; because I've specified other options that do the limiting. I found that for this git has a global option --no-pager to turn off the whatever pager is defined in the config file.
This global option is on the git command itself, is available for all subcommands and is placed before the subcommand like this:
git --no-pager log
Git is using the "pager" called less, which allows you to scroll through large amount of program output easily. However, the default settings on Git for Windows seem to be to keep the pager running even when there is less than one screen of output.
Here is the default setting I had before, which would always show the (END) and wait for you to hit q before returning you to your prompt:
$ git config --get core.pager
less -+F
You can change the behavior so that less will only keep running (and take control of the keyboard) when there is more than a screenful of output by changing the option to -F instead of -+F.
Fix the pesky pager with
$ git config --global core.pager "less -F"
(The -+X option syntax for less is documented to reset the -X option to its "default", although that is not the behavior I observed with -+F since removing the option altogether was equivalent to -F, not -+F.)

Resources