Use libgit2 git_reference_is_valid_name() to validate branch name
authorSup Yut Sum <ch3cooli@gmail.com>
Wed, 20 Mar 2013 14:05:31 +0000 (20 22:05 +0800)
committerSup Yut Sum <ch3cooli@gmail.com>
Sat, 23 Mar 2013 04:06:38 +0000 (23 12:06 +0800)
This covers more cases then our own checking

Signed-off-by: Sup Yut Sum <ch3cooli@gmail.com>
src/Git/Git.cpp

index fb662cb..d5996f8 100644 (file)
@@ -186,24 +186,8 @@ CGit::~CGit(void)
 \r
 bool CGit::IsBranchNameValid(CString branchname)\r
 {\r
-       if (branchname.IsEmpty())\r
-               return false;\r
-\r
-       for (int i = 0; i < branchname.GetLength(); ++i)\r
-       {\r
-               TCHAR c = branchname.GetAt(i);\r
-               if (c <= ' ' || c == '~' || c == '^' || c == ':' || c == '\\' || c == '?' || c == '[')\r
-                       return false;\r
-       }\r
-\r
-       if (branchname.Find(L".") == 0 || branchname.Find(L"/.") >= 0 || branchname.Find(L"..") >= 0 || branchname.Find(L"@{") >= 0 || branchname.ReverseFind('*') >= 0)\r
-               return false;\r
-\r
-       CString reverseBranchname = branchname.MakeReverse();\r
-       if (branchname.Find(L'.') == 0 || branchname.Find(L'/') == 0 || reverseBranchname.Find(L"kcol.") >= 0)\r
-               return false;\r
-\r
-       return true;\r
+       CStringA branchA = CUnicodeUtils::GetUTF8(_T("refs/heads/") + branchname);\r
+       return !!git_reference_is_valid_name(branchA);\r
 }\r
 \r
 static char g_Buffer[4096];\r