Accessing a repository is returning "A Git repository could not be found" error
プラットフォームについて: Data Center のみ - この記事は、Data Center プラットフォームのアトラシアン製品にのみ適用されます。
この KB は Data Center バージョンの製品用に作成されています。Data Center 固有ではない機能の Data Center KB は、製品のサーバー バージョンでも動作する可能性はありますが、テストは行われていません。サーバー*製品のサポートは 2024 年 2 月 15 日に終了しました。サーバー製品を利用している場合は、アトラシアンのサーバー製品のサポート終了のお知らせページにて移行オプションをご確認ください。
*Fisheye および Crucible は除く
要約
Accessing a repository page; <Base URL>/projects/<Project Key>/repos/<Repo Key>/browse
, returns an error in the UI stating A Git repository could not be found
.
環境
Bitbucket Server/DC
診断
The following error message can be found in the
atlassian-bitbucket.log
file:2021-08-15 14:50:25,188 ERROR [http-nio-7990-exec-5] admin @NF98V3x884x191x0 100fu7j 10.64.31.110,10.70.74.168 "GET /projects/TEST/repos/testrepo/browse HTTP/1.1" c.a.s.i.w.HandlerExceptionResolverImpl A Git repository could not be found. com.atlassian.bitbucket.scm.CommandFailedException: A Git repository could not be found. at com.atlassian.bitbucket.scm.git.command.GitCommandExitHandler.evaluateStdErr(GitCommandExitHandler.java:72) at com.atlassian.bitbucket.scm.git.command.GitCommandExitHandler.onError(GitCommandExitHandler.java:204) at com.atlassian.bitbucket.scm.DefaultCommandExitHandler.onExit(DefaultCommandExitHandler.java:32) at com.atlassian.bitbucket.scm.BaseCommand.callExitHandler(BaseCommand.java:214) at com.atlassian.bitbucket.scm.BaseCommand$CommandFuture.internalGet(BaseCommand.java:348) at com.atlassian.bitbucket.scm.BaseCommand$CommandFuture.get(BaseCommand.java:312) ... ... 317 frames trimmed
git fsck
returns the following:$ git fsck fatal: not a git repository (or any of the parent directories): .git
This type of error is one that git throws when it's asked to perform a git operation against a directory that is not a git repository. This likely means that one of two things is the case. Either:
- The git command is being executed against a directory that doesn't match the expected directory where the repository is located on the filesystem. Alternatively, if the Bitbucket service account has not been granted filesystem access to any of the needed git metadata files in that directory then we could see this same error.
または
- The directory is correct, but the hidden files and directories within that directory (such as the .git directory that contains the repository metadata) are not present, leading to the repository being treated as though it were not a git repository when git tries to run against it.
原因
Repository content was copied from a different file system
- Steps could involve copy via the Operating System GUI or command line (such as
cp
orscp
).
The backup of the instance was created using AWS native tools
The backup of the instance was created using AWS native tools to perform snapshots from filesystem + database backup and restore. Basically, the steps taken were:
- Stop Bitbucket.
Copied the shared folder to a new instance by using a command similar to the following:
aws commandaws s3 cp <<path-to-shared-folder>> s3://<test-atlassian-backup-bucket>/bitbucket/shared/<date>
At the same time, it was copied a snapshot of the production instance RDS DB.
Restored the DB in the test DB instance using the snapshot above.
Based on that, the scenario currently described in the Diagnosis section is dealing with the latter - as the above command will not copy an entire directory.
ソリューション
- For copying the repository content directly from the filesystem, it's recommended to use
rsync
with the--delete
flag. - When performing snapshots of AWS, it should be used the --recursive flag. You should take a new backup and use a tar command to create a single tar.gz file that contains the entire shared folder structure, empty directories, and all inside the shared directory.
We always encourage you to use the steps in the How to establish staging server environments for Bitbucket Server - Bitbucket Data Center and Server article to construct a new test environment. This is our tried and true method for successfully completing a refresh of a non-prod environment.