private void DocumentPush() { // TO DO nothing to push tip if (ActiveCanvas.Document == null) { return; } try { string docPath = ActiveCanvas.Document.FilePath; using (var repo = new Repository(getWorkDir(docPath))) { GH_SettingsServer sserver = new GH_SettingsServer("ggit"); if (repo.Network.Remotes["origin"] == null) { MessageBox.Show("Remote origin is not exist, create a repository remotely, something like github, and paste the url into next window form."); SingleInput inputer = new SingleInput(); inputer.Text = "Remote Url"; inputer.singleLabel.Text = "Remote Url"; inputer.ConfirmEvent += (sender, content) => { repo.Network.Remotes.Add("origin", content); inputer.Close(); }; inputer.ShowDialog(); return; } Remote remote = repo.Network.Remotes["origin"]; string token = sserver.GetValue("AccessToken", ""); if (token == "") { DialogResult choose = MessageBox.Show("Do you want to set a Personal Access Token to avoid input username and password for each push ?", "Access Token didn't exist", MessageBoxButtons.YesNoCancel); if (choose == DialogResult.OK) { MessageBox.Show("Remote origin is not exist, create a repository remotely, something like github, and paste the url into next window form."); SingleInput inputer = new SingleInput(); inputer.Text = "Access Token"; inputer.singleLabel.Text = "Token"; inputer.ConfirmEvent += (sender, accessToken) => { sserver.SetValue("AccessToken", accessToken); inputer.Close(); }; inputer.ShowDialog(); } else if (choose == DialogResult.No) { DoubleInput loginForm = new DoubleInput(); loginForm.Text = "Git login"; loginForm.label1.Text = "Username"; loginForm.input2.PasswordChar = '*'; loginForm.label2.Text = "Passowrd"; loginForm.ConfirmEvent += (sd, username, password) => { if (username == "") { MessageBox.Show("Username can't be empty."); return; } if (password == "") { MessageBox.Show("E-mail can't be empty."); return; } PushOptions options1 = new PushOptions(); options1.CredentialsProvider = (_url, _user, _cred) => new UsernamePasswordCredentials { // TO DO Set AccessToken From Username = username, Password = password }; repo.Network.Push(remote, @"refs/heads/master", options1); loginForm.Close(); }; loginForm.ShowDialog(); } return; } PushOptions options = new PushOptions(); options.CredentialsProvider = (_url, _user, _cred) => new UsernamePasswordCredentials { // TO DO Set AccessToken From Username = token, Password = string.Empty }; repo.Network.Push(remote, @"refs/heads/master", options); DocumentEditor.SetStatusBarEvent(new GH_RuntimeMessage("Push done !")); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }