Git Push Fails - remote: hooks/pre-receive: line 9: C:\Program: No such file or directory

Still need help?

The Atlassian Community is here for you.

Ask the community

Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server and Data Center platforms.

Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

Problem

Trying to push a change with SourceTree in Bitbucket Server fails with the following error:

git -c diff.mnemonicprefix=false -c core.quotepath=false -c credential.helper=manager-st push -v --tags origin develop:develop
POST git-receive-pack (526 bytes)
remote: hooks/pre-receive: line 9: C:\Program: No such file or directory 
Pushing to http://username@bitbucket.host/scm/proj/reponame.git
To http://username@bitbucket.host/scm/proj/reponame.git
 ! [remote rejected] develop -> develop (pre-receive hook declined)


error: failed to push some refs to 'http://username@bitbucket.host/scm/proj/reponame.git'

Diagnosis

Environment

  • This error is usually related to Windows platform.

Cause

The issue is caused by the presence of a space in the command path. This usually means that there is a space in $BITBUCKET_HOME.

This is also confirmed by an already existing bug report at  BSERV-7859 - Getting issue details... STATUS .

tip/resting Created with Sketch.

The bug is closed as "Won't fix" due to the fact that Atlassian does not support Bitbucket installation with spaces in the $BITBUCKET_HOME path.

Workaround

In the example the $BITBUCKET_HOME directory is located in C:\Program Files\Atlassian\ApplicationData\Bitbucket.

Locate the problematic line

Locate the line in the hook that is generating the error:

#!/usr/bin/env bash
#>*******************************************************
# THIS FILE WAS AUTO-GENERATED BY ATLASSIAN STASH.
# DO NOT MODIFY UNDER ANY CIRCUMSTANCE.
#>*******************************************************
if [[ "$OSTYPE" == "cygwin" ]]; then
    exec $(cygpath $STASH_HOOK_COORDINATOR) hooks/pre-receive.d "$@" <&0 >&1 2>&2
else
    exec $STASH_HOOK_COORDINATOR hooks/pre-receive.d "$@" <&0 >&1 2>&2
fi


In the example case the line is:

...    
exec $STASH_HOOK_COORDINATOR hooks/pre-receive.d "$@" <&0 >&1 2>&2
...


And the offending path is $STASH_HOOK_COORDINATOR that is translated into:

...    
exec C:\Program Files\Atlassian\ApplicationData\Bitbucket\bin\git-hooks\hook-coordinator.sh hooks/pre-receive.d "$@" <&0 >&1 2>&2
...


Modify the hook file

Modify the hook file to look like the following:

#!/usr/bin/env bash
#>*******************************************************
# THIS FILE WAS AUTO-GENERATED BY ATLASSIAN STASH.
# DO NOT MODIFY UNDER ANY CIRCUMSTANCE.
#>*******************************************************
if [[ "$OSTYPE" == "cygwin" ]]; then
    exec $(cygpath $STASH_HOOK_COORDINATOR) hooks/pre-receive.d "$@" <&0 >&1 2>&2
else
    exec "C:\\PROGRA~1\\\\Atlassian\\ApplicationData\\Bitbucket\\bin\\git-hooks\\hook-coordinator.sh" hooks/pre-receive.d "$@" <&0 >&1 2>&2
fi


Restart Bitbucket

In same case a Bitbucket Server restart is needed in order to have the hooks work properly.

Resolution

Change the $BITBUCKET_HOME for your Bitbucket instance to a path without spaces to solve the issue without having to manually edit the hooks.


Last modified on Jan 4, 2022

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.