private void Clone(IHostedRepository repo) { string targetDir = GetTargetDir(); if (targetDir == null) { return; } string repoSrc = repo.CloneReadWriteUrl; string cmd = GitCommandHelpers.CloneCmd(repoSrc, targetDir, false, string.Empty, null); var formProcess = new FormProcess(Settings.GitCommand, cmd); formProcess.ShowDialog(this); if (formProcess.ErrorOccurred()) { return; } Repositories.RepositoryHistory.AddMostRecentRepository(targetDir); Settings.WorkingDir = targetDir; if (_addRemoteAsTB.Text.Trim().Length > 0 && !string.IsNullOrEmpty(repo.ParentReadOnlyUrl)) { var error = Settings.Module.AddRemote(_addRemoteAsTB.Text.Trim(), repo.ParentReadOnlyUrl); if (!string.IsNullOrEmpty(error)) { MessageBox.Show(this, error, _strCouldNotAddRemote.Text); } } Close(); }
public void CloneCmd() { Assert.AreEqual( "clone -v --progress \"from\" \"to\"", GitCommandHelpers.CloneCmd("from", "to").Arguments); Assert.AreEqual( "clone -v --progress \"from/path\" \"to/path\"", GitCommandHelpers.CloneCmd("from\\path", "to\\path").Arguments); Assert.AreEqual( "clone -v --bare --progress \"from\" \"to\"", GitCommandHelpers.CloneCmd("from", "to", central: true).Arguments); Assert.AreEqual( "clone -v --recurse-submodules --progress \"from\" \"to\"", GitCommandHelpers.CloneCmd("from", "to", initSubmodules: true).Arguments); Assert.AreEqual( "clone -v --recurse-submodules --progress \"from\" \"to\"", GitCommandHelpers.CloneCmd("from", "to", initSubmodules: true).Arguments); Assert.AreEqual( "clone -v --depth 2 --progress \"from\" \"to\"", GitCommandHelpers.CloneCmd("from", "to", depth: 2).Arguments); Assert.AreEqual( "clone -v --single-branch --progress \"from\" \"to\"", GitCommandHelpers.CloneCmd("from", "to", isSingleBranch: true).Arguments); Assert.AreEqual( "clone -v --no-single-branch --progress \"from\" \"to\"", GitCommandHelpers.CloneCmd("from", "to", isSingleBranch: false).Arguments); Assert.AreEqual( "clone -v --progress --branch branch \"from\" \"to\"", GitCommandHelpers.CloneCmd("from", "to", branch: "branch").Arguments); Assert.AreEqual( "clone -v --progress --no-checkout \"from\" \"to\"", GitCommandHelpers.CloneCmd("from", "to", branch: null).Arguments); }
private void OkClick(object sender, EventArgs e) { try { Cursor = Cursors.Default; branchListLoader.Cancel(); var dirTo = _NO_TRANSLATE_To.Text; if (!dirTo.EndsWith(Settings.PathSeparator.ToString()) && !dirTo.EndsWith(Settings.PathSeparatorWrong.ToString())) { dirTo += Settings.PathSeparator.ToString(); } dirTo += _NO_TRANSLATE_NewDirectory.Text; Repositories.AddMostRecentRepository(_NO_TRANSLATE_From.Text); Repositories.AddMostRecentRepository(dirTo); if (!Directory.Exists(dirTo)) { Directory.CreateDirectory(dirTo); } var cloneCmd = GitCommandHelpers.CloneCmd(_NO_TRANSLATE_From.Text, dirTo, CentralRepository.Checked, cbIntializeAllSubmodules.Checked, Branches.Text, null); using (var fromProcess = new FormRemoteProcess(Module, Settings.GitCommand, cloneCmd)) { fromProcess.SetUrlTryingToConnect(_NO_TRANSLATE_From.Text); fromProcess.ShowDialog(this); if (fromProcess.ErrorOccurred() || Module.InTheMiddleOfPatch()) { return; } } if (openedFromProtocolHandler && AskIfNewRepositoryShouldBeOpened(dirTo)) { Hide(); GitUICommands uiCommands = new GitUICommands(dirTo); uiCommands.StartBrowseDialog(); } else if (ShowInTaskbar == false && AskIfNewRepositoryShouldBeOpened(dirTo)) { if (GitModuleChanged != null) { GitModuleChanged(new GitModule(dirTo)); } } Close(); } catch (Exception ex) { MessageBox.Show(this, "Exception: " + ex.Message, "Clone failed", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void OkClick(object sender, EventArgs e) { try { var dirTo = _NO_TRANSLATE_To.Text; if (!dirTo.EndsWith(Settings.PathSeparator.ToString()) && !dirTo.EndsWith(Settings.PathSeparatorWrong.ToString())) { dirTo += Settings.PathSeparator.ToString(); } dirTo += _NO_TRANSLATE_NewDirectory.Text; Repositories.RepositoryHistory.AddMostRecentRepository(_NO_TRANSLATE_From.Text); Repositories.RepositoryHistory.AddMostRecentRepository(dirTo); if (!Directory.Exists(dirTo)) { Directory.CreateDirectory(dirTo); } var fromProcess = new FormRemoteProcess(Settings.GitCommand, GitCommandHelpers.CloneCmd(_NO_TRANSLATE_From.Text, dirTo, CentralRepository.Checked, Branches.Text, null)); fromProcess.SetUrlTryingToConnect(_NO_TRANSLATE_From.Text); fromProcess.ShowDialog(this); if (fromProcess.ErrorOccurred() || Settings.Module.InTheMiddleOfPatch()) { return; } if (ShowInTaskbar == false && AskIfNewRepositoryShouldBeOpened(dirTo)) { Settings.WorkingDir = dirTo; if (File.Exists(Settings.WorkingDir + ".gitmodules") && AskIfSubmodulesShouldBeInitialized()) { GitUICommands.Instance.StartInitSubmodulesRecursiveDialog(this); } } Close(); } catch (Exception ex) { MessageBox.Show(this, "Exception: " + ex.Message, "Clone failed", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void Clone(IHostedRepository repo) { string targetDir = GetTargetDir(); if (targetDir == null) { return; } string repoSrc = repo.CloneReadWriteUrl; string cmd = GitCommandHelpers.CloneCmd(repoSrc, targetDir); FormRemoteProcess formRemoteProcess = new FormRemoteProcess(new GitModule(null), AppSettings.GitCommand, cmd); formRemoteProcess.Remote = repoSrc; formRemoteProcess.ShowDialog(); if (formRemoteProcess.ErrorOccurred()) { return; } GitModule module = new GitModule(targetDir); if (_addRemoteAsTB.Text.Trim().Length > 0 && !string.IsNullOrEmpty(repo.ParentReadOnlyUrl)) { var error = module.AddRemote(_addRemoteAsTB.Text.Trim(), repo.ParentReadOnlyUrl); if (!string.IsNullOrEmpty(error)) { MessageBox.Show(this, error, _strCouldNotAddRemote.Text); } } if (GitModuleChanged != null) { GitModuleChanged(this, new GitModuleEventArgs(module)); } Close(); }
private void Clone(IHostedRepository repo) { string targetDir = GetTargetDir(); if (targetDir == null) { return; } string repoSrc = repo.CloneReadWriteUrl; var cmd = GitCommandHelpers.CloneCmd(repoSrc, targetDir, depth: GetDepth()); var formRemoteProcess = new FormRemoteProcess(new GitModule(null), AppSettings.GitCommand, cmd) { Remote = repoSrc }; formRemoteProcess.ShowDialog(); if (formRemoteProcess.ErrorOccurred()) { return; } var module = new GitModule(targetDir); if (addUpstreamRemoteAsCB.Text.Trim().Length > 0 && !string.IsNullOrEmpty(repo.ParentReadOnlyUrl)) { var error = module.AddRemote(addUpstreamRemoteAsCB.Text.Trim(), repo.ParentReadOnlyUrl); if (!string.IsNullOrEmpty(error)) { MessageBox.Show(this, error, _strCouldNotAddRemote.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); } } _gitModuleChanged?.Invoke(this, new GitModuleEventArgs(module)); Close(); }
private void OkClick(object sender, EventArgs e) { try { Cursor = Cursors.Default; _branchListLoader.Cancel(); // validate if destination path is supplied var destination = _NO_TRANSLATE_To.Text; if (string.IsNullOrWhiteSpace(destination)) { MessageBox.Show(this, _errorDestinationNotSupplied.Text, _errorCloneFailed.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); _NO_TRANSLATE_To.Focus(); return; } if (!Path.IsPathRooted(destination)) { MessageBox.Show(this, _errorDestinationNotRooted.Text, _errorCloneFailed.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); _NO_TRANSLATE_To.Focus(); return; } var dirTo = Path.Combine(destination, _NO_TRANSLATE_NewDirectory.Text); // this will fail if the path is anyhow invalid dirTo = new Uri(dirTo).LocalPath; if (!Directory.Exists(dirTo)) { Directory.CreateDirectory(dirTo); } // Shallow clone params int? depth = null; bool?isSingleBranch = null; if (!cbDownloadFullHistory.Checked) { depth = 1; // Single branch considerations: // If neither depth nor single-branch family params are specified, then it's like no-single-branch by default. // If depth is specified, then single-branch is assumed. // But with single-branch it's really nontrivial to switch to another branch in the GUI, and it's very hard in cmdline (obvious choices to fetch another branch lead to local repo corruption). // So let's reset it to no-single-branch to (a) have the same branches behavior as with full clone, and (b) make it easier for users when switching branches. isSingleBranch = false; } // Branch name param string branch = _NO_TRANSLATE_Branches.Text; if (branch == _branchDefaultRemoteHead.Text) { branch = ""; } else if (branch == _branchNone.Text) { branch = null; } var cloneCmd = GitCommandHelpers.CloneCmd(_NO_TRANSLATE_From.Text, dirTo, CentralRepository.Checked, cbIntializeAllSubmodules.Checked, branch, depth, isSingleBranch, cbLfs.Checked); using (var fromProcess = new FormRemoteProcess(Module, AppSettings.GitCommand, cloneCmd)) { fromProcess.SetUrlTryingToConnect(_NO_TRANSLATE_From.Text); fromProcess.ShowDialog(this); if (fromProcess.ErrorOccurred() || Module.InTheMiddleOfPatch()) { return; } } ThreadHelper.JoinableTaskFactory.Run(() => RepositoryHistoryManager.Locals.AddAsMostRecentAsync(dirTo)); if (!string.IsNullOrEmpty(_puttySshKey)) { var clonedGitModule = new GitModule(dirTo); clonedGitModule.SetSetting(string.Format(SettingKeyString.RemotePuttySshKey, "origin"), _puttySshKey); clonedGitModule.LocalConfigFile.Save(); } if (_openedFromProtocolHandler && AskIfNewRepositoryShouldBeOpened(dirTo)) { Hide(); var uiCommands = new GitUICommands(dirTo); uiCommands.StartBrowseDialog(); } else if (ShowInTaskbar == false && _gitModuleChanged != null && AskIfNewRepositoryShouldBeOpened(dirTo)) { _gitModuleChanged(this, new GitModuleEventArgs(new GitModule(dirTo))); } Close(); } catch (Exception ex) { MessageBox.Show(this, "Exception: " + ex.Message, _errorCloneFailed.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void OkClick(object sender, EventArgs e) { try { Cursor = Cursors.Default; _branchListLoader.Cancel(); var dirTo = Path.Combine(_NO_TRANSLATE_To.Text, _NO_TRANSLATE_NewDirectory.Text); Repositories.AddMostRecentRepository(_NO_TRANSLATE_From.Text); if (!Directory.Exists(dirTo)) { Directory.CreateDirectory(dirTo); } // Shallow clone params int? depth = null; bool?isSingleBranch = null; if (!cbDownloadFullHistory.Checked) { depth = 1; // Single branch considerations: // If neither depth nor single-branch family params are specified, then it's like no-single-branch by default. // If depth is specified, then single-branch is assumed. // But with single-branch it's really nontrivial to switch to another branch in the GUI, and it's very hard in cmdline (obvious choices to fetch another branch lead to local repo corruption). // So let's reset it to no-single-branch to (a) have the same branches behavior as with full clone, and (b) make it easier for users when switching branches. isSingleBranch = false; } // Branch name param string branch = _NO_TRANSLATE_Branches.Text; if (branch == _branchDefaultRemoteHead.Text) { branch = ""; } else if (branch == _branchNone.Text) { branch = null; } var cloneCmd = GitCommandHelpers.CloneCmd(_NO_TRANSLATE_From.Text, dirTo, CentralRepository.Checked, cbIntializeAllSubmodules.Checked, branch, depth, isSingleBranch); using (var fromProcess = new FormRemoteProcess(Module, AppSettings.GitCommand, cloneCmd)) { fromProcess.SetUrlTryingToConnect(_NO_TRANSLATE_From.Text); fromProcess.ShowDialog(this); if (fromProcess.ErrorOccurred() || Module.InTheMiddleOfPatch()) { return; } } Repositories.AddMostRecentRepository(dirTo); if (openedFromProtocolHandler && AskIfNewRepositoryShouldBeOpened(dirTo)) { Hide(); GitUICommands uiCommands = new GitUICommands(dirTo); uiCommands.StartBrowseDialog(); } else if (ShowInTaskbar == false && GitModuleChanged != null && AskIfNewRepositoryShouldBeOpened(dirTo)) { GitModuleChanged(this, new GitModuleEventArgs(new GitModule(dirTo))); } Close(); } catch (Exception ex) { MessageBox.Show(this, "Exception: " + ex.Message, "Clone failed", MessageBoxButtons.OK, MessageBoxIcon.Error); } }