2

How can I, on a Mercurial repository server, figure out the current repository URL or at least name (subpath) in a changegroup — or somewhat equivalent — hook? I'm running HgWeb on IIS.

$HG_URL returns the pushers URL, not the receiving repository's. $HG_SOURCE only returns serve.

Context: I'm trying to write a changegroup hook for Jenkins using /mercurial/notifyCommit?url=<url> that tells Jenkins to perform an SCM poll, and if I can't get this to work, I have to do about 50 cURL calls (once for every repository on the server) on every changegroup trigger, and then remember to maintain this list in hgweb.config for all eternity.

J F
  • 631
  • 7
  • 15

2 Answers2

2

Your hook will be executed inside the root folder of that specific repository, you can use the following command in bash to get the current folder name:

${PWD##*/}
Ton Plomp
  • 3,020
  • 1
  • 18
  • 35
1

As per Ton's answer, this is what I ended up doing since I'm on Windows:

changegroup.jenkins.cmd:

@for /f "delims=\" %%a in ("%CD%") do @set TOPMOST=%%~nxa
@curl.exe "http://jenkins/mercurial/notifyCommit?url=http://hgweb/%TOPMOST%" -s -S
J F
  • 631
  • 7
  • 15