protected override void DoFetch(IGitTfsRemote remote, bool stopOnFailMergeCommit) { if (InitialChangeset.HasValue) { remote.QuickFetch(InitialChangeset.Value); } else { remote.QuickFetch(); } _properties.InitialChangeset = remote.MaxChangesetId; _properties.PersistAllOverrides(); }
public void WhenANewValueIsSetAndPersistedInTheGitConfigFile_ThenThisValueAppearInTheGitConfigFile() { h.SetupGitRepo("repo", g => { g.Commit("A sample commit from TFS.\n\ngit-tfs-id: [http://server/tfs]$/MyProject/trunk;C1"); }); using (var repo = h.Repository("repo")) { var gitRepository = new GitRepository(repo.Info.WorkingDirectory, new Container(), null, new RemoteConfigConverter()); var configProperties = new ConfigProperties(new ConfigPropertyLoader(new Globals() { Repository = gitRepository })); configProperties.BatchSize = 7; configProperties.PersistAllOverrides(); Assert.Equal("7", h.GetConfig<string>("repo", GitTfsConstants.BatchSize)); } }
public void WhenANewValueIsSetAndPersistedInTheGitConfigFile_ThenThisValueAppearInTheGitConfigFile() { h.SetupGitRepo("repo", g => { g.Commit("A sample commit from TFS.\n\ngit-tfs-id: [http://server/tfs]$/MyProject/trunk;C1"); }); using (var repo = h.Repository("repo")) { var gitRepository = new GitRepository(repo.Info.WorkingDirectory, new Container(), null, new RemoteConfigConverter()); var configProperties = new ConfigProperties(new ConfigPropertyLoader(new Globals() { Repository = gitRepository })); configProperties.BatchSize = 7; configProperties.PersistAllOverrides(); Assert.Equal("7", h.GetConfig <string>("repo", GitTfsConstants.BatchSize)); } }
protected virtual void DoFetch(IGitTfsRemote remote, bool stopOnFailMergeCommit) { if (upToChangeSet != -1 && InitialChangeset.HasValue && InitialChangeset.Value > upToChangeSet) { throw new GitTfsException("error: up-to changeset # must not be less than the initial one"); } var bareBranch = string.IsNullOrEmpty(BareBranch) ? remote.Id : BareBranch; // It is possible that we have outdated refs/remotes/tfs/<id>. // E.g. someone already fetched changesets from TFS into another git repository and we've pulled it since // in that case tfs fetch will retrieve same changes again unnecessarily. To prevent it we will scan tree from HEAD and see if newer changesets from // TFS exists (by checking git-tfs-id mark in commit's comments). // The process is similar to bootstrapping. if (!ForceFetch) { if (!remote.Repository.IsBare) { remote.Repository.MoveTfsRefForwardIfNeeded(remote); } else { remote.Repository.MoveTfsRefForwardIfNeeded(remote, bareBranch); } } if (!ForceFetch && remote.Repository.IsBare && remote.Repository.HasRef(GitRepository.ShortToLocalName(bareBranch)) && remote.MaxCommitHash != remote.Repository.GetCommit(bareBranch).Sha) { throw new GitTfsException("error : fetch is not allowed when there is ahead commits!", new[] { "Remove ahead commits and retry", "use the --force option (ahead commits will be lost!)" }); } var metadataExportInitializer = new ExportMetadatasInitializer(_globals); bool shouldExport = ExportMetadatas || remote.Repository.GetConfig(GitTfsConstants.ExportMetadatasConfigKey) == "true"; if (ExportMetadatas) { metadataExportInitializer.InitializeConfig(remote.Repository, ExportMetadatasFile); } metadataExportInitializer.InitializeRemote(remote, shouldExport); try { if (InitialChangeset.HasValue) { _properties.InitialChangeset = InitialChangeset.Value; _properties.PersistAllOverrides(); remote.QuickFetch(InitialChangeset.Value, IgnoreRestrictedChangesets); remote.Fetch(stopOnFailMergeCommit, upToChangeSet); } else { remote.Fetch(stopOnFailMergeCommit, upToChangeSet); } } finally { Trace.WriteLine("Cleaning..."); remote.CleanupWorkspaceDirectory(); if (remote.Repository.IsBare) { remote.Repository.UpdateRef(GitRepository.ShortToLocalName(bareBranch), remote.MaxCommitHash); } } }
protected virtual void DoFetch(IGitTfsRemote remote, bool stopOnFailMergeCommit) { if (remote.Repository.IsBare) { if (string.IsNullOrEmpty(BareBranch)) { throw new GitTfsException("error : specify a git branch to fetch on..."); } if (!remote.Repository.HasRef(GitRepository.ShortToLocalName(BareBranch))) { throw new GitTfsException("error : the specified git branch doesn't exist..."); } if (!ForceFetch && remote.MaxCommitHash != remote.Repository.GetCommit(BareBranch).Sha) { throw new GitTfsException("error : fetch is not allowed when there is ahead commits!", new List <string>() { "Remove ahead commits and retry", "use the --force option (ahead commits will be lost!)" }); } } // It is possible that we have outdated refs/remotes/tfs/<id>. // E.g. someone already fetched changesets from TFS into another git repository and we've pulled it since // in that case tfs fetch will retrieve same changes again unnecessarily. To prevent it we will scan tree from HEAD and see if newer changesets from // TFS exists (by checking git-tfs-id mark in commit's comments). // The process is similar to bootstrapping. if (!ForceFetch) { globals.Repository.MoveTfsRefForwardIfNeeded(remote); } var exportMetadatasFilePath = Path.Combine(globals.GitDir, "git-tfs_workitem_mapping.txt"); if (ExportMetadatas) { remote.ExportMetadatas = true; remote.Repository.SetConfig(GitTfsConstants.ExportMetadatasConfigKey, "true"); if (!string.IsNullOrEmpty(ExportMetadatasFile)) { if (File.Exists(ExportMetadatasFile)) { File.Copy(ExportMetadatasFile, exportMetadatasFilePath); } else { throw new GitTfsException("error: the work items mapping file doesn't exist!"); } } } else { if (remote.Repository.GetConfig(GitTfsConstants.ExportMetadatasConfigKey) == "true") { remote.ExportMetadatas = true; } } remote.ExportWorkitemsMapping = new Dictionary <string, string>(); if (remote.ExportMetadatas && File.Exists(exportMetadatasFilePath)) { try { foreach (var lineRead in File.ReadAllLines(exportMetadatasFilePath)) { if (string.IsNullOrWhiteSpace(lineRead)) { continue; } var values = lineRead.Split('|'); var oldWorkitem = values[0].Trim(); if (!remote.ExportWorkitemsMapping.ContainsKey(oldWorkitem)) { remote.ExportWorkitemsMapping.Add(oldWorkitem, values[1].Trim()); } } } catch (Exception) { throw new GitTfsException("error: bad format of workitems mapping file! One line format should be: OldWorkItemId|NewWorkItemId"); } } try { if (InitialChangeset.HasValue) { properties.InitialChangeset = InitialChangeset.Value; properties.PersistAllOverrides(); remote.QuickFetch(InitialChangeset.Value); remote.Fetch(stopOnFailMergeCommit); } else { remote.Fetch(stopOnFailMergeCommit); } } finally { Trace.WriteLine("Cleaning..."); remote.CleanupWorkspaceDirectory(); if (remote.Repository.IsBare) { remote.Repository.UpdateRef(GitRepository.ShortToLocalName(BareBranch), remote.MaxCommitHash); } } }