当前位置: 首页>>代码示例>>C#>>正文


C# Repository.Reset方法代码示例

本文整理汇总了C#中LibGit2Sharp.Repository.Reset方法的典型用法代码示例。如果您正苦于以下问题:C# Repository.Reset方法的具体用法?C# Repository.Reset怎么用?C# Repository.Reset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在LibGit2Sharp.Repository的用法示例。


在下文中一共展示了Repository.Reset方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CleanUpCurrentBranch

        private void CleanUpCurrentBranch(Repository repository)
        {
            repository.Reset(ResetOptions.Hard);
            repository.RemoveUntrackedFiles();

            repository.Head.Remote.Fetch();
        }
开发者ID:shinetechchina-tj,项目名称:VpnAddressPublisher,代码行数:7,代码来源:GitHubRawPageHoster.cs

示例2: RepositoryWrapper

 public RepositoryWrapper(Repository repo)
 {
     this.repo = repo;
     Head = async (i) => { return new BranchWrapper(repo, repo.Head); };
     Config = async (i) => { return repo.Config; };
     Index = async (i) => { return repo.Index; };
     Ignore = async (i) => { return repo.Ignore; };
     Network = async (i) => { return new NetworkWrapper(repo.Network); };
     ObjectDatabase = async (i) => { return repo.ObjectDatabase; };
     Refs = async (i) => { return repo.Refs; };
     Commits = async (i) => { return repo.Commits.Select(c => new CommitWrapper(c)); };
     Tags = async (i) => { return repo.Tags; };
     Stashes = async (i) => { return repo.Stashes; };
     Info = async (i) => { return repo.Info; };
     Diff = async (i) => { return repo.Diff; };
     Notes = async (i) => { return repo.Notes; };
     Submodules = async (i) => { return repo.Submodules; };
     Dispose = async (i) => { repo.Dispose(); return null; };
     Lookup = async (id) => {
         var found = repo.Lookup(id.ToString());
         if (found.GetType() == typeof(Commit)) {
             return new CommitWrapper((Commit)found);
         } else {
             return found;
         }
     };
     Branches = async (i) => repo.Branches.Select(b => new BranchWrapper(repo, b)).ToDictionary(b => b.Name);
     Reset = async (dynamic i) => {
         var modeName = ((string)i.mode).ToLower();
         ResetMode mode;
         if (modeName == "soft") {
             mode = ResetMode.Soft;
         } else if (modeName == "mixed") {
             mode = ResetMode.Mixed;
         } else {
             mode = ResetMode.Hard;
         }
         var committish = (string)i.committish;
         repo.Reset(mode, committish, null, null);
         return null;
     };
     Checkout = async (i) => {
         var branch = repo.Branches.First(b => b.Name == i.ToString());
         repo.Checkout(branch);
         return branch;
     };
 }
开发者ID:itsananderson,项目名称:edge-git,代码行数:47,代码来源:RepositoryWrapper.cs

示例3: CreateOrResetBranch

 public void CreateOrResetBranch(string branchName, string startPoint)
 {
     using (var repo = new LibGit2Sharp.Repository(RepositoryPath))
     {
         if (string.IsNullOrWhiteSpace(startPoint))
         {
             var branch = repo.GetOrCreateBranch(branchName);
             repo.Checkout(branch);
         }
         else
         {
             var commit = repo.Lookup<Commit>(startPoint);
             if (commit == null)
             {
                 throw new LibGit2Sharp.NotFoundException(string.Format("Start point \"{0}\" for reset was not found.", startPoint));
             }
             var branch = repo.GetOrCreateBranch(branchName);
             repo.Checkout(branch);
             repo.Reset(ResetMode.Hard, commit);
         }
     }
 }
开发者ID:sr457,项目名称:kudu,代码行数:22,代码来源:LibGit2SharpRepository.cs

示例4: Pull

        private static bool Pull(string directory)
        {
            try
            {
                using (var repo = new Repository(directory))
                {
                    Utility.Log(LogStatus.Info, "Pull", directory, Logs.MainLog);

                    repo.Reset(ResetMode.Hard);
                    repo.RemoveUntrackedFiles();
                    repo.Network.Pull(
                        new Signature(Config.Instance.Username, $"{Config.Instance.Username}@joduska.me", DateTimeOffset.Now),
                        new PullOptions
                            {
                                MergeOptions =
                                    new MergeOptions
                                        {
                                            FastForwardStrategy = FastForwardStrategy.Default,
                                            FileConflictStrategy = CheckoutFileConflictStrategy.Theirs,
                                            MergeFileFavor = MergeFileFavor.Theirs,
                                            CommitOnSuccess = true
                                        }
                            });

                    repo.Checkout(repo.Head, new CheckoutOptions { CheckoutModifiers = CheckoutModifiers.Force });

                    if (repo.Info.IsHeadDetached)
                    {
                        Utility.Log(LogStatus.Error, "Pull", "Update+Detached", Logs.MainLog);
                    }
                }

                return true;
            }
            catch (Exception e)
            {
                Utility.Log(LogStatus.Error, "Pull", e.Message, Logs.MainLog);
                return false;
            }
        }
开发者ID:VivianGit,项目名称:LeagueSharp.Loader,代码行数:40,代码来源:GitUpdater.cs

示例5: CreateDynamicRepository

        static string CreateDynamicRepository(string targetPath, Authentication authentication, string repositoryUrl, string targetBranch, bool noFetch)
        {
            Logger.WriteInfo(string.Format("Creating dynamic repository at '{0}'", targetPath));

            var gitDirectory = Path.Combine(targetPath, ".git");
            if (Directory.Exists(targetPath))
            {
                Logger.WriteInfo("Git repository already exists");
                GitHelper.NormalizeGitDirectory(gitDirectory, authentication, noFetch);
                Logger.WriteInfo(string.Format("Updating branch '{0}'", targetBranch));
                using (var repo = new Repository(targetPath))
                {
                    if (string.IsNullOrWhiteSpace(targetBranch))
                    {
                        throw new Exception("Dynamic Git repositories must have a target branch (/b)");
                    }
                    var targetGitBranch = repo.Branches[targetBranch];
                    var trackedBranch = targetGitBranch.TrackedBranch;
                    if (trackedBranch == null)
                        throw new InvalidOperationException(string.Format("Expecting {0} to have a remote tracking branch", targetBranch));

                    targetGitBranch.Checkout();
                    repo.Reset(ResetMode.Hard, trackedBranch.Tip);
                }

                return gitDirectory;
            }

            Credentials credentials = null;
            if (!string.IsNullOrWhiteSpace(authentication.Username) && !string.IsNullOrWhiteSpace(authentication.Password))
            {
                Logger.WriteInfo(string.Format("Setting up credentials using name '{0}'", authentication.Username));

                credentials = new UsernamePasswordCredentials
                {
                    Username = authentication.Username,
                    Password = authentication.Password
                };
            }

            Logger.WriteInfo(string.Format("Retrieving git info from url '{0}'", repositoryUrl));

            CloneRepository(repositoryUrl, gitDirectory, credentials);

            // Normalize (download branches) before using the branch
            GitHelper.NormalizeGitDirectory(gitDirectory, authentication, noFetch);

            using (var repository = new Repository(gitDirectory))
            {
                if (string.IsNullOrWhiteSpace(targetBranch))
                {
                    targetBranch = repository.Head.Name;
                }

                Reference newHead = null;

                var localReference = GetLocalReference(repository, targetBranch);
                if (localReference != null)
                {
                    newHead = localReference;
                }

                if (newHead == null)
                {
                    var remoteReference = GetRemoteReference(repository, targetBranch, repositoryUrl, authentication);
                    if (remoteReference != null)
                    {
                        repository.Network.Fetch(repositoryUrl, new[]
                            {
                                string.Format("{0}:{1}", remoteReference.CanonicalName, targetBranch)
                            });

                        newHead = repository.Refs[string.Format("refs/heads/{0}", targetBranch)];
                    }
                }

                if (newHead != null)
                {
                    Logger.WriteInfo(string.Format("Switching to branch '{0}'", targetBranch));

                    repository.Refs.UpdateTarget(repository.Refs.Head, newHead);
                }
            }

            return gitDirectory;
        }
开发者ID:nick4eva,项目名称:GitVersion,代码行数:86,代码来源:GitPreparer.cs

示例6: DownloadAddon

        private void DownloadAddon()
        {
            bool updated = false;
            bool cloned = false;

            if (!Directory.Exists(info.packedPath))
            {
                Directory.CreateDirectory(info.packedPath);
            }

            if (Directory.Exists(info.dlPath) && Repository.IsValid(info.dlPath))
            {
                using (Repository repo = new Repository(info.dlPath))
                {
                    RepositoryStatus status = repo.RetrieveStatus();

                    string commit = repo.Head.Tip.Id.Sha;

                    // reset local changes
                    if (status.IsDirty)
                    {
                        repo.Reset(ResetMode.Hard);
                    }

                    // fetch & merge from origin
                    repo.Network.Fetch(repo.Network.Remotes["origin"]);
                    repo.MergeFetchedRefs(new Signature("meldii", "[email protected]", new DateTimeOffset()), new MergeOptions());

                    // updated
                    if (!repo.Head.Tip.Id.Sha.Equals(commit))
                    {
                        updated = true;
                    }
                }
            }
            else
            {
                if (Directory.Exists(info.dlPath))
                {
                    ForceDeleteDirectory(info.dlPath);
                }

                CloneOptions co = new CloneOptions();
                co.BranchName = info.branch;
                Repository.Clone(info.url, info.dlPath, co);
                updated = true;
                cloned = true;
            }

            //Pack & ship it
            if (updated)
            {
                if (File.Exists(info.packedFile))
                {
                    File.Delete(info.packedFile);
                }

                ZipFile zip = new ZipFile(info.packedFile);
                foreach (string file in Directory.EnumerateFiles(info.dlPath, "*.*", SearchOption.AllDirectories))
                {
                    string rPath = file.Replace(info.dlPath, "").TrimStart(new char[] { '\\', '/' });
                    if (!rPath.StartsWith(".git", StringComparison.CurrentCultureIgnoreCase) && !rPath.Equals("README.md", StringComparison.CurrentCultureIgnoreCase))
                    {
                        string[] split = rPath.Split(new char[] { '\\', '/' });
                        string zipPath = split.Length == 1 ? "" : string.Join("\\", split, 0, split.Length - 1);

                        zip.AddFile(file, zipPath);
                    }

                }
                zip.Save();
            }

            if (cloned)
            {
                _Copy(Path.Combine(MeldiiSettings.Self.AddonLibaryPath, info.repoName) + ".zip", info.packedFile);
            }
        }
开发者ID:Jotaro31,项目名称:Meldii,代码行数:78,代码来源:GitRepository.cs

示例7: ResetBuildBranchToTag

        private static void ResetBuildBranchToTag(Repository repository, ILogger logger, VersionLabel versionLabel, Tag versionLabelTag)
        {
            var buildBranch =
                (from branch in repository.Branches
                 where branch.FriendlyName == BuildBranchName
                 select branch).SingleOrDefault();
            if (buildBranch == null)
            {
                logger.Log($"The branch '{BuildBranchName}' doesn't exist: creating it and resetting it to '{versionLabel.Raw}'");

                // If the build branch doesn't exist, create it and check it out
                buildBranch = repository.CreateBranch(BuildBranchName, versionLabelTag.Target as Commit);
                repository.Checkout(buildBranch, new CheckoutOptions() { CheckoutModifiers = CheckoutModifiers.Force });
            }
            else
            {
                logger.Log($"The branch '{BuildBranchName}' already exists: checking it out and resetting it to '{versionLabel.Raw}'");

                // If the build branch exists, check it out and do an hard reset
                repository.Checkout(buildBranch, new CheckoutOptions() { CheckoutModifiers = CheckoutModifiers.Force });
                repository.Reset(ResetMode.Hard, versionLabelTag.Target as Commit);
            }
        }
开发者ID:Bhaal22,项目名称:Msbuild.GitCloneTask,代码行数:23,代码来源:VersionResolver.cs

示例8: HandleFixedVersioning_Commit

        protected virtual void HandleFixedVersioning_Commit(Dependency dependency, Repository otherRepository)
        {
            var dependencyCommit = otherRepository.Lookup(dependency.Commit) as Commit;
            if (dependencyCommit == null)
                throw new InvalidOperationException($"Dependency {dependency}: Commit '{dependency.Commit}' is invalid");

            var buildBranch =
                (from branch in otherRepository.Branches
                where branch.FriendlyName == VersionResolver.BuildBranchName
                select branch).SingleOrDefault();

            if (buildBranch == null)
            {
                Log($"Dependency {dependency}: fixed versioning: '{VersionResolver.BuildBranchName}' branch not found => creating it at Commit = '{dependency.Commit}'...");
                otherRepository.CreateBranch(VersionResolver.BuildBranchName, dependency.Commit);
            }
            else
            {
                Log($"Dependency {dependency}: fixed versioning: '{VersionResolver.BuildBranchName}' branch found => checking it out and hard resetting it to Commit = '{dependency.Commit}'...");
                otherRepository.Checkout(buildBranch, new CheckoutOptions() { CheckoutModifiers = CheckoutModifiers.Force });
                otherRepository.Reset(ResetMode.Hard, dependencyCommit);
            }
        }
开发者ID:Bhaal22,项目名称:Msbuild.GitCloneTask,代码行数:23,代码来源:GitCloneTask.cs

示例9: HardReset

 public void HardReset()
 {
     using (var repo = new Repository(_settings.Workspace))
     {
         repo.Reset(ResetMode.Hard);
     }
 }
开发者ID:ericcastoldi,项目名称:Stag,代码行数:7,代码来源:Git.cs

示例10: TryUpdateRepository

        public void TryUpdateRepository(HttpContext context)
        {
            var targetWebRoot = GetTargetWebRoot();
            if (String.IsNullOrEmpty(targetWebRoot))
            {
                SendResponse(context, 404, "No web root target.");
                return;
            }

            if (!Repository.IsValid(targetWebRoot))
            {
                SendResponse(context, 404, "No repository configured at: {0}", targetWebRoot);
                return;
            }

            string snapshotId = null;
            string siteId = null;
            var handlers = GetProgressHandlers(context);
            using (var repo = new Repository(targetWebRoot))
            {
                repo.Fetch("origin", onCompletion: handlers.CompletionHandler,
                    onTransferProgress: handlers.TransferProgressHandler,
                    onProgress: msg => SendProgress(context, msg));
                repo.Reset(ResetOptions.Hard, "origin/master");
                snapshotId = GetLatestSnapShotId(repo);
                siteId = HostingEnvironment.ApplicationHost.GetSiteID();
                var url = GetScmUri(repo);
                Protocol.KuduCalfCmdUpdateSiteStatus(url, siteId, snapshotId);
            }
            SendResponse(context, 200, "Updated root {0} of subscriber {1} to {2}", targetWebRoot, siteId, snapshotId);
        }
开发者ID:projectkudu,项目名称:KuduCalf,代码行数:31,代码来源:KuduCalfWeb.ashx.cs


注:本文中的LibGit2Sharp.Repository.Reset方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。