Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7516255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:04:21+00:00 2026-05-30T01:04:21+00:00

I have the following in my .git/hooks/pre-commit file #!/bin/sh exec c:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -ExecutionPolicy RemoteSigned -Command

  • 0

I have the following in my .git/hooks/pre-commit file

#!/bin/sh
exec c:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -ExecutionPolicy RemoteSigned -Command " Get-Location | % { '$_\pre-commit-hook.ps1'} | % { & $_ }"
exit

This successfully executes the code in the pre-commit-hook.ps1 file in the same directory, but does not capture the exit code. According to tldp.org the last exit code will be returned if only exit is specified. Git hooks will fail if the exit code is non-zero, but even though my powershell script returns a status code of 1, it always succeeds. What can I do to capture the exit code from the powershell script so the hook will function correctly?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T01:04:23+00:00Added an answer on May 30, 2026 at 1:04 am

    Keep the invocation of the ps1 script simple and you should have it working. The following works for me:

    #!/bin/sh
    echo 
    exec powershell.exe -ExecutionPolicy RemoteSigned -File '.\.git\hooks\pre-commit-hook.ps1'
    exit
    

    The ps1 script just had an exit 1 and the commit did not happen.

    When you are doing stuff like -command, Powershell is not known to work properly and you might have to do something like -command {& .\test.ps1; exit $lastexitcode}

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have executed the following command git add <foo.java> git commit -m add the
I have the following in my .bashrc file: # Git Bash Completion source $HOME/.git_completion
Hello I have the following error by git-fsck, which cannot be cleaned by git-gc
In my current repo I have the following output: $ git branch -a *
I have followed the following instructions in setting a git repository locally in one
In my repository, I have created tags using the following commands. git tag v1.0.0
I have recently been writing git hooks for my project team. I would like
Backround: Suppose I have the following Git URLs (hosted on github) http://github.com/mikl/drupal.git git://github.com/mikl/drupal.git (Git
I have the following directories structure: g1/ .git a b c/ .git d e
I have following working tree state $ git status foo/bar.txt # On branch master

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.