public int Run(string remoteId) { var retVal = _fetch.Run(remoteId); if (retVal == 0) { var remote = _globals.Repository.ReadTfsRemote(remoteId); if (_shouldRebase) { _globals.WarnOnGitVersion(); if (_globals.Repository.WorkingCopyHasUnstagedOrUncommitedChanges) { throw new GitTfsException("error: You have local changes; rebase-workflow only possible with clean working directory.") .WithRecommendation("Try 'git stash' to stash your local changes and pull again."); } _globals.Repository.CommandNoisy("rebase", "--preserve-merges", remote.RemoteRef); } else { _globals.Repository.Merge(remote.RemoteRef); } } return(retVal); }
public int DoPull(string remoteId) { ValidatePrefix(); remoteId = remoteId ?? string.Format(GitTfsConstants.RemoteSubtreeFormat, _globals.RemoteId ?? GitTfsConstants.DefaultRepositoryId, Prefix); IGitTfsRemote remote = _globals.Repository.ReadTfsRemote(remoteId); int result = _fetch.Run(remote.Id); if (result == GitTfsExitCodes.OK) { var p = Prefix.Replace(" ", "\\ "); _globals.Repository.CommandNoisy("subtree", "merge", "--prefix=" + p, remote.RemoteRef); result = GitTfsExitCodes.OK; } return(result); }
public int Run(string remoteId) { var retVal = _fetch.Run(remoteId); if (retVal == 0) { // TFS representations of repository paths do not have trailing slashes var tfsBranchPath = (remoteId ?? string.Empty).TrimEnd('/'); if (!tfsBranchPath.IsValidTfsPath()) { var remotes = _globals.Repository.GetLastParentTfsCommits(tfsBranchPath); if (!remotes.Any()) { throw new Exception("error: TFS branch not found: " + remoteId); } tfsBranchPath = remotes.First().Remote.TfsRepositoryPath; } var allRemotes = _globals.Repository.ReadAllTfsRemotes(); var remote = allRemotes.FirstOrDefault(r => String.Equals(r.TfsRepositoryPath, tfsBranchPath, StringComparison.OrdinalIgnoreCase)); if (_shouldRebase) { _globals.WarnOnGitVersion(); if (_globals.Repository.WorkingCopyHasUnstagedOrUncommitedChanges) { throw new GitTfsException("error: You have local changes; rebase-workflow only possible with clean working directory.") .WithRecommendation("Try 'git stash' to stash your local changes and pull again."); } _globals.Repository.CommandNoisy("rebase", "--preserve-merges", remote.RemoteRef); } else { _globals.Repository.Merge(remote.RemoteRef); } } return(retVal); }
public int Run(string tfsUrl, string tfsRepositoryPath, string gitRepositoryPath) { var currentDir = Environment.CurrentDirectory; var repositoryDirCreated = InitGitDir(gitRepositoryPath); // TFS string representations of repository paths do not end in trailing slashes if (tfsRepositoryPath != GitTfsConstants.TfsRoot) { tfsRepositoryPath = (tfsRepositoryPath ?? string.Empty).TrimEnd('/'); } int retVal = 0; try { if (repositoryDirCreated) { retVal = _init.Run(tfsUrl, tfsRepositoryPath, gitRepositoryPath); } else { try { Environment.CurrentDirectory = gitRepositoryPath; _globals.Repository = _init.GitHelper.MakeRepository(_globals.GitDir); } catch (Exception) { retVal = _init.Run(tfsUrl, tfsRepositoryPath, gitRepositoryPath); } } VerifyTfsPathToClone(tfsRepositoryPath); } catch { if (!_resumable) { try { // if we appeared to be inside repository dir when exception was thrown - we won't be able to delete it Environment.CurrentDirectory = currentDir; if (repositoryDirCreated) { Directory.Delete(gitRepositoryPath, recursive: true); } else { CleanDirectory(gitRepositoryPath); } } catch (IOException e) { // swallow IOException. Smth went wrong before this and we're much more interested in that error string msg = string.Format("warning: Something went wrong while cleaning file after internal error (See below).\n Can't clean up files because of IOException:\n{0}\n", e.IndentExceptionMessage()); Trace.WriteLine(msg); } catch (UnauthorizedAccessException e) { // swallow it also string msg = string.Format("warning: Something went wrong while cleaning file after internal error (See below).\n Can't clean up files because of UnauthorizedAccessException:\n{0}\n", e.IndentExceptionMessage()); Trace.WriteLine(msg); } } throw; } bool errorOccurs = false; try { if (tfsRepositoryPath == GitTfsConstants.TfsRoot) { _fetch.BranchStrategy = BranchStrategy.None; } _globals.Repository.SetConfig(GitTfsConstants.IgnoreBranches, _fetch.BranchStrategy == BranchStrategy.None); if (retVal == 0) { _fetch.Run(_fetch.BranchStrategy == BranchStrategy.All); _globals.Repository.GarbageCollect(); } if (_fetch.BranchStrategy == BranchStrategy.All && _initBranch != null) { _initBranch.CloneAllBranches = true; retVal = _initBranch.Run(); } } catch (GitTfsException) { errorOccurs = true; throw; } catch (Exception ex) { errorOccurs = true; throw new GitTfsException("error: a problem occurred when trying to clone the repository. Try to solve the problem described below.\nIn any case, after, try to continue using command `git tfs " + (_fetch.BranchStrategy == BranchStrategy.All ? "branch --init --all" : "fetch") + "`\n", ex); } finally { try { if (!_init.IsBare) { _globals.Repository.Merge(_globals.Repository.ReadTfsRemote(_globals.RemoteId).RemoteRef); } } catch (Exception) { //Swallow exception because the previously thrown exception is more important... if (!errorOccurs) { throw; } } } return(retVal); }