Mercurial changeset hook exists with status -1 - mercurial

I am using Mercurial SCM over a LAN using a normal shared folder instead of HTTP and I'm having a problem getting the auto update hook to run.
I have entered this hook as detailed in the FAQ. This installs the hook, but when I push something to the remote repository, I get an error:
added 1 changesets with 1 changes to 1 files
running hook changegroup: hg update >&2
warning: changegroup hook exited with status -1
There is another stackoverflow question similar to this, but it offers no solutions other than it may be a permissions error somewhere.
Has anyone else had this problem and can anyone else shed any more light on this or give me a heads up on where to start fixing this? Thanks.

Is hg in your standard search PATH ?
Replace your .hgrc configuration with a custom script, e.g.
[hooks]
changegroup = /var/tmp/myscript.sh
[ui]
debug = true
(unix) In the /var/tmp/myscript.sh write something like this:
#!/bin/sh
set -e
echo ---------- >>/tmp/myscript.log
set >>/tmp/myscript.log
echo --- >>/tmp/myscript.log
pwd >>/tmp/myscript.log
hg update >>/tmp/myscript.log 2>&1
(unix) Do not forget to mark as executable: chmod a+x /var/tmp/myscript.sh
(windows) The corresponding batch file myscript.bat is:
#echo off
echo ------ >>%TEMP%\myscript.log
set >>%TEMP%\myscript.log
echo --- >>%TEMP%\myscript.log
cd >>%TEMP%\myscript.log
hg update >>%TEMP%\myscript.log 2>&1
(windows) Of course, the line in .hgrc is changegroup = \your\directory\myscript.bat.
Run your hg push command to reproduce the problem.
Check the content of the /tmp/myscript.log file.

Related

hg incoming display the repository root path

Executing the Mercurial command:
hg in -q
produces a list like below.
123:b64543
124:ef312a
This command will be execute on multiple repo's. How can we append the repository path to the above output to identify the repo? Executing command 'hg root' gives us that information but we only want to know about the path if the repo has new changeset. We looked at template but could not find a variable that gave us the right information.
Apppreciate any help.
The easiest solution for appending the root path to hg incoming is to concatenate the two commands with && (assuming you're using Unix):
hg in -q && hg root
This works because hg incoming will return 0 if there are incoming changes, 1 otherwise (or a non-zero value if there was an error).
For more sophisticated manipulation of the output, sed can usually do it. For example, the following command prepends the root to the output:
hg in -q | sed -e "1i$(hg root)"
I'd resort to a bit bash and call hg root within the template. Assuming all directories are sub-directories of the current one (otherwise give the list of dirs differently):
for i in *; do [ -d $i/.hg ] && hg incoming -R$i --template "$(hg root -R$i) {rev}:{node|short}\n"; done

Can I disable the default behaviour `hg add` with no arguments?

When I run hg add with no arguments, it is always by mistake, and the result, adding all of the files and directories recursively, is horribly annoying and difficult to undo, especially when other files have been (correctly) added since the last commit. Is there any way to make a plain hg add just print an error message?
Try putting this in your ~/.hgrc:
[defaults]
add = -X .
That tells hg add that unless specifically named it should ignore all files (got matches all). Here's an example:
(df)Ry4ans-MacBook-Air:~ ry4an$ hg init test
(df)Ry4ans-MacBook-Air:~ ry4an$ cd test/
(df)Ry4ans-MacBook-Air:test ry4an$ vi ~/.hgrc # added the section above
(df)Ry4ans-MacBook-Air:test ry4an$ hg status
(df)Ry4ans-MacBook-Air:test ry4an$ echo this > that
(df)Ry4ans-MacBook-Air:test ry4an$ hg add # nothing added
(df)Ry4ans-MacBook-Air:test ry4an$ hg status
? that
(df)Ry4ans-MacBook-Air:test ry4an$ hg add that
(df)Ry4ans-MacBook-Air:test ry4an$ hg status
A that
In general though, you should just make your .hgignore robust enough to ignore all the files you don't want added
In your user config file (~/.hgrc), add the following to your [alias] section:
[alias]
realadd = add
add = add --dry-run
Now, just hg add will always do a dry-run. To actually add, you have to use hg realadd. Note that you could redefine the add alias to do anything, it doesn't have to be add --dry-run.
I don't know a way to do this purely with Mercurial configuration, but if you're willing to tune your bash profile, then you can redefine the hg command as a function. The function would either detect hg add and fail or otherwise do a passthrough to the real hg command.
function hg() {
if [ "$#" -eq 1 ] && [ "$1" = "add" ]; then
echo "hg add with no arguments denied" 1>&2
false # sets exit code to 1, but doesn't close process like exit would
else
command hg $#
fi
}
Here is what it looks like in action after I source in the new function from my profile:
hg > /dev/null; echo $?
0
hg add > /dev/null; echo $?
hg add with no arguments denied
1
hg add . > /dev/null; echo $?
0
hg status
touch afile
hg add afile
hg status
A afile
You can undo a global add using the following command:
hg forget $(hg status -an)
Here, hg status -an will list all added files. hg forget will then remove those files from the list of added files.
You can also create an alias for this in your .hgrc, e.g.:
[alias]
unadd = !$HG forget $($HG status -an)
Note that this will also delist all previously added files that you did mean to add, so you may have to redo that.
Also, operating systems and shells have limits for how many arguments can be passed to a command. If you run into this limit because you accidentally added more than a few thousand files, you can use xargs instead:
hg status -an | xargs hg forget
Or, as an alias:
[alias]
unadd = !$HG status -an | xargs $HG forget

Checking the history of a file

I'm trying to setup a shortcut, a command which will let me check the history of one file.
I'm interested in when the file was originally commited, in what changesets it was changed and whether the current version in the working directory differs from the "last commited one".
So, in general
hg log --verbose filename.txt
hg status filename.txt
Is there a way to make this into a sort of a shortcut, so I can just type for example
hg file filename.txt
and get the "history" of the file?
Yes, you can add a shell alias:
[alias]
file = !$HG log --verbose "$1" && $HG status "$1"
The $HG environment variable refers to the path of the hg script used to invoke the shell alias, just in case hg is not in your path. The $1 refers to the first command line argument, the file name in your case.

I am failing to commit to mercurial repo

I tried committing to a local hg repo and it refuses:
trouble committing plot.py!
note: commit message saved in .hg/last-message.txt
abort: Permission denied: /home/md/md_perf/.hg/store/data/plot.py.i
Your file permissions are messed up inside the local repository -- probably someone else pushed or committed to that repository without making sure they were leaving the permissions in a state usable by your whole group. Try these, with the appropriate substitutions, and sudo if necessary:
chgrp -R yourgroup /home/md/md_perf
chmod -R g+rwX /home/md/md_perf
find /home/md/md_perf -type d -print0 | xargs -0 chmod g+s

Any Mercurial extension to grep for newly checked in code (not having "console.log")?

Is there any Mercurial extension that can grep for "console.log" that might have been accidentally left over as debugging code?
Right now this is what I am doing:
1) hg out ssh://....
the above is to see what is the first committed revision in my local repo, say, the smallest revision is 3456
2) hg diff -r 3455 | grep "^+" | grep "console\.log"
The number 3455 is 3456 - 1. the first grep is to see newly added code. the second one is for console.log
This method can tell that I have "console.log" in the new code, but won't say what file it is in.
It sounds like you're in need of a commit hook. Try putting something like this into your .hg/hgrc (or ~/.hgrc if you want it global):
[hooks]
pretxncommit = sh -c 'if hg log -p -r $HG_NODE | grep -q '^\+.*console\.log' ; then exit 1; else exit 0; fi'
That will abort your commits if they would be adding a line that contains console.log. Your commit message will be saved in .hg/last-message.txt.
See http://hgbook.red-bean.com/read/handling-repository-events-with-hooks.html for more details.