| 503 | } |
| 504 | |
| 505 | void CShellExt::InsertGitMenu(BOOL istop, HMENU menu, UINT pos, UINT_PTR id, UINT stringid, UINT icon, UINT idCmdFirst, TGitShellCommand com, UINT /*uFlags*/) |
| 506 | { |
| 507 | wchar_t menutextbuffer[512] = { 0 }; |
| 508 | wchar_t verbsbuffer[255] = { 0 }; |
| 509 | MAKESTRING(stringid); |
| 510 | |
| 511 | if (istop && menu) |
| 512 | { |
| 513 | //menu entry for the top context menu, so append an "Git " before |
| 514 | //the menu text to indicate where the entry comes from |
| 515 | wcscpy_s(menutextbuffer, L"Git "); |
| 516 | if (!g_ShellCache.HasShellMenuAccelerators()) |
| 517 | { |
| 518 | // remove the accelerators |
| 519 | std::wstring temp = stringtablebuffer; |
| 520 | temp.erase(std::remove(temp.begin(), temp.end(), '&'), temp.end()); |
| 521 | wcscpy_s(stringtablebuffer, temp.c_str()); |
| 522 | } |
| 523 | } |
| 524 | wcscat_s(menutextbuffer, stringtablebuffer); |
| 525 | |
| 526 | // insert branch name into "Git Commit..." entry, so it looks like "Git Commit "master"..." |
| 527 | // so we have an easy and fast way to check the current branch |
| 528 | // (the other alternative is using a separate disabled menu entry, the code is already done but commented out) |
| 529 | if (com == TGitShellCommand::Commit) |
| 530 | { |
| 531 | // get branch name |
| 532 | CTGitPath path(folder_.empty() ? files_.front().c_str() : folder_.c_str()); |
| 533 | CString sProjectRoot; |
| 534 | CString sBranchName; |
| 535 | |
| 536 | if (path.GetAdminDirMask() & ITEMIS_SUBMODULE) |
| 537 | { |
| 538 | if (istop) |
| 539 | wcscpy_s(menutextbuffer, L"Git "); |
| 540 | else |
| 541 | menutextbuffer[0] = L'\0'; |
| 542 | MAKESTRING(IDS_MENUCOMMITSUBMODULE); |
| 543 | wcscat_s(menutextbuffer, stringtablebuffer); |
| 544 | } |
| 545 | |
| 546 | if (path.HasAdminDir(&sProjectRoot) && !CGit::GetCurrentBranchFromFile(sProjectRoot, sBranchName)) |
| 547 | { |
| 548 | if (sBranchName.GetLength() == 2 * GIT_HASH_SIZE) |
| 549 | { |
| 550 | // if SHA1 only show 4 first bytes |
| 551 | BOOL bIsSha1 = TRUE; |
| 552 | for (int i = 0; i < 2 * GIT_HASH_SIZE; ++i) |
| 553 | if ( !iswxdigit(sBranchName[i]) ) |
| 554 | { |
| 555 | bIsSha1 = FALSE; |
| 556 | break; |
| 557 | } |
| 558 | if (bIsSha1) |
| 559 | sBranchName = sBranchName.Left(g_Git.GetShortHASHLength()) + L"..."; |
| 560 | } |
| 561 | |
| 562 | // sanity check |
nothing calls this directly
no test coverage detected