From 2c6282c53642574601a8689d842a55e8a9891b08 Mon Sep 17 00:00:00 2001 From: Sven Strickroth Date: Tue, 27 Dec 2011 02:08:53 +0100 Subject: [PATCH] added method to detect bare repos Signed-off-by: Sven Strickroth --- src/Git/GitAdminDir.cpp | 16 ++++++++++++++++ src/Git/GitAdminDir.h | 3 +++ 2 files changed, 19 insertions(+) diff --git a/src/Git/GitAdminDir.cpp b/src/Git/GitAdminDir.cpp index aced086eb..8d7c04aae 100644 --- a/src/Git/GitAdminDir.cpp +++ b/src/Git/GitAdminDir.cpp @@ -193,3 +193,19 @@ bool GitAdminDir::IsAdminDirPath(const CString& path) const return bIsAdminDir; } +bool GitAdminDir::IsBareRepo(const CString& path) const +{ + if (path.IsEmpty()) + return false; + + if (IsAdminDirPath(path)) + return false; + + if (!PathFileExists(path + _T("\\HEAD")) || !PathFileExists(path + _T("\\config"))) + return false; + + if (!PathFileExists(path + _T("\\objects\\")) || !PathFileExists(path + _T("\\refs\\"))) + return false; + + return true; +} diff --git a/src/Git/GitAdminDir.h b/src/Git/GitAdminDir.h index a7e3b5797..f8637b72f 100644 --- a/src/Git/GitAdminDir.h +++ b/src/Git/GitAdminDir.h @@ -43,6 +43,9 @@ public: /// Returns true if the path points to or below an admin directory bool IsAdminDirPath(const CString& path) const; + /// Returns true if the path points is a bare repository + bool IsBareRepo(const CString& path) const; + /// Returns true if the path (file or folder) has an admin directory /// associated, i.e. if the path is in a working copy. bool HasAdminDir(const CString& path) const; -- 2.11.4.GIT