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

お困りですか?

アトラシアン コミュニティをご利用ください。

コミュニティに質問

プラットフォームについて: Server および Data Center のみ。この記事は、Server および Data Center プラットフォームのアトラシアン製品にのみ適用されます。

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.

*Fisheye および Crucible は除く

問題

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'

診断

環境

  • This error is usually related to Windows platform.

原因

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.

回避策

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.

ソリューション

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


最終更新日: 2022 年 1 月 4 日

この内容はお役に立ちましたか?

はい
いいえ
この記事についてのフィードバックを送信する
Powered by Confluence and Scroll Viewport.