Пример #1
0
		public void GetUserInfo (out string name, out string email)
		{
			try {
				name = RootRepository.Config.Get<string> ("user.name").Value;
				email = RootRepository.Config.Get<string> ("user.email").Value;
			} catch {
				string dlgName = null, dlgEmail = null;

				Runtime.RunInMainThread (() => {
					var dlg = new UserGitConfigDialog ();
					try {
						if ((Gtk.ResponseType)MessageService.RunCustomDialog (dlg) == Gtk.ResponseType.Ok) {
							dlgName = dlg.UserText;
							dlgEmail = dlg.EmailText;
							SetUserInfo (dlgName, dlgEmail);
						}
					} finally {
						dlg.Destroy ();
						dlg.Dispose ();
					}
				}).Wait ();

				name = dlgName;
				email = dlgEmail;
			}
		}
        public override bool OnBeginCommit(ChangeSet changeSet)
        {
            // In this callback we check if the user information configured in Git
            // matches the user information configured in MonoDevelop. If the configurations
            // don't match, it shows a dialog asking the user what to do.

            GitRepository repo = (GitRepository)changeSet.Repository;

            if (!widget.CommitterIsAuthor)
            {
                if (widget.AuthorName.Length > 0)
                {
                    changeSet.ExtendedProperties ["Git.AuthorName"] = widget.AuthorName;
                }
                if (widget.AuthorMail.Length > 0)
                {
                    changeSet.ExtendedProperties ["Git.AuthorEmail"] = widget.AuthorMail;
                }
            }

            Solution sol = null;

            // Locate the solution to which the changes belong
            foreach (Solution s in IdeApp.Workspace.GetAllSolutions())
            {
                if (s.BaseDirectory == changeSet.BaseLocalPath || changeSet.BaseLocalPath.IsChildPathOf(s.BaseDirectory))
                {
                    sol = s;
                    break;
                }
            }
            if (sol == null)
            {
                return(true);
            }

            string user;
            string email;

            repo.GetUserInfo(out user, out email);

            string val = sol.UserProperties.GetValue <string> ("GitUserInfo");

            if (val == "UsingMD")
            {
                // If the solution is configured to use the MD configuration, make sure the Git config is up to date.
                if (user != sol.AuthorInformation.Name || email != sol.AuthorInformation.Email)
                {
                    repo.SetUserInfo(sol.AuthorInformation.Name, sol.AuthorInformation.Email);
                }
            }
            else if (val != "UsingGIT")
            {
                if (repo.IsUserInfoDefault())
                {
                    var dlg = new UserGitConfigDialog();
                    try {
                        if (MessageService.RunCustomDialog(dlg) == (int)Gtk.ResponseType.Ok)
                        {
                            user  = dlg.UserText;
                            email = dlg.EmailText;
                            repo.SetUserInfo(dlg.UserText, dlg.EmailText);
                        }
                        else
                        {
                            return(false);
                        }
                    } finally {
                        dlg.Destroy();
                    }
                }

                if (user != sol.AuthorInformation.Name || email != sol.AuthorInformation.Email)
                {
                    // There is a conflict. Ask the user what to do
                    string gitInfo = GetDesc(user, email);
                    string mdInfo  = GetDesc(sol.AuthorInformation.Name, sol.AuthorInformation.Email);

                    UserInfoConflictDialog dlg = new UserInfoConflictDialog(mdInfo, gitInfo);
                    try {
                        if (MessageService.RunCustomDialog(dlg) == (int)Gtk.ResponseType.Ok)
                        {
                            if (dlg.UseMonoDevelopConfig)
                            {
                                repo.SetUserInfo(sol.AuthorInformation.Name, sol.AuthorInformation.Email);
                                sol.UserProperties.SetValue("GitUserInfo", "UsingMD");
                            }
                            else
                            {
                                sol.UserProperties.SetValue("GitUserInfo", "UsingGIT");
                            }
                            sol.SaveUserProperties();
                        }
                        else
                        {
                            return(false);
                        }
                    } finally {
                        dlg.Destroy();
                    }
                }
            }
            return(true);
        }
		public override bool OnBeginCommit (ChangeSet changeSet)
		{
			// In this callback we check if the user information configured in Git
			// matches the user information configured in MonoDevelop. If the configurations
			// don't match, it shows a dialog asking the user what to do.

			GitRepository repo = (GitRepository) changeSet.Repository;
			Solution sol = null;

			// Locate the solution to which the changes belong
			foreach (Solution s in IdeApp.Workspace.GetAllSolutions ()) {
				if (s.BaseDirectory == changeSet.BaseLocalPath || changeSet.BaseLocalPath.IsChildPathOf (s.BaseDirectory)) {
					sol = s;
					break;
				}
			}
			if (sol == null)
				return true;

			if (!widget.CommitterIsAuthor) {
				if (widget.AuthorName.Length > 0)
					changeSet.ExtendedProperties ["Git.AuthorName"] = widget.AuthorName;
				if (widget.AuthorMail.Length > 0)
					changeSet.ExtendedProperties ["Git.AuthorEmail"] = widget.AuthorMail;
				return true;
			}

			string user;
			string email;
			repo.GetUserInfo (out user, out email);
			
			string val = sol.UserProperties.GetValue<string> ("GitUserInfo");
			if (val == "UsingMD") {
				// If the solution is configured to use the MD configuration, make sure the Git config is up to date.
				if (user != sol.AuthorInformation.Name || email != sol.AuthorInformation.Email)
					repo.SetUserInfo (sol.AuthorInformation.Name, sol.AuthorInformation.Email);
			}
			else if (val != "UsingGIT") {
				if (repo.IsUserInfoDefault ()) {
					var dlg = new UserGitConfigDialog ();
					try {
						if (MessageService.RunCustomDialog (dlg) == (int) Gtk.ResponseType.Ok) {
							user = dlg.UserText;
							email = dlg.EmailText;
							repo.SetUserInfo (dlg.UserText, dlg.EmailText);
						} else
							return false;
					} finally {
						dlg.Destroy ();
					}
				}

				if (user != sol.AuthorInformation.Name || email != sol.AuthorInformation.Email) {
					// There is a conflict. Ask the user what to do
					string gitInfo = GetDesc (user, email);
					string mdInfo = GetDesc (sol.AuthorInformation.Name, sol.AuthorInformation.Email);
					
					UserInfoConflictDialog dlg = new UserInfoConflictDialog (mdInfo, gitInfo);
					try {
						if (MessageService.RunCustomDialog (dlg) == (int) Gtk.ResponseType.Ok) {
							if (dlg.UseMonoDevelopConfig) {
								repo.SetUserInfo (sol.AuthorInformation.Name, sol.AuthorInformation.Email);
								sol.UserProperties.SetValue ("GitUserInfo", "UsingMD");
							} else
								sol.UserProperties.SetValue ("GitUserInfo", "UsingGIT");
							sol.SaveUserProperties ();
						}
						else
							return false;
					} finally {
						dlg.Destroy ();
					}
				}
			}
			return true;
		}