/// <summary> /// Checkout the specified tree. /// </summary> /// <param name="tree">The <see cref="Tree"/> to checkout.</param> /// <param name="paths">The paths to checkout.</param> /// <param name="opts">Collection of parameters controlling checkout behavior.</param> private void CheckoutTree( Tree tree, IList <string> paths, CheckoutOptions opts) { CheckoutNotifyHandler onCheckoutNotify = opts.CheckoutNotificationOptions != null ? opts.CheckoutNotificationOptions.CheckoutNotifyHandler : null; CheckoutNotifyFlags checkoutNotifyFlags = opts.CheckoutNotificationOptions != null ? opts.CheckoutNotificationOptions.NotifyFlags : default(CheckoutNotifyFlags); CheckoutCallbacks checkoutCallbacks = CheckoutCallbacks.GenerateCheckoutCallbacks(opts.OnCheckoutProgress, onCheckoutNotify); GitStrArrayIn strArray = (paths != null && paths.Count > 0) ? GitStrArrayIn.BuildFrom(ToFilePaths(paths)) : null; var options = new GitCheckoutOpts { version = 1, checkout_strategy = CheckoutStrategy.GIT_CHECKOUT_SAFE, progress_cb = checkoutCallbacks.CheckoutProgressCallback, notify_cb = checkoutCallbacks.CheckoutNotifyCallback, notify_flags = checkoutNotifyFlags, paths = strArray }; try { if (opts.CheckoutModifiers.HasFlag(CheckoutModifiers.Force)) { options.checkout_strategy = CheckoutStrategy.GIT_CHECKOUT_FORCE; } Proxy.git_checkout_tree(Handle, tree.Id, ref options); } finally { options.Dispose(); } }
public void RevertReportsCheckoutNotification() { const string revertBranchName = "refs/heads/revert"; string repoPath = SandboxRevertTestRepo(); using (var repo = new Repository(repoPath)) { // Checkout the revert branch. Branch branch = repo.Checkout(revertBranchName); Assert.NotNull(branch); bool wasCalled = false; CheckoutNotifyFlags actualNotifyFlags = CheckoutNotifyFlags.None; RevertOptions options = new RevertOptions() { OnCheckoutNotify = (path, notificationType) => { wasCalled = true; actualNotifyFlags = notificationType; return(true); }, CheckoutNotifyFlags = CheckoutNotifyFlags.Updated, }; repo.Revert(repo.Head.Tip, Constants.Signature, options); Assert.True(wasCalled); } }
/// <summary> /// Implements the <see cref="CheckoutOptions.OnCheckoutNotify"/> callback. /// </summary> /// <param name="path">The path to the file</param> /// <param name="flags">Flags for setting which notifications to receive.</param> /// <returns></returns> private static bool HandleCheckoutNotifications(string path, CheckoutNotifyFlags flags) { switch (flags) { case CheckoutNotifyFlags.Conflict: PrintMessage("conflicted file found at " + path); return(true); case CheckoutNotifyFlags.Ignored: PrintMessage("ignored file found at: " + path); return(true); case CheckoutNotifyFlags.None: PrintMessage("unchanged file found at: " + path); return(true); case CheckoutNotifyFlags.Untracked: PrintMessage("untracked file found at: " + path); return(true); case CheckoutNotifyFlags.Updated: //PrintMessage("updated file found at: " + path); return(true); default: PrintMessage("dirty file at: " + path); return(true); } }
public bool CheckoutNotifyHandler(string path, CheckoutNotifyFlags notifyFlags) { if (gitSettings.CreateFoldersForDriftingMeta) { if (UniGitPathHelper.IsMetaPath(path)) { string assetPath = AssetPathFromMeta(path); string rootedAssetPath = Path.Combine(paths.RepoPath, assetPath); if (!Path.HasExtension(assetPath) && !File.Exists(rootedAssetPath) && !Directory.Exists(rootedAssetPath)) { Directory.CreateDirectory(rootedAssetPath); logger.LogFormat(LogType.Log, "Folder '{0}' created for drifting '{1}' file.", assetPath, path); } } } return(true); }
private int OnGitCheckoutNotify( CheckoutNotifyFlags why, IntPtr pathPtr, IntPtr baselinePtr, IntPtr targetPtr, IntPtr workdirPtr, IntPtr payloadPtr) { bool result = true; if (this.onCheckoutNotify != null) { FilePath path = LaxFilePathMarshaler.FromNative(pathPtr) ?? FilePath.Empty; result = onCheckoutNotify(path.Native, why); } return(Proxy.ConvertResultToCancelFlag(result)); }
private int OnGitCheckoutNotify( CheckoutNotifyFlags why, IntPtr pathPtr, IntPtr baselinePtr, IntPtr targetPtr, IntPtr workdirPtr, IntPtr payloadPtr) { int result = 0; if (this.onCheckoutNotify != null) { string path = (pathPtr != IntPtr.Zero) ? FilePathMarshaler.FromNative(pathPtr).Native : string.Empty; result = onCheckoutNotify(path, why) ? 0 : 1; } return(result); }
public void FastForwardMergeReportsCheckoutNotifications() { string repoPath = SandboxMergeTestRepo(); using (var repo = new Repository(repoPath)) { Commit commitToMerge = repo.Branches["fast_forward"].Tip; bool wasCalled = false; CheckoutNotifyFlags actualNotifyFlags = CheckoutNotifyFlags.None; MergeOptions options = new MergeOptions() { OnCheckoutNotify = (path, notificationType) => { wasCalled = true; actualNotifyFlags = notificationType; return(true); }, CheckoutNotifyFlags = CheckoutNotifyFlags.Updated, }; repo.Merge(commitToMerge, Constants.Signature, options); Assert.True(wasCalled); Assert.Equal(CheckoutNotifyFlags.Updated, actualNotifyFlags); } }
/// <summary> /// Construct the CheckoutNotificationOptions class. /// </summary> /// <param name="checkoutNotifyHandler"><see cref="CheckoutNotifyHandler"/> that checkout notifications are reported through.</param> /// <param name="notifyFlags">The checkout notification type.</param> public CheckoutNotificationOptions(CheckoutNotifyHandler checkoutNotifyHandler, CheckoutNotifyFlags notifyFlags) { CheckoutNotifyHandler = checkoutNotifyHandler; NotifyFlags = notifyFlags; }
public void CheckingOutCallsCheckoutNotify(CheckoutNotifyFlags notifyFlags, string expectedNotificationPath, bool isDirectory) { if (isDirectory) { expectedNotificationPath = expectedNotificationPath + Path.DirectorySeparatorChar; } string repoPath = InitNewRepository(); using (var repo = new Repository(repoPath)) { PopulateBasicRepository(repo); string relativePathUpdated = "updated.txt"; Touch(repo.Info.WorkingDirectory, relativePathUpdated, "updated file text A"); repo.Stage(relativePathUpdated); repo.Commit("Commit initial update file", Constants.Signature, Constants.Signature); // Create conflicting change string relativePathConflict = "conflict.txt"; Touch(repo.Info.WorkingDirectory, relativePathConflict, "conflict file text A"); repo.Stage(relativePathConflict); repo.Commit("Initial commit of conflict.txt and update.txt", Constants.Signature, Constants.Signature); // Create another branch repo.CreateBranch("newbranch"); // Make an edit to conflict.txt and update.txt Touch(repo.Info.WorkingDirectory, relativePathUpdated, "updated file text BB"); repo.Stage(relativePathUpdated); Touch(repo.Info.WorkingDirectory, relativePathConflict, "conflict file text BB"); repo.Stage(relativePathConflict); repo.Commit("2nd commit of conflict.txt and update.txt on master branch", Constants.Signature, Constants.Signature); // Checkout other branch repo.Checkout("newbranch"); // Make alternate edits to conflict.txt and update.txt Touch(repo.Info.WorkingDirectory, relativePathUpdated, "updated file text CCC"); repo.Stage(relativePathUpdated); Touch(repo.Info.WorkingDirectory, relativePathConflict, "conflict file text CCC"); repo.Stage(relativePathConflict); repo.Commit("2nd commit of conflict.txt and update.txt on newbranch", Constants.Signature, Constants.Signature); // make conflicting change to conflict.txt Touch(repo.Info.WorkingDirectory, relativePathConflict, "conflict file text DDDD"); repo.Stage(relativePathConflict); // Create ignored change string relativePathIgnore = Path.Combine("bin", "ignored.txt"); Touch(repo.Info.WorkingDirectory, relativePathIgnore, "ignored file"); // Create untracked change string relativePathUntracked = "untracked.txt"; Touch(repo.Info.WorkingDirectory, relativePathUntracked, "untracked file"); bool wasCalled = false; string actualNotificationPath = string.Empty; CheckoutNotifyFlags actualNotifyFlags = CheckoutNotifyFlags.None; CheckoutOptions options = new CheckoutOptions() { OnCheckoutNotify = (path, notificationType) => { wasCalled = true; actualNotificationPath = path; actualNotifyFlags = notificationType; return true; }, CheckoutNotifyFlags = notifyFlags, }; Assert.Throws<MergeConflictException>(() => repo.Checkout("master", options)); Assert.True(wasCalled); Assert.Equal(expectedNotificationPath, actualNotificationPath); Assert.Equal(notifyFlags, actualNotifyFlags); } }
protected bool OnCheckoutNotify(string path, CheckoutNotifyFlags notifyFlags) { Debug.Log(path + " (" + notifyFlags + ")"); return(true); }
bool RefreshFile (string path, CheckoutNotifyFlags flags) { FilePath fp = RootRepository.FromGitPath (path); Gtk.Application.Invoke (delegate { if (IdeApp.IsInitialized) { MonoDevelop.Ide.Gui.Document doc = IdeApp.Workbench.GetDocument (fp); if (doc != null) doc.Reload (); } FileService.NotifyFileChanged (fp); VersionControlService.NotifyFileStatusChanged (new FileUpdateEventArgs (this, fp, false)); }); return true; }
protected bool OnCheckoutNotify(string path, CheckoutNotifyFlags notifyFlags) { logger.LogFormat(LogType.Log, "{0} ({1})", path, notifyFlags); return(true); }
private int OnGitCheckoutNotify( CheckoutNotifyFlags why, IntPtr pathPtr, IntPtr baselinePtr, IntPtr targetPtr, IntPtr workdirPtr, IntPtr payloadPtr) { int result = 0; if (this.onCheckoutNotify != null) { string path = (pathPtr != IntPtr.Zero) ? FilePathMarshaler.FromNative(pathPtr).Native : string.Empty; result = onCheckoutNotify(path, why) ? 0 : 1; } return result; }
private bool OnCheckoutNotify(string path, CheckoutNotifyFlags notifyFlags) { Logging.Log().Debug($"Checkout notify: {notifyFlags} {path}"); this.syncLogger.Log(this.sync, $"Checkout notify: {notifyFlags} {path}"); return(true); }
private int OnGitCheckoutNotify( CheckoutNotifyFlags why, IntPtr pathPtr, IntPtr baselinePtr, IntPtr targetPtr, IntPtr workdirPtr, IntPtr payloadPtr) { bool result = true; if (this.onCheckoutNotify != null) { FilePath path = LaxFilePathMarshaler.FromNative(pathPtr) ?? FilePath.Empty; result = onCheckoutNotify(path.Native, why); } return Proxy.ConvertResultToCancelFlag(result); }
public void CheckingOutCallsCheckoutNotify(CheckoutNotifyFlags notifyFlags, string expectedNotificationPath, bool isDirectory) { if (isDirectory) { expectedNotificationPath = expectedNotificationPath + Path.DirectorySeparatorChar; } string repoPath = InitNewRepository(); using (var repo = new Repository(repoPath)) { PopulateBasicRepository(repo); const string relativePathUpdated = "updated.txt"; Touch(repo.Info.WorkingDirectory, relativePathUpdated, "updated file text A"); repo.Stage(relativePathUpdated); repo.Commit("Commit initial update file", Constants.Signature, Constants.Signature); // Create conflicting change const string relativePathConflict = "conflict.txt"; Touch(repo.Info.WorkingDirectory, relativePathConflict, "conflict file text A"); repo.Stage(relativePathConflict); repo.Commit("Initial commit of conflict.txt and update.txt", Constants.Signature, Constants.Signature); // Create another branch repo.CreateBranch("newbranch"); // Make an edit to conflict.txt and update.txt Touch(repo.Info.WorkingDirectory, relativePathUpdated, "updated file text BB"); repo.Stage(relativePathUpdated); Touch(repo.Info.WorkingDirectory, relativePathConflict, "conflict file text BB"); repo.Stage(relativePathConflict); repo.Commit("2nd commit of conflict.txt and update.txt on master branch", Constants.Signature, Constants.Signature); // Checkout other branch repo.Checkout("newbranch"); // Make alternate edits to conflict.txt and update.txt Touch(repo.Info.WorkingDirectory, relativePathUpdated, "updated file text CCC"); repo.Stage(relativePathUpdated); Touch(repo.Info.WorkingDirectory, relativePathConflict, "conflict file text CCC"); repo.Stage(relativePathConflict); repo.Commit("2nd commit of conflict.txt and update.txt on newbranch", Constants.Signature, Constants.Signature); // make conflicting change to conflict.txt Touch(repo.Info.WorkingDirectory, relativePathConflict, "conflict file text DDDD"); repo.Stage(relativePathConflict); // Create ignored change string relativePathIgnore = Path.Combine("bin", "ignored.txt"); Touch(repo.Info.WorkingDirectory, relativePathIgnore, "ignored file"); // Create untracked change const string relativePathUntracked = "untracked.txt"; Touch(repo.Info.WorkingDirectory, relativePathUntracked, "untracked file"); bool wasCalled = false; string actualNotificationPath = string.Empty; CheckoutNotifyFlags actualNotifyFlags = CheckoutNotifyFlags.None; CheckoutOptions options = new CheckoutOptions() { OnCheckoutNotify = (path, notificationType) => { wasCalled = true; actualNotificationPath = path; actualNotifyFlags = notificationType; return(true); }, CheckoutNotifyFlags = notifyFlags, }; Assert.Throws <CheckoutConflictException>(() => repo.Checkout("master", options)); Assert.True(wasCalled); Assert.Equal(expectedNotificationPath, actualNotificationPath); Assert.Equal(notifyFlags, actualNotifyFlags); } }