0
votes

I tried to get the author name for the file which is being committed in SVN. I know the code should be written in pre-commit hook.

The below commands are used to get the details of committed files alone, not the file which is being committed.

  1. SVN info "Repos_Path"
  2. svnlook author "repos_path"

I can't even get the revision number for the file which is being committed. If I can get the revision number, then I can get the author name.

So, is there any possible way to get author name or revision number of the file which is being committed?

2

2 Answers

1
votes

First of all, you should read SVNBook | Implementing Repository Hooks. The section should answer all your questions. Read it carefully, please.

In the hook scripts, you should use svnlook author command. Pre-commit hook script passes the transaction ID (TXN-NAME) as the %2 parameter and repository path as %1 parameter. Therefore, in order to catch author name of the transaction about to be committed, use the command svnlook author "%1" --transaction %2.

Read SVNBook!

Edit:

You say that "It is not showing any exception and not giving any output" and this is totally expected just because the transaction is generated in the process of commit and if the commit is accepted and completes successfully, Subversion will generate new revision based on this transaction. The command sample I specified should be adjusted and used in hook script.

If you just want to test the command, use --revision instead of --transaction. For example, run the command svnlook author <REPOS-PATH> --revision REVNUM. REVNUM = any revision number in the repository at .

1
votes

Instead of writing the code in pre-commit, i have written code in start-commit hook. In which, we can get four arguments as below:

   [1] REPOS-PATH   (the path to this repository)
   [2] USER         (the authenticated user attempting to commit)
   [3] CAPABILITIES (a colon-separated list of capabilities reported
                     by the client; see note below)
   [4] TXN-NAME     (the name of the commit txn just created

Finally, i got this simplest answer.