public static bool CreatePatch (ChangeSet items, bool test)
		{
			bool can = CanCreatePatch (items);
			if (test || !can){ return can; }
			
			Repository repo = items.Repository;
			items = items.Clone ();
			
			List<DiffInfo> diffs = new List<DiffInfo> ();
			
			object[] exts = AddinManager.GetExtensionObjects ("/MonoDevelop/VersionControl/CommitDialogExtensions", typeof(CommitDialogExtension), false);
			
			try {
				foreach (CommitDialogExtension ext in exts) {
					ext.Initialize (items);
					ext.OnBeginCommit (items);
				}
				diffs.AddRange (repo.PathDiff (items, false));
			} finally {
				foreach (CommitDialogExtension ext in exts) {
					ext.OnEndCommit (items, false);
					ext.Destroy ();
				}
			}
			
			string patch = repo.CreatePatch (diffs);
			string filename = string.Format ("{0}.diff", ((string)items.BaseLocalPath.FullPath).TrimEnd (Path.DirectorySeparatorChar));
			IdeApp.Workbench.NewDocument (filename, "text/x-diff", patch);
			return can;
		}
Exemple #2
0
			public CommitWorker (Repository vc, ChangeSet changeSet, CommitDialog dlg)
			{
				this.vc = vc;
				this.changeSet = changeSet;
				this.dlg = dlg;
				OperationType = VersionControlOperationType.Push;
			}
		public static void Commit (Repository vc, ChangeSet changeSet)
		{
			try {
				if (vc.GetVersionInfo (changeSet.BaseLocalPath).CanCommit) {
					if (!VersionControlService.NotifyPrepareCommit (vc, changeSet))
						return;

					CommitDialog dlg = new CommitDialog (changeSet);
					try {
						if (MessageService.RunCustomDialog (dlg) == (int) Gtk.ResponseType.Ok) {
							if (VersionControlService.NotifyBeforeCommit (vc, changeSet)) {
								new CommitWorker (vc, changeSet, dlg).Start();
								return;
							}
						}
						dlg.EndCommit (false);
					} finally {
						dlg.Destroy ();
					}
					VersionControlService.NotifyAfterCommit (vc, changeSet, false);
				}
			}
			catch (Exception ex) {
					MessageService.ShowException (ex, GettextCatalog.GetString ("Version control command failed."));
			}
		}
		/// <summary>
		/// Creates a patch from a VersionControlItemList
		/// </summary>
		/// <param name="items">
		/// A <see cref="VersionControlItemList"/> from which to create a patch.
		/// </param>
		/// <param name="test">
		/// A <see cref="System.Boolean"/>: Whether this is a test run.
		/// </param>
		/// <returns>
		/// A <see cref="System.Boolean"/>: Whether the patch creation succeeded.
		/// </returns>
		public static bool CreatePatch (VersionControlItemList items, bool test)
		{
			bool can = CanCreatePatch (items);
			if (test || !can){ return can; }
			
			FilePath basePath = items.FindMostSpecificParent (FilePath.Null);
			if (FilePath.Empty == basePath)
				return false;
			
			ChangeSet cset = new ChangeSet (items[0].Repository, basePath);
			foreach (VersionControlItem item in items) {
				cset.AddFile (item.Path);
			}
			return CreatePatch (cset, test);
		}
		/// <summary>
		/// Creates a patch from a VersionControlItemList
		/// </summary>
		/// <param name="items">
		/// A <see cref="VersionControlItemList"/> from which to create a patch.
		/// </param>
		/// <param name="test">
		/// A <see cref="System.Boolean"/>: Whether this is a test run.
		/// </param>
		/// <returns>
		/// A <see cref="System.Boolean"/>: Whether the patch creation succeeded.
		/// </returns>
		public static bool CreatePatch (VersionControlItemList items, bool test)
		{
			if (items.Count < 1)
				return false;
				
			FilePath basePath = FindMostSpecificParent (items, FilePath.Null);
			if (FilePath.Empty == basePath)
				return false;
			
			ChangeSet cset = new ChangeSet (items[0].Repository, basePath);
			foreach (VersionControlItem item in items) {
				cset.AddFile (item.Path);
			}
			return CreatePatch (cset, test);
		}
		public override void Initialize (ChangeSet cset)
		{	
			this.cset = cset;
			msgLabel = new Label ();
			pathLabel = new Label ();
			msgLabel.Xalign = 0;
			pathLabel.Xalign = 0;
			vbox.PackStart (msgLabel, false, false, 0);
			vbox.PackStart (pathLabel, false, false, 3);
			
			GenerateLogEntries ();
			if (enabled) {
				ShowAll ();
				UpdateStatus ();
			}
		}
		public static bool Commit (Repository vc, ChangeSet changeSet, bool test)
		{
			try {
				if (changeSet.IsEmpty) {
					if (!test)
						MessageService.ShowMessage (GettextCatalog.GetString ("There are no changes to be committed."));
					return false;
				}
				
				if (vc.GetVersionInfo (changeSet.BaseLocalPath).CanCommit) {
					if (test)
						return true;

					if (!VersionControlService.NotifyPrepareCommit (vc, changeSet))
						return false;
					CommitDialog dlg = new CommitDialog (changeSet);
					try {
						if (MessageService.RunCustomDialog (dlg) == (int) Gtk.ResponseType.Ok) {
							if (VersionControlService.NotifyBeforeCommit (vc, changeSet)) {
								new CommitWorker (vc, changeSet, dlg).Start();
								return true;
							}
						}
						dlg.EndCommit (false);
					} finally {
						dlg.Destroy ();
					}
					VersionControlService.NotifyAfterCommit (vc, changeSet, false);
				}
				return false;
			}
			catch (Exception ex) {
				if (test)
					LoggingService.LogError (ex.ToString ());
				else
					MessageService.ShowException (ex, GettextCatalog.GetString ("Version control command failed."));
				return false;
			}
		}
		public static void Commit (Repository vc, ChangeSet changeSet)
		{
			try {
				VersionControlService.NotifyPrepareCommit (vc, changeSet);

				CommitDialog dlg = new CommitDialog (changeSet);
				try {
					if (MessageService.RunCustomDialog (dlg) == (int) Gtk.ResponseType.Ok) {
						VersionControlService.NotifyBeforeCommit (vc, changeSet);
							new CommitWorker (vc, changeSet, dlg).Start();
							return;
						}
					dlg.EndCommit (false);
				} finally {
					dlg.Destroy ();
					dlg.Dispose ();
				}
				VersionControlService.NotifyAfterCommit (vc, changeSet, false);
			}
			catch (Exception ex) {
				MessageService.ShowError (GettextCatalog.GetString ("Version control command failed."), ex);
			}
		}
		// Returns a diff description between local files and the remote files.
		// baseLocalPath is the root path of the diff. localPaths is optional and
		// it can be a list of files to compare.
		public DiffInfo[] PathDiff (ChangeSet cset, bool remoteDiff)
		{
			return PathDiff (cset.BaseLocalPath, cset.Items.Select (i => i.LocalPath).ToArray (), remoteDiff);
		}
		protected abstract void OnCommit (ChangeSet changeSet, ProgressMonitor monitor);
		/// <summary>
		/// Determines whether a patch can be created 
		/// from a ChangeSet.
		/// </summary>
		public static bool CanCreatePatch (ChangeSet items) 
		{
			if (null == items || 0 == items.Count){ return false; }
			
			var vinfos = items.Repository.GetVersionInfo (items.Items.Select (i => i.LocalPath));
			return vinfos.All (i => i.CanRevert);
		}
		public override void OnEndCommit (ChangeSet changeSet, bool success)
		{
			if (!enabled)
				return;
				
			if (!success)
				RollbackMakefiles ();
			else
				DeleteBackupFiles ();
		}
		public override void Commit(ChangeSet changeSet, IProgressMonitor monitor)
		{
			throw new NotImplementedException();
		}
		internal static bool NotifyAfterCommit (Repository repo, ChangeSet changeSet, bool success)
		{
			if (EndCommit != null) {
				try {
					EndCommit (null, new CommitEventArgs (repo, changeSet, success));
				} catch (Exception ex) {
					MessageService.ShowException (ex);
					return false;
				}
			}
			if (success) {
				foreach (ChangeSetItem it in changeSet.Items)
					SetCommitComment (it.LocalPath, null, false);
				SaveComments ();
			}
			return true;
		}
		/// <summary>
		/// Called when the commit operation ends
		/// </summary>
		/// <param name='changeSet'>
		/// The changeSet being committed
		/// </param>
		/// <param name='success'>
		/// True if the commit succeeded.
		/// </param>
		public virtual void OnEndCommit (ChangeSet changeSet, bool success)
		{
		}
		/// <summary>
		/// Called when the commit operation starts.
		/// </summary>
		/// <param name='changeSet'>
		/// The changeSet being committed
		/// </param>
		/// <returns>
		/// False if the commit cannot continue.
		/// </returns>
		public virtual bool OnBeginCommit (ChangeSet changeSet)
		{
			return true;
		}
		public virtual string FormatDialogTitle (ChangeSet changeSet, string title)
		{
			return null;
		}
		/// <summary>
		/// Initialize the extension.
		/// </summary>
		/// <param name='changeSet'>
		/// The changeSet being committed
		/// </param>
		/// <returns>
		/// True if the extension is valid for the provided change set.
		/// False otherwise (the OnBeginCommit and OnEndCommit methods
		/// won't be called).
		/// </returns>
		public virtual bool Initialize (ChangeSet changeSet)
		{
			return true;
		}
		public virtual void CopyFrom (ChangeSet other)
		{
			repo = other.repo;
			basePath = other.basePath;
			items = new List<ChangeSetItem> (other.items.Select (cit => cit.Clone()));
		}
Exemple #20
0
		public virtual void CopyFrom (ChangeSet other)
		{
			repo = other.repo;
			basePath = other.basePath;
			items = new List<ChangeSetItem> ();
			foreach (ChangeSetItem cit in other.items)
				items.Add (cit.Clone ());
		}
			public CommitWorker (Repository vc, ChangeSet changeSet, CommitDialog dlg)
			{
				this.vc = vc;
				this.changeSet = changeSet;
				this.dlg = dlg;
			}
		public override void Commit (ChangeSet changeSet, IProgressMonitor monitor)
		{
		}
		internal static bool NotifyBeforeCommit (Repository repo, ChangeSet changeSet)
		{
			if (BeginCommit != null) {
				try {
					BeginCommit (null, new CommitEventArgs (repo, changeSet, false));
				} catch (Exception ex) {
					MessageService.ShowException (ex);
					return false;
				}
			}
			return true;
		}
Exemple #24
0
		// Returns a dif description between local files and the remote files.
		// baseLocalPath is the root path of the diff. localPaths is optional and
		// it can be a list of files to compare.
		public DiffInfo[] PathDiff (ChangeSet cset, bool remoteDiff)
		{
			List<FilePath> paths = new List<FilePath> ();
			foreach (ChangeSetItem item in cset.Items)
				paths.Add (item.LocalPath);
			return PathDiff (cset.BaseLocalPath, paths.ToArray (), remoteDiff);
		}
		public static CommitMessageFormat GetCommitMessageFormat (ChangeSet cset, out AuthorInformation authorInfo)
		{
			// If all files belong to a project, use that project's policy. If not, use the solution policy
			Project project = null;
			bool sameProject = true;
			foreach (ChangeSetItem item in cset.Items) {
				if (project != null) {
					if (project.Files.GetFile (item.LocalPath) == null) {
						// Not all files belong to the same project
						sameProject = false;
						break;
					}
				} else {
					project = IdeApp.Workspace.GetProjectContainingFile (item.LocalPath);
				}
			}
			CommitMessageStyle style;
			
			if (project != null) {
				VersionControlPolicy policy;
				if (sameProject)
					policy = project.Policies.Get<VersionControlPolicy> ();
				else
					policy = project.ParentSolution.Policies.Get<VersionControlPolicy> ();
				style = policy.CommitMessageStyle;
			}
			else {
				style = PolicyService.GetDefaultPolicy<CommitMessageStyle> ();
			}
			
			authorInfo = project != null ? project.AuthorInformation : AuthorInformation.Default;
			
			CommitMessageFormat format = new CommitMessageFormat ();
			format.Style = style;
			format.ShowFilesForSingleComment = false;
			
			return format;
		}
		internal CommitEventArgs (Repository repo, ChangeSet cset, bool success)
		{
			ChangeSet = cset;
			Repository = repo;
			Success = success;
		}
		public override bool OnBeginCommit (ChangeSet changeSet)
		{
			if (!enabled)
				return true;

			try {
				foreach (ChangeLogEntry ce in entries.Values) {
					if (ce.CantGenerate)
						continue;

					// Make a backup copy of the log file
					if (!ce.IsNew) {
						ce.BackupFile = System.IO.Path.GetTempFileName ();
						FileService.CopyFile (ce.File, ce.BackupFile);
						
						// Read the log file and add the new entry
						TextFile tf = TextFile.ReadFile (ce.File);
						tf.InsertText (0, ce.Message);
						tf.Save ();
					} else {
						File.WriteAllText (ce.File, ce.Message);
					}
					if (!cset.ContainsFile (ce.File)) {
						if (!cset.Repository.IsVersioned (ce.File))
							cset.Repository.Add (ce.File, false, new MonoDevelop.Core.ProgressMonitoring.NullProgressMonitor ());
						cset.AddFile (ce.File);
					}
				}
				return true;
			}
			catch (Exception e) {
				// Restore the makefiles
				LoggingService.LogError (e.ToString ());
				RollbackMakefiles ();
				throw;
			}
		}
		// Commits changes in a set of files or directories into the repository
		public void Commit (ChangeSet changeSet, ProgressMonitor monitor)
		{
			ClearCachedVersionInfo (changeSet.BaseLocalPath);
			OnCommit (changeSet, monitor);
		}
Exemple #29
0
		// Commits changes in a set of files or directories into the repository
		public abstract void Commit (ChangeSet changeSet, IProgressMonitor monitor);
		/// <summary>
		/// Determines whether a patch can be created 
		/// from a VersionControlItemList.
		/// </summary>
		public static bool CanCreatePatch (ChangeSet items) 
		{
			if (null == items || 0 == items.Count){ return false; }
			
			foreach (ChangeSetItem item in items.Items) {
				if (!items.Repository.CanRevert (item.LocalPath)) {
					return false;
				}
			}
			
			return true;
		}