/// <summary> /// Get a single file version from the git repository /// </summary> /// <param name="repoPath">Repository main path</param> /// <param name="tmpItem">The temporary item table holding the sha commit</param> /// <returns>a temporary file path</returns> public static string FileGetVersion(string repoPath, string fileName, SysVersionControlTmpItem tmpItem) { string indexPath = tmpItem.InternalFilename.Replace(repoPath, string.Empty); CheckoutOptions options = new CheckoutOptions(); options.CheckoutModifiers = CheckoutModifiers.Force; using (Repository repo = new Repository(repoPath)) { var commit = repo.Lookup <Commit>(tmpItem.GTXSha); if (commit != null) { try { repo.CheckoutPaths(commit.Id.Sha, new [] { fileName }, options); } catch (MergeConflictException ex) { //should not reach here as we're forcing checkout throw ex; } } } return(fileName); }
public void Revert(IEnumerable <string> paths) { try { var options = new CheckoutOptions(); options.CheckoutModifiers = CheckoutModifiers.Force; options.OnCheckoutNotify = (string path, CheckoutNotifyFlags notifyFlag) => { Trace.TraceInformation("git revert file '{0}'... {1}", path, notifyFlag); return(true); }; _repo.CheckoutPaths(_repo.Head.FriendlyName, paths, options); //var results = _repo.Revert(_repo.Head.Tip, GetSignature()); //if (results.Status == RevertStatus.Conflicts) //{ // throw new GitException("Revert resulted in conflicts. Revert failed."); //} Refresh(paths); } catch (LibGit2SharpException ex) { throw new GitException("Revert failed.", ex); } }
/// <summary> /// Resets the changes of a file to it's HEAD last commit /// </summary> /// <param name="repoPath">Repository main path</param> /// <param name="fileName">The file path</param> /// <returns>True if reset was successful false if not</returns> public static bool FileUndoCheckout(string repoPath, string fileName, bool forceCheckout) { //TODO: Dangerous, consider refactoring FileInfo fileInfo = new FileInfo(fileName); using (Repository repo = new Repository(repoPath)) { string indexPath = fileInfo.FullName.Replace(repo.Info.WorkingDirectory, string.Empty); CheckoutOptions checkoutOptions = new CheckoutOptions { CheckoutModifiers = forceCheckout ? CheckoutModifiers.Force : CheckoutModifiers.None }; var fileCommits = repo.Head.Commits.Where(c => c.Parents.Count() == 1 && c.Tree[indexPath] != null && (c.Parents.FirstOrDefault().Tree[indexPath] == null || c.Tree[indexPath].Target.Id != c.Parents.FirstOrDefault().Tree[indexPath].Target.Id) ); if (fileCommits.Any()) { var lastCommit = fileCommits.First(); repo.CheckoutPaths(lastCommit.Id.Sha, new[] { fileName }, checkoutOptions); } return(true); } }
// ------------------------------------------------------------- public string ShowCheckoutWindowAsync( PaddleProductID productID, CheckoutOptions options, bool openInBrowser, bool isDialog) { ScTask task = new ScTask(); PaddleProduct product = Paddle_GetProduct(productID); product.Refresh((success) => { #if kUseThreads // do on another thread i_threadData.i_currentWindowType = (PaddleWindowType)PaddleWindowType.Checkout; i_threadData.i_currentProduct = product; i_threadData.i_checkoutOptions = options; i_threadData.i_openInBrowser = openInBrowser; i_threadData.i_isDialog = isDialog; StartWindowThread(); #else // do it on this thread Paddle.Instance.ShowCheckoutWindowForProduct(product, options, openInBrowser, isDialog); #endif }); return(task.await_result()); }
//------------------------------------------------------------------- private string Purchase(string jsonCmd) { string jsonResult = ""; JObject cmdObject = JObject.Parse(jsonCmd); PaddleProductID prodID = cmdObject.Value <PaddleProductID>(kPaddleCmdKey_SKU); string emailStr = cmdObject.Value <string>(kPaddleCmdKey_EMAIL); string couponStr = cmdObject.Value <string>(kPaddleCmdKey_COUPON); string countryStr = cmdObject.Value <string>(kPaddleCmdKey_COUNTRY); string postStr = cmdObject.Value <string>(kPaddleCmdKey_POSTCODE); string titleStr = cmdObject.Value <string>(kPaddleCmdKey_TITLE); string messageStr = cmdObject.Value <string>(kPaddleCmdKey_MESSAGE); CheckoutOptions checkoutOptions = new CheckoutOptions { Email = emailStr, Coupon = couponStr, Country = countryStr, PostCode = postStr }; // custom param keys are documented here: // https://paddle.com/docs/api-custom-checkout/ checkoutOptions.AddCheckoutParameters("quantity_variable", "0"); checkoutOptions.AddCheckoutParameters("title", titleStr); checkoutOptions.AddCheckoutParameters("custom_message", messageStr); // documented here: https://paddle.com/docs/checkout-options-windows-sdk/ jsonResult = ShowCheckoutWindowAsync(prodID, checkoutOptions, false, true); return(jsonResult); }
public override bool Revert(string path, ref string error) { try { using (var repo = new LibGit2Sharp.Repository(RepositoryRootFolder)) { if (Path.GetFullPath(new Uri(RepositoryRootFolder).LocalPath).TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar).ToUpperInvariant() == Path.GetFullPath(new Uri(path).LocalPath).TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar).ToUpperInvariant()) { //undo all changes repo.Reset(ResetMode.Hard); } else { //undo specific changes string committishOrBranchSpec = "master"; CheckoutOptions checkoutOptions = new CheckoutOptions(); checkoutOptions.CheckoutModifiers = CheckoutModifiers.Force; checkoutOptions.CheckoutNotifyFlags = CheckoutNotifyFlags.Ignored; repo.CheckoutPaths(committishOrBranchSpec, new[] { path }, checkoutOptions); } } } catch (Exception e) { error = e.Message + Environment.NewLine + e.InnerException; return(false); } return(true); }
internal static void ActualizarUltimaRama(string proyecto) { string ramaActual = GetActualBranchRepository(proyecto); string rutaDirectorio = $"{AppContext.BaseDirectory}Views/{proyecto}"; using (var repo = new Repository(rutaDirectorio)) { Branch rama = FindBranch(ramaActual, repo); if (rama == null) { // Let's get a reference on the remote tracking branch... string trackedBranchName = "origin/" + ramaActual; Branch trackedBranch = repo.Branches[trackedBranchName]; // ...and create a local branch pointing at the same Commit Branch branch = repo.CreateBranch(ramaActual, trackedBranch.Tip); // So, let's configure the local branch to track the remote one. rama = repo.Branches.Update(branch, b => b.TrackedBranch = trackedBranch.CanonicalName); } CheckoutOptions option = new CheckoutOptions(); option.CheckoutModifiers = CheckoutModifiers.None; Commands.Checkout(repo, rama, option); repo.Index.Write(); } }
protected override void OnEnable() { checkoutOptions = new CheckoutOptions() { }; base.OnEnable(); }
public void CheckoutRepo(string branch = "master", string remote = "origin") { loadRepo(); if (repo.Branches[branch] == null) { Fetch(remote); var trackedBranch = repo.Branches[$"{remote}/{branch}"]; if (trackedBranch == null) { throw new Exception($"Branch '{branch}' is not found localy or on remote '{remote}'."); } var newBranch = repo.CreateBranch(branch, trackedBranch.Tip); repo.Branches.Update(newBranch, b => b.TrackedBranch = trackedBranch.CanonicalName); } repo.Reset(ResetMode.Hard, repo.Head.TrackedBranch?.Tip ?? repo.Head.Tip); var checkoutOptions = new CheckoutOptions() { CheckoutModifiers = CheckoutModifiers.Force, }; Commands.Checkout(repo, branch, checkoutOptions); //repo.Reset(ResetMode.Hard); // TGS has it, but do we need it? UpdateSubmodules(); // TODO: Stage a update }
/// <summary> /// Synchronizes a folder /// </summary> /// <param name="repoPath">Main repository path</param> /// <param name="folderPath">The folder to synchronize (checkout). Could be the model path or the layer path</param> /// <param name="forceCheckout">Forces the update from the latest commit (head tip)</param> /// <returns>A SysVersionControlItem with all the files that have been affected</returns> public static SysVersionControlTmpItem FolderSync(string repoPath, string folderPath, bool forceCheckout) { SysVersionControlTmpItem tmpItem = new SysVersionControlTmpItem(); CheckoutOptions checkoutOptions = new CheckoutOptions { CheckoutModifiers = forceCheckout ? CheckoutModifiers.Force : CheckoutModifiers.None }; string tipSha; string folderName = folderPath.Split('\\').Last(); using (Repository repo = new Repository(repoPath)) { repo.CheckoutPaths(repo.Head.Tip.Id.Sha, new[] { folderPath }, checkoutOptions); tipSha = repo.Head.Tip.Id.Sha; InitTmpItemFromTree(repoPath, repo.Head.Tip.Tree[folderName].Target as Tree, ref tmpItem); } return(tmpItem); }
/// <summary> /// Checkout a tree, and if it fails, recursively attempt to checkout all of its members. /// </summary> /// <param name="repo">The repo to check files out in</param> /// <param name="tree">The current tree we're looking at (starts at root)</param> /// <param name="treePath">The built-up path of the tree we are currently recursively in</param> /// <param name="commit">The commit we are trying to checkout at. This should be resolved already if it needs to be (i.e. normal whole-repo checkout failed)</param> /// <param name="options">Options for checkout - mostly used to force checkout</param> /// <param name="log">Logger</param> private static void SafeCheckoutTreeByIndividualFiles(Repository repo, Tree tree, string treePath, string commit, CheckoutOptions options, ILogger log) { foreach (TreeEntry f in tree) { try { repo.CheckoutPaths(commit, new[] { Path.Combine(treePath, f.Path) }, options); } catch (Exception e) when(e is InvalidSpecificationException || e is NameConflictException || e is LibGit2SharpException) { log.LogWarning($"Failed to checkout {Path.Combine(treePath, f.Path)} in {repo.Info.WorkingDirectory} at {commit}, skipping. Exception: {e.ToString()}"); if (f.TargetType == TreeEntryTargetType.Tree) { SafeCheckoutTreeByIndividualFiles(repo, f.Target.Peel <Tree>(), Path.Combine(treePath, f.Path), commit, options, log); } } } }
protected virtual CheckoutOptions GetOptions(MarketId marketId) { var configuration = GetConfiguration(marketId); var options = new CheckoutOptions { RequireValidateCallbackSuccess = configuration.RequireValidateCallbackSuccess, AllowSeparateShippingAddress = configuration.AllowSeparateShippingAddress, ColorButton = GetColor(configuration.WidgetButtonColor), ColorButtonText = GetColor(configuration.WidgetButtonTextColor), ColorCheckbox = GetColor(configuration.WidgetCheckboxColor), ColorCheckboxCheckmark = GetColor(configuration.WidgetCheckboxCheckmarkColor), ColorHeader = GetColor(configuration.WidgetHeaderColor), ColorLink = GetColor(configuration.WidgetLinkColor), RadiusBorder = configuration.WidgetBorderRadius, DateOfBirthMandatory = configuration.DateOfBirthMandatory, ShowSubtotalDetail = configuration.ShowSubtotalDetail, TitleMandatory = configuration.TitleMandatory, ShippingDetails = configuration.ShippingDetailsText }; var additionalCheckboxText = configuration.AdditionalCheckboxText; if (!string.IsNullOrEmpty(additionalCheckboxText)) { options.AdditionalCheckbox = new AdditionalCheckbox { Text = additionalCheckboxText, Checked = configuration.AdditionalCheckboxDefaultChecked, Required = configuration.AdditionalCheckboxRequired }; } return(options); }
public void DiscardChanges(StatusItem statusItem) { var options = new CheckoutOptions { CheckoutModifiers = CheckoutModifiers.Force }; _repository.CheckoutPaths(_repository.Head.FriendlyName, new[] { statusItem.Path }, options); }
// rebase current branch and pull from master // @handled @logs public static UpdateStatus ForcedUpdate(string repoPath, string username, string password) { logger.Debug("Force updating repo \"{0}\"...", repoPath); try { var repo = new Repository(repoPath); var options = new PullOptions(); var fetchOpts = new FetchOptions(); // add username and password to clone options, if provided by user if (username != null && password != null) { fetchOpts.CredentialsProvider = (_url, _usernameFromUrl, _credTypes) => new UsernamePasswordCredentials { Username = username, Password = password } } ; options.FetchOptions = fetchOpts; // before updating, let's first // forced checkout to overwrite possible local changes // Re: https://github.com/eirannejad/pyRevit/issues/229 var checkoutOptions = new CheckoutOptions(); checkoutOptions.CheckoutModifiers = CheckoutModifiers.Force; Commands.Checkout(repo, repo.Head, checkoutOptions); // now let's pull from the tracked remote var res = Commands.Pull(repo, new Signature("GitInstaller", commiterEmail, new DateTimeOffset(DateTime.Now)), options); // process the results and let user know if (res.Status == MergeStatus.FastForward) { logger.Debug("Fast-Forwarded repo \"{0}\"", repoPath); return(UpdateStatus.FastForward); } else if (res.Status == MergeStatus.NonFastForward) { logger.Debug("Non-Fast-Forwarded repo \"{0}\"", repoPath); return(UpdateStatus.NonFastForward); } else if (res.Status == MergeStatus.Conflicts) { logger.Debug("Conflicts on updating clone \"{0}\"", repoPath); return(UpdateStatus.Conflicts); } logger.Debug("Repo \"{0}\" is already up to date.", repoPath); return(UpdateStatus.UpToDate); } catch (Exception ex) { throw new PyRevitException(ex.Message, ex); } }
public void UndoFileChanges(string filename) { using (var repository = GetRepository()) { CheckoutOptions options = new CheckoutOptions { CheckoutModifiers = CheckoutModifiers.Force }; repository.CheckoutPaths("HEAD", new string[] { filename }, options); } }
public void Set(CheckoutOptions other) { if (other != null) { m_ApiVersion = EcomInterface.CheckoutApiLatest; LocalUserId = other.LocalUserId; OverrideCatalogNamespace = other.OverrideCatalogNamespace; Entries = other.Entries; } }
private static void SetupDevBranch(Repository repository, string branchName, string masterName, Signature author) { Log("Setting Up Dev Branch"); var branch = repository.AddGetBranch(branchName, masterName, track: true); CheckoutOptions options = new CheckoutOptions(); options.CheckoutModifiers = CheckoutModifiers.Force; repository.TryCheckout(branch, true); Log("Checked out Dev Branch"); }
public HomeController() { string sellerCode = "0102"; string successUrlReturn = "http://localhost:5525/Home/PaymentSuccessReturnUrl"; //"YOUR_SUCCESS_URL"; string ipnUrlReturn = "http://localhost:5525/Home/IPNDestination"; //"YOUR_IPN_URL"; string cancelUrlReturn = "http://localhost:5525/Home/PaymentCancelReturnUrl"; //"YOUR_CANCEL_URL"; string failureUrlReturn = ""; //"YOUR_FAILURE_URL"; bool useSandBox = true; checkoutoptions = new CheckoutOptions(sellerCode, string.Empty, CheckoutType.Express, useSandBox, null, successUrlReturn, cancelUrlReturn, ipnUrlReturn, failureUrlReturn); }
public void GivenUriNullOrEmptyShouldDefaultToSandbox(string uri) { var options = new CheckoutOptions { SecretKey = "sk_xxx", Uri = uri }; var configuration = options.CreateConfiguration(); configuration.Uri.ShouldBe(CheckoutConfiguration.SandboxUri); }
public void GivenSandboxFalseShouldUseProductionUri() { var options = new CheckoutOptions { SecretKey = "sk_xxx", UseSandbox = false }; var configuration = options.CreateConfiguration(); configuration.Uri.ShouldBe(CheckoutConfiguration.ProductionUri); }
public void Switch(string headText, bool pull = false) { Branch branch; Branch existingBranch; var splittext = headText.Split('/'); var name = splittext.Last(); //Find name (case sensitive) or sha, local first existingBranch = Repo.Branches.OrderBy(x => x.IsRemote).FirstOrDefault(x => x.FriendlyName.EndsWith(name) || x.Tip.Sha.StartsWith(name)); //Try lower case name, local first if (existingBranch == null) { name = name.ToLower(); existingBranch = Repo.Branches.OrderBy(x => x.IsRemote).FirstOrDefault(x => x.FriendlyName.ToLower().EndsWith(name)); } var chechoutOptions = new CheckoutOptions() { }; //If remote only if (existingBranch != null && existingBranch.IsRemote) { Branch newBranch = Repo.CreateBranch(name, existingBranch.Tip); // Make the local branch track the upstream one Repo.Branches.Update(newBranch, b => b.TrackedBranch = existingBranch.CanonicalName); existingBranch = newBranch; } if (existingBranch != null) { branch = Commands.Checkout(Repo, existingBranch, chechoutOptions); } else { //Try using gitlib to find branch or commit branch = Commands.Checkout(Repo, headText, chechoutOptions); } if (pull) { PullOptions pulloptions = new PullOptions() { FetchOptions = new FetchOptions() { Prune = true } }; Commands.Pull(Repo, new Signature("In App", "*****@*****.**", new DateTimeOffset(DateTime.Now)), pulloptions); } }
private void GitHardReset() { using (var repo = new Repository(RepositoryPath())) { var options = new CheckoutOptions() { CheckoutModifiers = CheckoutModifiers.Force, OnCheckoutProgress = CheckoutProgressHandler, }; var currentCommit = repo.Head.Tip; repo.Reset(ResetMode.Hard, currentCommit, options); } }
private void btnFileUndo_Click(object sender, EventArgs e) { using (var repo = new Repository(fbdGitFolder.SelectedPath)) { var UndoList = new List <string>(); UndoList.Add(ofdGitFile.FileName); CheckoutOptions options = new CheckoutOptions { CheckoutModifiers = CheckoutModifiers.Force }; repo.CheckoutPaths(repo.Head.Name, UndoList, options); } }
public void DiscardFileChanges(string filePath) { if (string.IsNullOrEmpty(filePath)) { throw new ArgumentNullException(nameof(filePath)); } var options = new CheckoutOptions { CheckoutModifiers = CheckoutModifiers.Force }; _repository.CheckoutPaths(_repository.Head.FriendlyName, new[] { filePath }, options); }
public void GivenUriProvidedShouldOverrideSandbox() { var options = new CheckoutOptions { SecretKey = "sk_xxx", UseSandbox = true, Uri = "https://api.com" }; var configuration = options.CreateConfiguration(); configuration.Uri.ShouldBe(options.Uri); }
static void Update(List <string> updateArgs) { if (updateArgs.Count == 1) { var repoPath = updateArgs[0]; try { var repo = new Repository(repoPath); var options = new PullOptions(); options.FetchOptions = new FetchOptions(); // before updating, let's first // forced checkout to overwrite possible local changes // Re: https://github.com/eirannejad/pyRevit/issues/229 var checkoutOptions = new CheckoutOptions(); checkoutOptions.CheckoutModifiers = CheckoutModifiers.Force; Commands.Checkout(repo, repo.Head, checkoutOptions); // now let's pull from the tracked remote Console.WriteLine(String.Format("Updating repo at: {0}", repoPath)); var res = Commands.Pull(repo, new Signature("pyRevitCoreUpdater", commiterEmail, new DateTimeOffset(DateTime.Now)), options); // process the results and let user know if (res.Status == MergeStatus.FastForward) { Console.WriteLine("Successfully updated repo to HEAD"); } else if (res.Status == MergeStatus.UpToDate) { Console.WriteLine("Repo is already up to date."); } else if (res.Status == MergeStatus.Conflicts) { Console.WriteLine("There are conflicts to be resolved. Use the git tool to resolve conflicts."); } else { Console.WriteLine("Failed updating repo to HEAD"); } } catch (Exception ex) { Console.WriteLine(String.Format("EXCEPTION: {0}", ex.Message)); } } else { Console.WriteLine("Provide repo path to update."); } }
/// <summary> /// Discards local changes to a specific file and the file is updated with latest remote commit (origin/master) /// by checking out the specific file. /// </summary> /// <param name="org">Unique identifier of the organisation responsible for the app.</param> /// <param name="repository">The name of the repository</param> /// <param name="fileName">the name of the file</param> public void CheckoutLatestCommitForSpecificFile(string org, string repository, string fileName) { string localServiceRepoFolder = _settings.GetServicePath(org, repository, AuthenticationHelper.GetDeveloperUserName(_httpContextAccessor.HttpContext)); using (LibGit2Sharp.Repository repo = new LibGit2Sharp.Repository(localServiceRepoFolder)) { CheckoutOptions checkoutOptions = new CheckoutOptions { CheckoutModifiers = CheckoutModifiers.Force, }; repo.CheckoutPaths("origin/master", new[] { fileName }, checkoutOptions); } }
public void CanCreateConfiguration() { var options = new CheckoutOptions { SecretKey = "sk_xxx", PublicKey = "pk_xxx", UseSandbox = true }; var configuration = options.CreateConfiguration(); configuration.SecretKey.ShouldBe(options.SecretKey); configuration.PublicKey.ShouldBe(options.PublicKey); configuration.Uri.ShouldBe(CheckoutConfiguration.SandboxUri); }
private static void WalkIntoProjectHistory(string projectName, string localRepoPath , string projectPath, string branchName, Action <LibGit2Sharp.Commit, string, string, string> CheckoutHandler) { using (var repo = new Repository(localRepoPath)) { foreach (var commit in repo.Branches[branchName].Commits) { var checkoutOptions = new CheckoutOptions(); checkoutOptions.CheckoutModifiers = CheckoutModifiers.Force; repo.Checkout(commit, checkoutOptions); CheckoutHandler(commit, projectName, projectPath, branchName); } } }
public void CheckoutOptions_Serialize_PropertyNamesAsExpected() { // Arrange var checkoutOptions = new CheckoutOptions(); // Act var serializedObject = JsonConvert.SerializeObject(checkoutOptions); // Assert Assert.AreEqual(@"{ ""tax_tables"": null, ""shipping_methods"": null, ""rounding_policy"": null, ""no_shipping_method"": false }" .RemoveWhiteSpace(), serializedObject.RemoveWhiteSpace()); }
public void CanCancelCheckoutThroughNotifyCallback() { string repoPath = InitNewRepository(); using (var repo = new Repository(repoPath)) { string relativePath = "a.txt"; Touch(repo.Info.WorkingDirectory, relativePath, "Hello\n"); repo.Stage(relativePath); repo.Commit("Initial commit", Constants.Signature, Constants.Signature); // Create 2nd branch repo.CreateBranch("branch2"); // Update file in main Touch(repo.Info.WorkingDirectory, relativePath, "Hello from master!\n"); repo.Stage(relativePath); repo.Commit("2nd commit", Constants.Signature, Constants.Signature); // Checkout branch2 repo.Checkout("branch2"); // Update the context of a.txt - a.txt will then conflict between branch2 and master. Touch(repo.Info.WorkingDirectory, relativePath, "Hello From branch2!\n"); // Verify that we get called for the notify conflict cb string conflictPath = string.Empty; CheckoutOptions options = new CheckoutOptions() { OnCheckoutNotify = (path, flags) => { conflictPath = path; return false; }, CheckoutNotifyFlags = CheckoutNotifyFlags.Conflict, }; Assert.Throws<UserCancelledException>(() => repo.Checkout("master", options)); Assert.Equal(relativePath, conflictPath); } }
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); } }
public void CanCheckoutPathFromCurrentBranch(string fileName) { string repoPath = CloneStandardTestRepo(); using (var repo = new Repository(repoPath)) { // Set the working directory to the current head ResetAndCleanWorkingDirectory(repo); Assert.False(repo.RetrieveStatus().IsDirty); Touch(repo.Info.WorkingDirectory, fileName, "new text file"); Assert.True(repo.RetrieveStatus().IsDirty); var opts = new CheckoutOptions { CheckoutModifiers = CheckoutModifiers.Force }; repo.CheckoutPaths("HEAD", new[] { fileName }, opts); Assert.False(repo.RetrieveStatus().IsDirty); } }
public bool checkoutRevisionFile() { StarTeam.Item revFile; StarTeam.View currentView; if (getRevisionFile(m_strProject, m_strView, out currentView, out revFile)) { StarTeam.CheckoutOptions opt = new CheckoutOptions(currentView); opt.ForceCheckout = true; opt.SetCheckoutTip(); StarTeam.CheckoutManager coManager = currentView.CreateCheckoutManager(opt); m_revisionFile = (StarTeam.File)revFile; System.IO.FileInfo fileInfo = new System.IO.FileInfo(m_tempFilePath + @"\revision.txt"); try { coManager.CheckoutTo(m_revisionFile, fileInfo); StarTeam.File[] commitResults; commitResults = coManager.Commit(); if (commitResults[0].IsWorkingFileAvailable == true) { return true; } } catch (Exception ex) { MessageBox.Show(ex.Message, "StarTeam Checkout Error", MessageBoxButtons.OK); return false; } if (fileInfo.Exists) return true; } return false; }