Pre commit hook condition not throwing error

51 views
Skip to first unread message

Void

unread,
Dec 7, 2017, 3:07:44 PM12/7/17
to TortoiseSVN
I'm looking for a way to cancel a pre commit hook on a error. I only want the user to enter a number between 1 and 2 and if it's not I need to cancel the commit, how can I do this?

     int val;
      if (!int.TryParse(Console.ReadLine(), out val))
      {
        Console.Error.WriteLine("Please enter a number");
        return;
      }


Stefan

unread,
Dec 9, 2017, 2:39:36 AM12/9/17
to TortoiseSVN
If there's something written to the console error, the script will read that and show it to the user. But only if the hook script is configured with "wait for the script to finish".
 

Void

unread,
Dec 11, 2017, 1:02:35 PM12/11/17
to TortoiseSVN
Unfortunately this is still prompting the user with a window to commit when I try this and does not log an error.

Stefan

unread,
Dec 11, 2017, 3:03:52 PM12/11/17
to TortoiseSVN


On Monday, December 11, 2017 at 7:02:35 PM UTC+1, Void wrote:
Unfortunately this is still prompting the user with a window to commit when I try this and does not log an error.

      int val;
      if (!int.TryParse(Console.ReadLine(), out val))
      {
        Console.Error.WriteLine("Please enter a number");
        return;
      }




Did you compile your script as a console program?
If not, the Console.Error.WriteLine has nowhere to write to.

Void

unread,
Dec 11, 2017, 6:13:46 PM12/11/17
to torto...@googlegroups.com
Yes it's compiled as a console app since I'm getting my read line. This is also not canceling the commit either, :) 

Stefan

unread,
Dec 12, 2017, 3:33:49 PM12/12/17
to TortoiseSVN


On Tuesday, December 12, 2017 at 12:13:46 AM UTC+1, Void wrote:
Yes it's compiled as a console app since I'm getting my read line. This is also not canceling the commit either, :) 

How exactly did you set up your hook script? Is it even called? When is it called?


Void

unread,
Dec 12, 2017, 4:19:46 PM12/12/17
to TortoiseSVN
I added it as as a hook script in the Hook Scripts settings. It's a start_commit_hook, and yes it's called as I get console window to enter to the console. 
When I enter a letter and read it with Console.ReadLine() the function should exit out and popup a error message, but it's not showing the error and it continues with the commit. 

Stefan

unread,
Dec 13, 2017, 1:51:37 PM12/13/17
to TortoiseSVN


On Tuesday, December 12, 2017 at 10:19:46 PM UTC+1, Void wrote:
I added it as as a hook script in the Hook Scripts settings. It's a start_commit_hook, and yes it's called as I get console window to enter to the console. 
When I enter a letter and read it with Console.ReadLine() the function should exit out and popup a error message, but it's not showing the error and it continues with the commit. 

first: maybe you may want a check-commit hook instead start-commit hook. But that's just my guess.
second: you also have to return from your script with a non-null exit code to indicate an error. If your script returns with zero, then that means no error.

Stefan

Void

unread,
Dec 13, 2017, 1:57:20 PM12/13/17
to TortoiseSVN
No, I need to commit a file that the hook updates. So start-commit hook is what I need. 
You are correct about the return, I was using a void. Thank you so much this really helped! 
Reply all
Reply to author
Forward
0 new messages