How to execute commandline application (bat) before mercurial commit? - mercurial-hook

I would like to execute command line application before each commit (push) to central repository. If application will execute with errors, commit should fail with some message.
I have found some examples of python hooks, but nothing about calling bats or exe.

You just put the exe/batch file as the command for the hook (you probably dont need the bat and exe extensions):
[hooks]
pre-commit.example1 = /path/to/somebatfile.bat
pre-commit.example2 = /path/to/someexefile.exe

Related

How to run a github action from command line

I need to run some Github action on my repository,
but the Web-UI gives me some trouble with branch selection.
How can i run action by command line?
The Github Command Line tool has many options for managing actions.
to run a workflow, simply run gh workflow run which will let you interactively select the workflow and fill in parameters.
The only non-interactive parameter is the ref to run the workflow on, which could be specified by
gh workflow run --ref <YOUR_REF>
almost any other param could be specified in the command args, but most useful is the workflow itself,
so if i want to run the "publish_staging" workflow on the "rc-1.3.5" branch, i can just run
gh workflow run publish_staging.yml --ref rc.1.3.5

zsh: How to always execute a command after current command's execution if it matches a pattern

After I run any hg command e.g. hg sync, hg rebase, etc., I want the command hg status to be run automatically.
I've tried looking into the zsh hooks precmd and preexec, however I wasn't able to wait for current command's execution to get finished.
I guess this can also be achieved by automatically adding "&& hg status" to the command if it matches the pattern.
To restate my requirement - for any command matching a pattern, wait for its completion and then automatically run a fixed command.
Thanks!

How can I start GitKraken from the command line with a Git repository path on Windows?

I'd like to create a bunch of shortcuts to open Git repository
GitKraken starts like this:
C:\Users\<username>\AppData\Local\gitkraken\Update.exe --processStart "gitkraken.exe"
I tried to just add the path like this, but nothing happened:
C:\Users\<username>\AppData\Local\gitkraken\Update.exe --processStart "gitkraken.exe \"C:\<path to repo with spaces>\MyRepo1\""
C:\Users\<username>\AppData\Local\gitkraken\Update.exe --processStart "gitkraken.exe \"C:\<path to repo with spaces>\MyRepo2\""
C:\Users\<username>\AppData\Local\gitkraken\Update.exe --processStart "gitkraken.exe \"C:\<path to repo with spaces>\MyRepo3\""
There could be multiple problems:
GitKraken might not support a path as parameter. Didn't find any documentation when I googled for "gitkraken from command line with repository path as parameter"
Quotes within quotes might be wrong, but I think it's correct: Command line passing quotes within quotes
The command line syntax might be different, but as mentioned above, I didn't find any documentation. I tried "-p" because I saw something similar while googling but it didn't work either C:\Users\<username>\AppData\Local\gitkraken\Update.exe --processStart "gitkraken.exe -p \"C:\<path to repo with spaces>\MyRepo1\""
GitKraken uses the Squirrel.Windows project for installation and update management for it's Windows installs. So the update.exe that is running when you click on the shortcut labeled "GitKraken" is running the Squirrel.Windows process that checks for and downloads updates and then runs the newest version of GitKraken. Once that check is complete, it launches the GitKraken.exe and starts the program.
To solve your issue you will need to pass a CLI option through the Squirrel call into the the gitkraken.exe. You are correct that gitkraken.exe accepts the -p | --path option for the repo to open at launch (e.g. gitkraken.exe -p "\path\to\repo"). If you run it from the app folder directly, you can see the options available at gitkraken.exe --help. Luckily, there are a couple of as-yet undocumented options you can pass that do the pass-through for you (referenced here) so your custom shortcut could now be:
..\Update.exe --processStart "gitkraken.exe" --process-start-args="--path \"d:\path with spaces\to\repo\""
Re: persistence through GitKraken executable updates- OP has confirmed in comments after GitKraken updated to v4.2 that the shortcuts they set up continued to work!
This is what working for me in Ubuntu Desktop
Define it
gkk() { # gkk aka gitkraken
repo_d=$1
if [ -z $repo_d ]; then repo_d=`pwd`; fi
if [ ! -d $repo_d ]; then echo "Invalid :repo_d at $repo_d"; exit 1; fi
/usr/bin/gitkraken -p $repo_d &
}
Use it
cd /path/to/your/repo
gkk
Note, calling the command again on 2nd repo will NOT work!
The workaround I can think of is to close and reopen GitKraken app

Commit hooks not printing any error message if script exists with code 0

My pre-commit is calling a perl script commit_log.pl.The script is doing so many pre-checks.Now I am trying to send out a mail after commit approval.We are not able to set up post-commit hooks due to some permission issues.So I am trying to call the send mail in the pre-commit script itself.
In my commit_log.pl if the exit code is zero ,even printf is not working.
If exit code is 1 everything is working fine
pre-commit:
log=`$SVNLOOK log -t "$TXN" "$REPOS"`
author=`$SVNLOOK author -t "$TXN" "$REPOS"`
CHANGED=`$SVNLOOK changed -t "$TXN" "$REPOS"`
/usr/bin/perl /isource/svnroot/fgw_ins/hooks/user/commit_log.pl "$log" "$author" "$CHANGED" "$0" 1>&2
if [ "$?" -eq "1" ];
then
exit 1
else
exit 0
fi
# if does not match..fail...
exit 1
---------------------------------------------------------------------------------
commit_log.pl
------------------------
}
else
{
print("Commit approved\n");#this printf itself is not working
`python $path/send_mail.py $comment $committed_filepath`;
exit 0;
}
Can't add much more to Avi's answer: STDOUT is swallowed by the hook. You will NEVER see STDOUT. STDERR is only seen by the client if the hook script returns a non-zero exitcode -- which usually means the hook failed, and in a pre-commit hook prevents the commit.
If you need to send mail out after a commit, and you can't use a post-commit hook, I suggest you use a continuous build system like Jenkins. You can have Jenkins watch your repository, and when it sees a new revision, send out email to those involved.
Jenkins is a continuous build system which can do a build after every commit, but there's no reason why you need to do a build (except it is usually a good idea anyway). Jenkins can be setup to do any action post commit, so you could have Jenkins simply email those involved.
Yes, it's a bit of an overkill having an entire system like Jenkins just to send out email. Why not simply write your own script? However, you can download, install, and configure Jenkins in an hour or two. It'll take you longer just to layout what you think needs to be done.
Besides, once you have Jenkins, you'll find plenty of other uses for it.
I'm not sure where standard output from the pre-commit hook is sent to. According to the SVN book, the standard error is sent back to the client, but only if there is an error (i.e. it exited with a non-zero exit code).
I would try writing to a specific location, rather than to standard output (e.g. /tmp/pre-commit.log for testing purposes).
Also, in general, you probably should avoid as much as possible doing work in the pre-commit script that assumes the commit was successful. The commit may still fail after the pre-commit script runs, such as during the commit itself, which is why the post-commit script exists.

TortoiseSVN from the command line and "IF ERRORLEVEL"?

I have a batch file I'm running from a Windows XP w/service pack 3 workstation which applies SQL changes to a database using sqlcmd.exe in SQL 2005.
I've got a command-line entry for TortoiseSVN to automatically update the local copy of my repository like so:
tortoiseproc /command:update /path:"C:/SVN/My Code/Dev/2009.07.23" /closeonend:3
According to the documentation, the /closeonend:3 option will leave the TortoiseSVN dialog box open if any errors, conflicts or merges occur during the update.
If such does occur, and the user closes the dialog without resolving the issues, they could potentially omit changes we want applied to a given branch's test database.
When the TortoiseSVN dialog box is closed in the case of an error, conflict, or merge following an update, will the ERRORLEVEL be set to some nonzero value, enabling me to bypass the rest of the batch file? Or will it happily return 0 to indicate it did its job successfully even if the code isn't quite right?
Old question, but I encountered the same thing today and there is a solution...
TortoiseProc returns -1 on error and 0 on success, so the following solved the problem for me:
TortoiseProc /path:"%targetdir%" /command:update /closeonend:3
IF %ERRORLEVEL% NEQ 0 goto SvnError
:SvnSuccess
echo It worked!
goto Done
:SvnError
echo It didn't work!
:Done
I ended up just manually updating my local SVN repository prior to performing the other actions in the batch file.