0

I'm writing a hook, which is supposed to process files before they actually will be commited. So I found out that I can get list of all files have chanded recenlty like this:

def hook(ui, repo, node, **kwargs):
    changedFileList =  repo.status()[0]

So, this construction provides me with list of changed files. Now, suppose user selected just some files to be commited (via tortoise ui for example).

Roman
  • 1,396
  • 4
  • 15
  • 39

1 Answers1

1

Just use the correct hook which for your case might be the pretxncommit hook. In that hook $HG_NODE of the commit already exists, but the commit is not yet done. But using $HG_NODE explicitly you can check all properties of that commit, including files it touches, e.g. by

hg log -r$HG_NODE --template="{files}\n"

or in python code

_changedFiles = [os.path.abspath(file) for file in repo[_node].changeset()[3]]

Check hg help hgrc (search for hook therein) and hg log templates how to finetune the log output in the way you need it.

planetmaker
  • 5,884
  • 3
  • 28
  • 37
  • I actually do use pretxncommit. As I specified earlier, I'm getting list of all files that has been changed. And I'm looking for files that are explicitely selected by user (if user, for example doesnot want to commit all changed files). Thank your answer, anyway. – Roman Oct 29 '15 at 07:28
  • As explained: Analyse the $HG_NODE. IT will only contain stuff which will become part of the commit. Do NOT make use of hg commands which reference the working dir. You have to reference the revision $HG_NODE explicitly to get information about what is going to be committed. – planetmaker Oct 29 '15 at 10:11
  • Add this code to your answer, please. Is't actual python solution: _changedFiles = [os.path.abspath(file) for file in repo[_node].changeset()[3]] – Roman Nov 11 '15 at 06:20