Exemple #1
0
int CGit::GetRefList(STRING_VECTOR &list)
{
	int ret;
	if(this->m_IsUseGitDLL)
	{
		CAutoLocker lock(g_Git.m_critGitDllSec);
		ret = git_for_each_ref_in("",addto_list_each_ref_fn, &list);
		std::sort(list.begin(), list.end(), LogicalComparePredicate);
	}
	else
	{
		CString cmd, output;
		cmd=_T("git.exe show-ref -d");
		ret = Run(cmd, &output, NULL, CP_UTF8);
		if(!ret)
		{
			int pos=0;
			CString one;
			while( pos>=0 )
			{
				one=output.Tokenize(_T("\n"),pos);
				int start=one.Find(_T(" "),0);
				if(start>0)
				{
					CString name;
					name=one.Right(one.GetLength()-start-1);
					list.push_back(name);
				}
			}
			std::sort(list.begin(), list.end(), LogicalComparePredicate);
		}
	}
	return ret;
}
static void GetFirstEntryStartingWith(STRING_VECTOR& heystack, const CString& needle, CString& result)
{
	auto it = std::find_if(heystack.cbegin(), heystack.cend(), [&needle](const CString& entry) { return entry.Find(needle) == 0; });
	if (it == heystack.cend())
		return;
	result = *it;
}
BOOL CSettingGitRemote::OnInitDialog()
{
	ISettingsPropPage::OnInitDialog();

	//CString str=((CSettings*)GetParent())->m_CmdPath.GetWinPath();
	CString proj;
	if(	g_GitAdminDir.HasAdminDir(m_cmdPath,&proj) )
	{
		CString title;
		this->GetWindowText(title);
		this->SetWindowText(title + _T(" - ") + proj);
	}

	STRING_VECTOR remotes;
	g_Git.GetRemoteList(remotes);
	m_ctrlRemoteList.ResetContent();
	for (size_t i = 0; i < remotes.size(); i++)
		m_ctrlRemoteList.AddString(remotes[i]);

	m_ctrlTagOpt.AddString(CString(MAKEINTRESOURCE(IDS_FETCH_REACHABLE)));
	m_ctrlTagOpt.AddString(CString(MAKEINTRESOURCE(IDS_NONE)));
	m_ctrlTagOpt.AddString(CString(MAKEINTRESOURCE(IDS_FETCH_TAGS_ONLY)));
	m_ctrlTagOpt.SetCurSel(0);

	//this->GetDlgItem(IDC_EDIT_REMOTE)->EnableWindow(FALSE);
	this->UpdateData(FALSE);

	if (remotes.empty())
	{
		GetDlgItem(IDC_EDIT_REMOTE)->SetWindowText(_T("origin"));
		OnEnChangeEditRemote();
	}

	return TRUE;
}
Exemple #4
0
void CRefLogDlg::Refresh()
{
	STRING_VECTOR list;
	list.push_back(_T("HEAD"));
	if (g_Git.GetRefList(list))
		MessageBox(g_Git.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR);

	m_ChooseRef.SetList(list);

	if (m_CurrentBranch.IsEmpty())
	{
		m_CurrentBranch.Format(_T("refs/heads/%s"), (LPCTSTR)g_Git.GetCurrentBranch());
		m_ChooseRef.SetCurSel(0); /* Choose HEAD */
	}
	else
	{
		bool found = false;
		for (int i = 0; i < (int)list.size(); ++i)
		{
			if(list[i] == m_CurrentBranch)
			{
				m_ChooseRef.SetCurSel(i);
				found = true;
				break;
			}
		}
		if (!found)
			m_ChooseRef.SetCurSel(0);
	}

	m_RefList.m_RevCache.clear();

	OnCbnSelchangeRef();
}
static int SplitRemoteBranchName(CString ref, CString &remote, CString &branch)
{
	if (ref.Left(13) == _T("refs/remotes/"))
		ref = ref.Mid(13);
	else if (ref.Left(8) == _T("remotes/"))
		ref = ref.Mid(8);

	STRING_VECTOR list;
	int result = g_Git.GetRemoteList(list);
	if (result != 0)
		return result;

	for (size_t i = 0; i < list.size(); ++i)
	{
		if (ref.Left(list[i].GetLength() + 1) == list[i] + _T("/"))
		{
			remote = list[i];
			branch = ref.Mid(list[i].GetLength() + 1);
			return 0;
		}
		if (ref == list[i])
		{
			remote = list[i];
			branch = _T("");
			return 0;
		}
	}

	return -1;
}
void CDeleteRemoteTagDlg::OnBnClickedOk()
{
	if (m_ctrlTags.GetSelectedCount() > 1)
	{
		CString msg;
		msg.Format(IDS_PROC_DELETENREFS, m_ctrlTags.GetSelectedCount());
		if (CMessageBox::Show(m_hWnd, msg, _T("TortoiseGit"), 2, IDI_QUESTION, CString(MAKEINTRESOURCE(IDS_DELETEBUTTON)), CString(MAKEINTRESOURCE(IDS_ABORTBUTTON))) == 2)
			return;
	}
	else // GetSelectedCount() is 1, otherwise the button is disabled
	{
		POSITION pos = m_ctrlTags.GetFirstSelectedItemPosition();
		CString msg;
		msg.Format(IDS_PROC_DELETEBRANCHTAG, (LPCTSTR)m_taglist[(m_ctrlTags.GetNextSelectedItem(pos))]);
		if (CMessageBox::Show(m_hWnd, msg, _T("TortoiseGit"), 2, IDI_QUESTION, CString(MAKEINTRESOURCE(IDS_DELETEBUTTON)), CString(MAKEINTRESOURCE(IDS_ABORTBUTTON))) == 2)
			return;
	}

	STRING_VECTOR list;
	POSITION pos = m_ctrlTags.GetFirstSelectedItemPosition();
	int index;
	while ((index = m_ctrlTags.GetNextSelectedItem(pos)) >= 0)
		list.push_back(_T("refs/tags/") + m_taglist[index]);
	CSysProgressDlg sysProgressDlg;
	sysProgressDlg.SetTitle(CString(MAKEINTRESOURCE(IDS_APPNAME)));
	sysProgressDlg.SetLine(1, CString(MAKEINTRESOURCE(IDS_DELETING_REMOTE_REFS)));
	sysProgressDlg.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT)));
	sysProgressDlg.SetShowProgressBar(false);
	sysProgressDlg.ShowModal(this, true);
	if (g_Git.DeleteRemoteRefs(m_sRemote, list))
		CMessageBox::Show(m_hWnd, g_Git.GetGitLastErr(_T("Could not delete remote ref."), CGit::GIT_CMD_PUSH), _T("TortoiseGit"), MB_OK | MB_ICONERROR);
	sysProgressDlg.Stop();
	BringWindowToTop();
	Refresh();
}
static int DeleteOtherKeys(int type)
{
	CString match;
	if (type == SimpleCredentialType::LocalWincred)
		match = _T("L\ncredential.helper\nwincred");
	else if (type == SimpleCredentialType::LocalWinstore)
		match = _T("L\ncredential.helper\n") + GetWinstorePath();
	else if (type == SimpleCredentialType::GlobalWincred)
		match = _T("G\ncredential.helper\nwincred");
	else if (type == SimpleCredentialType::GlobalWinstore)
		match = _T("G\ncredential.helper\n") + GetWinstorePath();
	else if (type == SimpleCredentialType::SystemWincred)
		match = _T("S\ncredential.helper\nwincred");

	CAutoConfig config(true);
	git_config_add_file_ondisk(config, CGit::GetGitPathStringA(g_Git.GetGitLocalConfig()), GIT_CONFIG_LEVEL_LOCAL, FALSE);
	git_config_add_file_ondisk(config, CGit::GetGitPathStringA(g_Git.GetGitGlobalConfig()), GIT_CONFIG_LEVEL_GLOBAL, FALSE);
	git_config_add_file_ondisk(config, CGit::GetGitPathStringA(g_Git.GetGitGlobalXDGConfig()), GIT_CONFIG_LEVEL_XDG, FALSE);
	git_config_add_file_ondisk(config, CGit::GetGitPathStringA(g_Git.GetGitSystemConfig()), GIT_CONFIG_LEVEL_SYSTEM, FALSE);

	STRING_VECTOR list;
	git_config_foreach_match(config, "credential\\..*", GetCredentialAnyEntryCallback, &list);
	for (size_t i = 0; i < list.size(); ++i)
	{
		int pos = 0;
		CString prefix = list[i].Tokenize(_T("\n"), pos);
		if (prefix == _T("S") && !CAppUtils::IsAdminLogin())
		{
			RunUAC();
			return -1;
		}
	}

	int result = 0;
	// workaround gitdll bug
	// TODO: switch to libgit2
	bool old = g_Git.m_IsUseGitDLL;
	g_Git.m_IsUseGitDLL = false;
	for (size_t i = 0; i < list.size(); ++i)
	{
		if (list[i] != match)
		{
			int pos = 0;
			CString prefix = list[i].Tokenize(_T("\n"), pos);
			CString key = list[i].Tokenize(_T("\n"), pos);
			CONFIG_TYPE configLevel = prefix == _T("S") ? CONFIG_SYSTEM : prefix == _T("G") || prefix == _T("X") ? CONFIG_GLOBAL : CONFIG_LOCAL;
			if (g_Git.UnsetConfigValue(key, configLevel))
			{
				CString msg;
				msg.Format(IDS_PROC_SAVECONFIGFAILED, key, _T(""));
				CMessageBox::Show(NULL, msg, _T("TortoiseGit"), MB_OK | MB_ICONERROR);
				result = 1;
				break;
			}
		}
	}
	g_Git.m_IsUseGitDLL = old;

	return result;
}
Exemple #8
0
void CSettingGitCredential::OnBnClickedButtonRemove()
{
	int index = m_ctrlUrlList.GetCurSel();
	if (index >= 0)
	{
		CString str;
		m_ctrlUrlList.GetText(index, str);
		CString msg;
		msg.Format(IDS_WARN_REMOVE, (LPCTSTR)str);
		if (CMessageBox::Show(GetSafeHwnd(), msg, L"TortoiseGit", MB_YESNO | MB_ICONQUESTION) == IDYES)
		{
			CAutoConfig config(true);
			int pos = str.Find(L':');
			CString prefix = pos >= 0 ? str.Left(pos) : str;
			CString url = pos >= 0 ? str.Mid(pos + 1) : L"";
			CONFIG_TYPE configLevel = CONFIG_LOCAL;
			switch (prefix[0])
			{
			case L'L':
				{
				configLevel = CONFIG_LOCAL;
				git_config_add_file_ondisk(config, CGit::GetGitPathStringA(g_Git.GetGitLocalConfig()), GIT_CONFIG_LEVEL_LOCAL, FALSE);
				break;
				}
			case L'G':
			case L'X':
				{
				configLevel = CONFIG_GLOBAL;
				git_config_add_file_ondisk(config, CGit::GetGitPathStringA(g_Git.GetGitGlobalConfig()), GIT_CONFIG_LEVEL_GLOBAL, FALSE);
				git_config_add_file_ondisk(config, CGit::GetGitPathStringA(g_Git.GetGitGlobalXDGConfig()), GIT_CONFIG_LEVEL_XDG, FALSE);
				break;
				}
			case L'P':
			case L'S':
				{
				if (!CAppUtils::IsAdminLogin())
				{
					RunUAC();
					EndDialog(0);
					return;
				}
				configLevel = CONFIG_SYSTEM;
				git_config_add_file_ondisk(config, CGit::GetGitPathStringA(g_Git.GetGitSystemConfig()), GIT_CONFIG_LEVEL_SYSTEM, FALSE);
				if (!g_Git.ms_bCygwinGit && !g_Git.ms_bMsys2Git)
					git_config_add_file_ondisk(config, CGit::GetGitPathStringA(g_Git.GetGitProgramDataConfig()), GIT_CONFIG_LEVEL_PROGRAMDATA, FALSE);
				break;
				}
			}

			STRING_VECTOR list;
			CStringA urlA = CUnicodeUtils::GetUTF8(url);
			CStringA pattern = urlA.IsEmpty() ? "^credential\\.[^.]+$" : ("credential\\." + RegexEscape(urlA) + "\\..*");
			git_config_foreach_match(config, pattern, GetCredentialEntryCallback, &list);
			for (size_t i = 0; i < list.size(); ++i)
				g_Git.UnsetConfigValue(list[i], configLevel);
			m_ctrlUrlList.DeleteString(index);
			OnLbnSelchangeListUrl();
		}
	}
}
BOOL CRequestPullDlg::OnInitDialog()
{
	CHorizontalResizableStandAloneDialog::OnInitDialog();
	CAppUtils::MarkWindowAsUnpinnable(m_hWnd);

	AddAnchor(IDOK,BOTTOM_RIGHT);
	AddAnchor(IDCANCEL,BOTTOM_RIGHT);
	AddAnchor(IDHELP,BOTTOM_RIGHT);

	AddAnchor(IDC_BUTTON_LOCAL_BRANCH, TOP_RIGHT);
	AddAnchor(IDC_COMBOBOXEX_LOCAL_BRANCH, TOP_LEFT,TOP_RIGHT);
	AddAnchor(IDC_COMBOBOXEX_URL, TOP_LEFT,TOP_RIGHT);
	AddAnchor(IDC_REMOTE_BRANCH, TOP_LEFT,TOP_RIGHT);

	EnableSaveRestore(_T("RequestPullDlg"));

	CString sWindowTitle;
	GetWindowText(sWindowTitle);
	CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir, sWindowTitle);

	STRING_VECTOR list;
	int current;
	g_Git.GetBranchList(list, &current, CGit::BRANCH_ALL);
	m_cStartRevision.SetMaxHistoryItems(0x7FFFFFFF);
	for (unsigned int i = 0; i < list.size(); i++)
	{
		m_cStartRevision.AddString(list[i]);
	}

	CString WorkingDir=g_Git.m_CurrentDir;
	WorkingDir.Replace(_T(':'), _T('_'));

	m_RegStartRevision = CRegString(_T("Software\\TortoiseGit\\History\\RequestPull\\")+WorkingDir+_T("\\startrevision"));
	if(m_StartRevision.IsEmpty()) {
		m_StartRevision = m_RegStartRevision;
	}
	m_cStartRevision.SetWindowTextW(m_StartRevision);

	// store URLs in global history, but save last used local url separately,
	// because one normally has only one writable repository
	m_cRepositoryURL.SetURLHistory(TRUE);
	m_cRepositoryURL.LoadHistory(_T("Software\\TortoiseGit\\History\\RequestPull"), _T("url"));
	m_RegRepositoryURL = CRegString(_T("Software\\TortoiseGit\\History\\RequestPull\\")+WorkingDir+_T("\\repositoryurl"));
	if(m_RepositoryURL.IsEmpty())
	{
		m_RepositoryURL = m_RegRepositoryURL;
	}
	m_cRepositoryURL.SetWindowTextW(m_RepositoryURL);

	m_RegEndRevision = CRegString(_T("Software\\TortoiseGit\\History\\RequestPull\\")+WorkingDir+_T("\\endrevision"), _T("HEAD"));
	if(m_EndRevision.IsEmpty()) {
		m_EndRevision = m_RegEndRevision;
	}
	m_cEndRevision.SetWindowTextW(m_EndRevision);

	this->UpdateData(FALSE);

	return TRUE;
}
Exemple #10
0
int addto_list_each_ref_fn(const char *refname, const unsigned char * /*sha1*/, int /*flags*/, void *cb_data)
{
	STRING_VECTOR *list = (STRING_VECTOR*)cb_data;
	CString str;
	g_Git.StringAppend(&str, (BYTE*)refname, CP_UTF8);
	list->push_back(str);
	return 0;
}
Exemple #11
0
void CSyncDlg::FetchComplete()
{
	EnableControlButton(true);
	SwitchToInput();
	this->FetchOutList(true);

	if (g_Git.UsingLibGit2(CGit::GIT_CMD_FETCH))
		ShowTab(IDC_CMD_GIT_PROG);
	else
		ShowTab(IDC_REFLIST);
	if( (!this->m_GitCmdStatus) && this->m_CurrentCmd == GIT_COMMAND_FETCHANDREBASE)
	{
		CRebaseDlg dlg;
		CString remote, remotebranch;
		m_ctrlURL.GetWindowText(remote);
		if (!remote.IsEmpty())
		{
			STRING_VECTOR remotes;
			g_Git.GetRemoteList(remotes);
			if (std::find(remotes.begin(), remotes.end(), remote) == remotes.end())
				remote.Empty();
		}
		m_ctrlRemoteBranch.GetWindowText(remotebranch);
		if (!remote.IsEmpty() && !remotebranch.IsEmpty())
			dlg.m_Upstream = _T("remotes/") + remote + _T("/") + remotebranch;
		dlg.m_PostButtonTexts.Add(CString(MAKEINTRESOURCE(IDS_MENULOG)));
		dlg.m_PostButtonTexts.Add(_T("Email &Patch..."));
		INT_PTR response = dlg.DoModal();
		if(response == IDOK)
		{
			return ;
		}

		if (response == IDC_REBASE_POST_BUTTON)
		{
			CString cmd = _T("/command:log");
			cmd += _T(" /path:\"") + g_Git.m_CurrentDir + _T("\"");
			CAppUtils::RunTortoiseGitProc(cmd);
		}
		if(response == IDC_REBASE_POST_BUTTON + 1)
		{
			CString cmd, out, err;
			cmd.Format(_T("git.exe format-patch -o \"%s\" %s..%s"),
					g_Git.m_CurrentDir,
					g_Git.FixBranchName(dlg.m_Upstream),
					g_Git.FixBranchName(dlg.m_Branch));
			if (g_Git.Run(cmd, &out, &err, CP_UTF8))
			{
				CMessageBox::Show(NULL, out + L"\n" + err, _T("TortoiseGit"), MB_OK|MB_ICONERROR);
				return ;
			}

			CAppUtils::SendPatchMail(cmd,out);
		}
	}
}
Exemple #12
0
int CGit::GetRemoteList(STRING_VECTOR &list)
{
	if (this->m_IsUseLibGit2)
	{
		git_repository *repo = NULL;

		CStringA gitdir = CUnicodeUtils::GetMulti(CTGitPath(m_CurrentDir).GetGitPathString(), CP_UTF8);
		if (git_repository_open(&repo, gitdir.GetBuffer()))
		{
			gitdir.ReleaseBuffer();
			return -1;
		}
		gitdir.ReleaseBuffer();

		git_strarray remotes;

		if (git_remote_list(&remotes, repo))
		{
			git_repository_free(repo);
			return -1;
		}

		for (size_t i = 0; i < remotes.count; i++)
		{
			CStringA remote(remotes.strings[i]);
			list.push_back(CUnicodeUtils::GetUnicode(remote));
		}

		git_strarray_free(&remotes);

		git_repository_free(repo);

		std::sort(list.begin(), list.end());

		return 0;
	}
	else
	{
		int ret;
		CString cmd, output;
		cmd=_T("git.exe remote");
		ret = Run(cmd, &output, NULL, CP_UTF8);
		if(!ret)
		{
			int pos=0;
			CString one;
			while( pos>=0 )
			{
				one=output.Tokenize(_T("\n"),pos);
				if (!one.IsEmpty())
					list.push_back(one);
			}
		}
		return ret;
	}
}
int findVectorPosition(const STRING_VECTOR& vector, const CString& entry)
{
	int i = 0;
	for (auto it = vector.cbegin(); it != vector.cend(); ++it, ++i)
	{
		if (*it == entry)
			return i;
	}
	return -1;
}
Exemple #14
0
BOOL CBisectStartDlg::OnInitDialog()
{
	CHorizontalResizableStandAloneDialog::OnInitDialog();
	CAppUtils::MarkWindowAsUnpinnable(m_hWnd);

	AddAnchor(IDOK, BOTTOM_RIGHT);
	AddAnchor(IDCANCEL, BOTTOM_RIGHT);
	AddAnchor(IDHELP, BOTTOM_RIGHT);

	AddAnchor(IDC_BUTTON_GOOD, TOP_RIGHT);
	AddAnchor(IDC_BUTTON_BAD, TOP_RIGHT);
	AddAnchor(IDC_COMBOBOXEX_GOOD, TOP_LEFT, TOP_RIGHT);
	AddAnchor(IDC_COMBOBOXEX_BAD, TOP_LEFT, TOP_RIGHT);

	EnableSaveRestore(_T("BisectStartDlg"));

	CString sWindowTitle;
	GetWindowText(sWindowTitle);
	CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir, sWindowTitle);

	STRING_VECTOR list;
	int current;
	g_Git.GetBranchList(list, &current, CGit::BRANCH_ALL);
	m_cLastGoodRevision.SetMaxHistoryItems(0x7FFFFFFF);
	m_cFirstBadRevision.SetMaxHistoryItems(0x7FFFFFFF);
	for (unsigned int i = 0; i < list.size(); ++i)
	{
		m_cLastGoodRevision.AddString(list[i]);
		m_cFirstBadRevision.AddString(list[i]);
	}
	list.clear();
	g_Git.GetTagList(list);
	for (unsigned int i = 0; i < list.size(); ++i)
	{
		m_cLastGoodRevision.AddString(list[i]);
		m_cFirstBadRevision.AddString(list[i]);
	}

	if (m_sLastGood.IsEmpty())
		m_cLastGoodRevision.SetCurSel(-1);
	else
		m_cLastGoodRevision.SetWindowTextW(m_sLastGood);
	if (m_sFirstBad.IsEmpty())
		m_cFirstBadRevision.SetCurSel(current);
	else
		m_cFirstBadRevision.SetWindowTextW(m_sFirstBad);

	this->UpdateData(FALSE);

	// EnDisable OK Button
	OnChangedRevision();

	return TRUE;
}
bool CBrowseRefsDlg::DoDeleteRef(CString completeRefName)
{
	bool bIsRemoteBranch = false;
	bool bIsBranch = false;
	if		(wcsncmp(completeRefName, L"refs/remotes/",13) == 0)	{bIsBranch = true; bIsRemoteBranch = true;}
	else if	(wcsncmp(completeRefName, L"refs/heads/",11) == 0)		{bIsBranch = true;}

	if (bIsRemoteBranch)
	{
		CString branchToDelete = completeRefName.Mid(13);
		CString remoteName, remoteBranchToDelete;
		if (SplitRemoteBranchName(branchToDelete, remoteName, remoteBranchToDelete))
			return false;

		if (CAppUtils::IsSSHPutty())
			CAppUtils::LaunchPAgent(NULL, &remoteName);

		CSysProgressDlg sysProgressDlg;
		sysProgressDlg.SetTitle(CString(MAKEINTRESOURCE(IDS_APPNAME)));
		sysProgressDlg.SetLine(1, CString(MAKEINTRESOURCE(IDS_DELETING_REMOTE_REFS)));
		sysProgressDlg.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT)));
		sysProgressDlg.SetShowProgressBar(false);
		sysProgressDlg.ShowModal(this, true);

		STRING_VECTOR list;
		list.push_back(_T("refs/heads/") + remoteBranchToDelete);
		if (g_Git.DeleteRemoteRefs(remoteName, list))
		{
			CMessageBox::Show(m_hWnd, g_Git.GetGitLastErr(_T("Could not delete remote ref."), CGit::GIT_CMD_PUSH), _T("TortoiseGit"), MB_OK | MB_ICONERROR);
			sysProgressDlg.Stop();
			BringWindowToTop();
			return false;
		}
		sysProgressDlg.Stop();
		BringWindowToTop();
	}
	else if (bIsBranch)
	{
		if (g_Git.DeleteRef(completeRefName))
		{
			CMessageBox::Show(m_hWnd, g_Git.GetGitLastErr(L"Could not delete reference.", CGit::GIT_CMD_DELETETAGBRANCH), _T("TortoiseGit"), MB_OK | MB_ICONERROR);
			return false;
		}
	}
	else if (wcsncmp(completeRefName, L"refs/tags/", 10) == 0)
	{
		if (g_Git.DeleteRef(completeRefName))
		{
			CMessageBox::Show(m_hWnd, g_Git.GetGitLastErr(L"Could not delete reference.", CGit::GIT_CMD_DELETETAGBRANCH), _T("TortoiseGit"), MB_OK | MB_ICONERROR);
			return false;
		}
	}
	return true;
}
Exemple #16
0
void CPushDlg::Refresh()
{
	CString WorkingDir=g_Git.m_CurrentDir;
	WorkingDir.Replace(_T(':'),_T('_'));

	CRegString remote(CString(_T("Software\\TortoiseGit\\History\\PushRemote\\")+WorkingDir));
	m_RemoteReg = remote;
	int sel = -1;

	STRING_VECTOR list;
	m_Remote.Reset();

	list.push_back(CString(MAKEINTRESOURCE(IDS_PROC_PUSHFETCH_ALLREMOTES)));
	if(!g_Git.GetRemoteList(list))
	{
		if (list.size() <= 2)
			list.erase(list.begin());

		for (unsigned int i = 0; i < list.size(); ++i)
		{
			m_Remote.AddString(list[i]);
			if(list[i] == remote)
				sel = i;
		}
	}
	// if the last selected remote was "- All -" and "- All -" is still in the list -> select it
	if (list.size() > 1 && remote == CString(MAKEINTRESOURCE(IDS_PROC_PUSHFETCH_ALLREMOTES)))
		sel = 0;
	m_Remote.SetCurSel(sel);

	int current=0;
	list.clear();
	m_BranchSource.Reset();
	m_BranchSource.AddString(_T(" ")); // empty string does not work, for removal of remote branches/tags
	m_BranchSource.SetMaxHistoryItems(0x7FFFFFFF);
	if(!g_Git.GetBranchList(list,&current))
	{
		for (unsigned int i = 0; i < list.size(); ++i)
			m_BranchSource.AddString(list[i]);
		++current; // shift for " "
	}
	if (wcsncmp(m_BranchSourceName, _T("refs/"), 5) == 0)
		m_BranchSourceName = m_BranchSourceName.Mid(5);
	if (wcsncmp(m_BranchSourceName, _T("heads/"), 6) == 0)
	{
		m_BranchSourceName = m_BranchSourceName.Mid(6);
		m_BranchSource.SetCurSel(m_BranchSource.FindStringExact(-1, m_BranchSourceName));
	}
	else if (wcsncmp(m_BranchSourceName, _T("remotes/"), 8) == 0)
		m_BranchSource.SetCurSel(m_BranchSource.FindStringExact(-1, m_BranchSourceName));
	else
		m_BranchSource.SetCurSel(current);

	GetRemoteBranch(m_BranchSource.GetString());

	this->GetDlgItem(IDOK)->EnableWindow(m_BranchSource.GetCount() != 0);
}
Exemple #17
0
BOOL CRefLogDlg::OnInitDialog()
{
	CResizableStandAloneDialog::OnInitDialog();
	CAppUtils::MarkWindowAsUnpinnable(m_hWnd);

	AddAnchor(IDOK,BOTTOM_RIGHT);
	AddAnchor(IDCANCEL,BOTTOM_RIGHT);

	AddAnchor(IDC_REFLOG_LIST,TOP_LEFT,BOTTOM_RIGHT);
	AddAnchor(IDHELP, BOTTOM_RIGHT);

	AddOthersToAnchor();
	this->EnableSaveRestore(_T("RefLogDlg"));

	CString sWindowTitle;
	GetWindowText(sWindowTitle);
	CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir, sWindowTitle);

	STRING_VECTOR list;
	list.push_back(_T("HEAD"));
	g_Git.GetRefList(list);

	m_RefList.m_hasWC = !g_GitAdminDir.IsBareRepo(g_Git.m_CurrentDir);

	m_ChooseRef.SetMaxHistoryItems(0x7FFFFFFF);
	this->m_ChooseRef.AddString(list);

	this->m_RefList.InsertRefLogColumn();
	//m_RefList.m_logEntries.ParserFromRefLog(_T("master"));
	if(this->m_CurrentBranch.IsEmpty())
	{
		m_CurrentBranch.Format(_T("refs/heads/%s"),g_Git.GetCurrentBranch());
		m_ChooseRef.SetCurSel(0); /* Choose HEAD */
	}
	else
	{
		for(int i=0;i<list.size();i++)
		{
			if(list[i] == m_CurrentBranch)
			{
				m_ChooseRef.SetCurSel(i);
				break;
			}
		}
	}


	OnCbnSelchangeRef();

	return TRUE;
}
Exemple #18
0
int CGit::GetBranchList(STRING_VECTOR &list,int *current,BRANCH_TYPE type)
{
	int ret;
	CString cmd, output, cur;
	cmd = _T("git.exe branch --no-color");

	if((type&BRANCH_ALL) == BRANCH_ALL)
		cmd += _T(" -a");
	else if(type&BRANCH_REMOTE)
		cmd += _T(" -r");

	ret = Run(cmd, &output, NULL, CP_UTF8);
	if(!ret)
	{
		int pos=0;
		CString one;
		while( pos>=0 )
		{
			one=output.Tokenize(_T("\n"),pos);
			one.Trim(L" \r\n\t");
			if(one.Find(L" -> ") >= 0 || one.IsEmpty())
				continue; // skip something like: refs/origin/HEAD -> refs/origin/master
			if(one[0] == _T('*'))
			{
				one = one.Mid(2);
				cur = one;
			}
			if (one != _T("(no branch)"))
				list.push_back(one);
		}
	}

	if(type & BRANCH_FETCH_HEAD && !DerefFetchHead().IsEmpty())
		list.push_back(L"FETCH_HEAD");

	std::sort(list.begin(), list.end(), LogicalComparePredicate);

	if (current && cur != _T("(no branch)"))
	{
		for (unsigned int i = 0; i < list.size(); i++)
		{
			if (list[i] == cur)
			{
				*current = i;
				break;
			}
		}
	}

	return ret;
}
Exemple #19
0
void CPushDlg::Refresh()
{
	CString WorkingDir=g_Git.m_CurrentDir;
	WorkingDir.Replace(_T(':'),_T('_'));

	CRegString remote(CString(_T("Software\\TortoiseGit\\History\\PushRemote\\")+WorkingDir));
	m_RemoteReg = remote;
	int sel=0;

	STRING_VECTOR list;
	m_Remote.Reset();

	if(!g_Git.GetRemoteList(list))
	{
		for(unsigned int i=0;i<list.size();i++)
		{
			m_Remote.AddString(list[i]);
			if(list[i] == remote)
				sel = i;
		}
	}
	m_Remote.SetCurSel(sel);

	int current=0;
	list.clear();
	m_BranchSource.Reset();
	m_BranchSource.SetMaxHistoryItems(0x7FFFFFFF);
	if(!g_Git.GetBranchList(list,&current))
	{
		for(unsigned int i=0;i<list.size();i++)
			m_BranchSource.AddString(list[i]);
	}
	if (wcsncmp(m_BranchSourceName, _T("refs/"), 5) == 0)
		m_BranchSourceName = m_BranchSourceName.Mid(5);
	if (wcsncmp(m_BranchSourceName, _T("heads/"), 6) == 0)
	{
		m_BranchSourceName = m_BranchSourceName.Mid(6);
		m_BranchSource.SetCurSel(m_BranchSource.FindStringExact(-1, m_BranchSourceName));
	}
	else if (wcsncmp(m_BranchSourceName, _T("remotes/"), 8) == 0)
		m_BranchSource.SetCurSel(m_BranchSource.FindStringExact(-1, m_BranchSourceName));
	else
		m_BranchSource.SetCurSel(current);

	GetRemoteBranch(m_BranchSource.GetString());

	this->GetDlgItem(IDOK)->EnableWindow(m_BranchSource.GetCount() != 0);
}
Exemple #20
0
int CGit::GetRemoteList(STRING_VECTOR &list)
{
	int ret;
	CString cmd,output;
	cmd=_T("git.exe config  --get-regexp remote.*.url");
	ret=g_Git.Run(cmd,&output,CP_UTF8);
	if(!ret)
	{
		int pos=0;
		CString one;
		while( pos>=0 )
		{
			one=output.Tokenize(_T("\n"),pos);
			int start=one.Find(_T("."),0);
			if(start>0)
			{
				CString url;
				url=one.Right(one.GetLength()-start-1);
				one=url;
				one=one.Left(one.Find(_T("."),0));
				list.push_back(one);
			}
		}
	}
	return ret;
}
static void AddHelper(CComboBox& combobox, STRING_VECTOR& availableHelpers, const CString& helper, const CString& selected = L"")
{
	availableHelpers.push_back(helper);
	int idx = combobox.AddString(helper);
	if (selected == helper)
		combobox.SetCurSel(idx);
}
void CHistoryCombo::AddString(STRING_VECTOR &list,BOOL isSel)
{
	for(unsigned int i=0;i<list.size();i++)
	{
		AddString(list[i], -1, isSel);
	}
}
Exemple #23
0
int CGit::GetBranchList(STRING_VECTOR &list,int *current,BRANCH_TYPE type)
{
	int ret;
	CString cmd,output;
	cmd=_T("git.exe branch");

	if(type==(BRANCH_LOCAL|BRANCH_REMOTE))
		cmd+=_T(" -a");
	else if(type==BRANCH_REMOTE)
		cmd+=_T(" -r");

	int i=0;
	ret=g_Git.Run(cmd,&output,CP_UTF8);
	if(!ret)
	{		
		int pos=0;
		CString one;
		while( pos>=0 )
		{
			one=output.Tokenize(_T("\n"),pos);
			list.push_back(one.Right(one.GetLength()-2));
			if(one[0] == _T('*'))
				if(current)
					*current=i;
			i++;
		}
	}
	return ret;
}
BOOL CRevGraphFilterDlg::OnInitDialog()
{
	CDialog::OnInitDialog();
	this->m_ctrlFromRev.Init();
	this->m_ctrlToRev.Init();

	STRING_VECTOR list;
	g_Git.GetRefList(list);

	m_ctrlFromRev.AddSearchString(_T("HEAD"));
	m_ctrlToRev.AddSearchString(_T("HEAD"));

	for(int i=0;i<list.size();i++)
	{
		CString str=list[i];

		m_ctrlFromRev.AddSearchString(list[i]);
		m_ctrlToRev.AddSearchString(list[i]);

		if(str.Find(_T("refs/")) == 0)
		{
			m_ctrlFromRev.AddSearchString(list[i].Mid(5));
			m_ctrlToRev.AddSearchString(list[i].Mid(5));
		}

		if(str.Find(_T("refs/heads/")) == 0)
		{
			m_ctrlFromRev.AddSearchString(list[i].Mid(11));
			m_ctrlToRev.AddSearchString(list[i].Mid(11));
		}

		if(str.Find(_T("refs/remotes/")) == 0)
		{
			m_ctrlFromRev.AddSearchString(list[i].Mid(13));
			m_ctrlToRev.AddSearchString(list[i].Mid(13));
		}

		if(str.Find(_T("refs/tags/")) == 0)
		{
			m_ctrlFromRev.AddSearchString(list[i].Mid(10));
			m_ctrlToRev.AddSearchString(list[i].Mid(10));
		}
	}

	return TRUE;
}
Exemple #25
0
void CSyncDlg::Refresh()
{
	theApp.DoWaitCursor(1);

	int lastSelected = m_ctrlURL.GetCurSel();
	CString url;
	this->m_ctrlURL.GetWindowText(url);

	this->m_ctrlURL.Reset();
	CString workingDir = g_Git.m_CurrentDir;
	workingDir.Replace(_T(':'), _T('_'));
	this->m_ctrlURL.LoadHistory(_T("Software\\TortoiseGit\\History\\SyncURL\\") + workingDir, _T("url"));

	STRING_VECTOR list;
	bool found = false;
	if (!g_Git.GetRemoteList(list))
	{
		for (size_t i = 0; i < list.size(); ++i)
		{
			m_ctrlURL.AddString(list[i]);
			if (list[i] == url)
				found = true;
		}
	}
	if (lastSelected >= 0 && !found)
	{
		m_ctrlURL.SetCurSel(0);
		m_ctrlURL.GetWindowText(url);
	}

	CString local;
	CString remote;
	this->m_ctrlLocalBranch.GetWindowText(local);
	this->m_ctrlRemoteBranch.GetWindowText(remote);

	this->LoadBranchInfo();

	this->m_ctrlLocalBranch.AddString(local);
	this->m_ctrlRemoteBranch.AddString(remote);
	this->m_ctrlURL.AddString(url);

	m_OutLogList.ShowText(CString(MAKEINTRESOURCE(IDS_PROC_SYNC_REFRESHING)));
	this->FetchOutList(true);
	theApp.DoWaitCursor(-1);
}
static void GetSubmodulePathList(STRING_VECTOR &list, STRING_VECTOR &prefixList)
{
	CAutoRepository repo(g_Git.GetGitRepository());
	if (!repo)
	{
		MessageBox(NULL, CGit::GetLibGit2LastErr(_T("Could not open repository.")), _T("TortoiseGit"), MB_ICONERROR);
		return;
	}

	STRING_VECTOR *listParams[] = { &list, &prefixList };
	if (git_submodule_foreach(repo, SubmoduleCallback, &listParams))
	{
		MessageBox(NULL, CGit::GetLibGit2LastErr(_T("Could not get submodule list.")), _T("TortoiseGit"), MB_ICONERROR);
		return;
	}

	std::sort(list.begin(), list.end(), LogicalComparePredicate);
}
Exemple #27
0
void CRebaseDlg::LoadBranchInfo()
{
	m_BranchCtrl.SetMaxHistoryItems(0x7FFFFFFF);
	m_UpstreamCtrl.SetMaxHistoryItems(0x7FFFFFFF);

	STRING_VECTOR list;
	list.clear();
	int current;
	g_Git.GetBranchList(list,&current,CGit::BRANCH_ALL);
	m_BranchCtrl.AddString(list);
	list.clear();
	g_Git.GetBranchList(list,&current,CGit::BRANCH_ALL_F);
	m_UpstreamCtrl.AddString(list);

	m_BranchCtrl.SetCurSel(current);

	AddBranchToolTips(&m_BranchCtrl);
	AddBranchToolTips(&m_UpstreamCtrl);

	if(!m_Upstream.IsEmpty())
	{
		m_UpstreamCtrl.AddString(m_Upstream);
		m_UpstreamCtrl.SetCurSel(m_UpstreamCtrl.GetCount()-1);
	}
	else
	{
		//Select pull-remote from current branch
		CString currentBranch = g_Git.GetSymbolicRef();
		CString configName;
		configName.Format(L"branch.%s.remote", currentBranch);
		CString pullRemote = g_Git.GetConfigValue(configName);

		//Select pull-branch from current branch
		configName.Format(L"branch.%s.merge", currentBranch);
		CString pullBranch = CGit::StripRefName(g_Git.GetConfigValue(configName));

		CString defaultUpstream;
		defaultUpstream.Format(L"remotes/%s/%s", pullRemote, pullBranch);
		int found = m_UpstreamCtrl.FindStringExact(0, defaultUpstream);
		if(found >= 0)
			m_UpstreamCtrl.SetCurSel(found);
	}
}
static void GetSubmodulePathList(STRING_VECTOR &list, STRING_VECTOR &prefixList)
{
    git_repository *repo;
    if (git_repository_open(&repo, CUnicodeUtils::GetUTF8(g_Git.m_CurrentDir)))
    {
        MessageBox(NULL, CGit::GetLibGit2LastErr(_T("Could not open repository.")), _T("TortoiseGit"), MB_ICONERROR);
        return;
    }

    STRING_VECTOR *listParams[] = { &list, &prefixList };
    if (git_submodule_foreach(repo, SubmoduleCallback, &listParams))
    {
        MessageBox(NULL, CGit::GetLibGit2LastErr(_T("Could not get submodule list.")), _T("TortoiseGit"), MB_ICONERROR);
        return;
    }

    git_repository_free(repo);
    std::sort(list.begin(), list.end());
}
Exemple #29
0
void CPushDlg::Refresh()
{
	CString WorkingDir=g_Git.m_CurrentDir;
	WorkingDir.Replace(_T(':'),_T('_'));

	CRegString remote(CString(_T("Software\\TortoiseGit\\History\\PushRemote\\")+WorkingDir));
	m_RemoteReg = remote;
	int sel = -1;

	STRING_VECTOR list;
	m_Remote.Reset();

	if(!g_Git.GetRemoteList(list))
	{
		if (list.size() > 1)
			m_Remote.AddString(CString(MAKEINTRESOURCE(IDS_PROC_PUSHFETCH_ALLREMOTES)));
		for (unsigned int i = 0; i < list.size(); ++i)
		{
			m_Remote.AddString(list[i]);
			if(list[i] == remote)
				sel = i + (list.size() > 1 ? 1 : 0);
		}
	}
	else
		MessageBox(g_Git.GetGitLastErr(_T("Could not get list of remotes.")), _T("TortoiseGit"), MB_ICONERROR);
	// if the last selected remote was "- All -" and "- All -" is still in the list -> select it
	if (list.size() > 1 && remote == CString(MAKEINTRESOURCE(IDS_PROC_PUSHFETCH_ALLREMOTES)))
		sel = 0;
	m_Remote.SetCurSel(sel);

	int current = -1;
	list.clear();
	m_BranchSource.Reset();
	m_BranchSource.SetMaxHistoryItems(0x7FFFFFFF);
	if(!g_Git.GetBranchList(list,&current))
		m_BranchSource.SetList(list);
	else
		MessageBox(g_Git.GetGitLastErr(_T("Could not get list of local branches.")), _T("TortoiseGit"), MB_ICONERROR);
	if (wcsncmp(m_BranchSourceName, _T("refs/"), 5) == 0)
		m_BranchSourceName = m_BranchSourceName.Mid(5);
	if (wcsncmp(m_BranchSourceName, _T("heads/"), 6) == 0)
	{
		m_BranchSourceName = m_BranchSourceName.Mid(6);
		m_BranchSource.SetCurSel(m_BranchSource.FindStringExact(-1, m_BranchSourceName));
	}
	else if (wcsncmp(m_BranchSourceName, _T("remotes/"), 8) == 0)
		m_BranchSource.SetCurSel(m_BranchSource.FindStringExact(-1, m_BranchSourceName));
	else
		m_BranchSource.SetCurSel(current);

	GetRemoteBranch(m_BranchSource.GetString());

	this->GetDlgItem(IDOK)->EnableWindow(m_BranchSource.GetCount() != 0);

	if (list.size() > 1 && m_bPushAllRemotes)
		m_Remote.SetCurSel(0);
	m_bPushAllRemotes = FALSE; // reset to FALSE, so that a refresh does not reselect all even if it was already deselected by user; correct value will be set in OnBnClickedOk method
}
BOOL CSettingGitRemote::OnInitDialog()
{
    ISettingsPropPage::OnInitDialog();

    //CString str=((CSettings*)GetParent())->m_CmdPath.GetWinPath();
    CString proj;
    if(	g_GitAdminDir.HasAdminDir(m_cmdPath,&proj) )
    {
        CString title;
        this->GetWindowText(title);
        this->SetWindowText(title + _T(" - ") + proj);
    }

    STRING_VECTOR remotes;
    g_Git.GetRemoteList(remotes);
    m_ctrlRemoteList.ResetContent();
    for (size_t i = 0; i < remotes.size(); i++)
        m_ctrlRemoteList.AddString(remotes[i]);

    m_ctrlTagOpt.AddString(CString(MAKEINTRESOURCE(IDS_FETCH_REACHABLE)));
    m_ctrlTagOpt.AddString(CString(MAKEINTRESOURCE(IDS_NONE)));
    m_ctrlTagOpt.AddString(CString(MAKEINTRESOURCE(CAppUtils::GetMsysgitVersion() < 0x01090000 ? IDS_FETCH_TAGS_ONLY : IDS_ALL)));
    m_ctrlTagOpt.SetCurSel(0);

    if (CAppUtils::GetMsysgitVersion() < 0x0108030)
    {
        GetDlgItem(IDC_CHECK_PUSHDEFAULT)->ShowWindow(SW_HIDE);
    }
    if (CAppUtils::GetMsysgitVersion() < 0x0108050)
    {
        GetDlgItem(IDC_CHECK_PRUNE)->ShowWindow(SW_HIDE);
        GetDlgItem(IDC_CHECK_PRUNEALL)->ShowWindow(SW_HIDE);
    }

    CString pruneAll = g_Git.GetConfigValue(_T("fetch.prune"));
    m_bPruneAll = pruneAll == _T("true") ? TRUE : FALSE;

    //this->GetDlgItem(IDC_EDIT_REMOTE)->EnableWindow(FALSE);
    this->UpdateData(FALSE);

    SetTimer(TIMER_PREFILL, 1000, nullptr);
    return TRUE;
}