Represents a branch in git. You can create and manipulate git branches and you can manipulate your working directory using Branch. Note, that new Branch( ...) does not create a new branch in the repository but rather constructs the object to manipulate an existing branch. To create a new branch use the static Branch.Create API.
Inheritance: Ref
Exemplo n.º 1
0
        public void Branch()
        {
            //Get the current branch
            var branch = repo.CurrentBranch;
            Console.WriteLine("Current branch is " + branch.Name);

            //Another way to get the current branch
            Branch head = repo.Head;

            // check if head == master
            Debug.Assert(head.Name == "master");

            //Get master branch
            var master = new Branch(repo, "master");
            Debug.Assert(master == repo.Get<Branch>("master"));

            //Get the abbreviated hash of the last commit on master
            Console.WriteLine(master.CurrentCommit.ShortHash);

            //Create a new branch
            var b = GitSharp.Branch.Create(repo, "foo");

            // Switching to our new branch
            b.Checkout();

            //Check if foo is current branch
            Debug.Assert(b.IsCurrent);

            //Reset the branch to a previous commit (hard or soft or mixed)
            master.Reset("HEAD^", ResetBehavior.Hard);
            master.Reset("49322bb17d3acc9146f98c97d078513228bbf3c0", ResetBehavior.Soft);
            master.Reset("master", ResetBehavior.Mixed);
        }
Exemplo n.º 2
0
		/// <summary>
		/// Merge the given branch into this Branch using the given merge strategy. 
		/// </summary>
		/// <param name="other"></param>
		/// <param name="strategy"></param>
		public MergeResult Merge(Branch other, MergeStrategy strategy)
		{
			return MergeCommand.Execute(new MergeOptions { Branches = new[] { this, other }, MergeStrategy = strategy });
		}
Exemplo n.º 3
0
 /// <summary>
 /// Check out the given branch
 /// </summary>
 /// <param name="branch"></param>
 public void CheckoutBranch(Branch branch)
 {
     Branch.SwitchTo(branch);
 }
Exemplo n.º 4
0
 public void Merge(Branch other)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 5
0
 /// <summary>
 /// Switch to the given branch
 /// </summary>
 /// <param name="branch"></param>
 public static void SwitchTo(Branch branch)
 {
     var db = branch._repo._internal_repo;
     db.WriteSymref(GitSharp.Core.Constants.HEAD, branch.Name);
     branch.Reset(ResetBehavior.Hard);
 }
 private bool TryGetBranch(string branchName, out Branch branch)
 {
     if (string.IsNullOrEmpty(branchName))
     {
         branch = _repository.Branches.Where(i => i.Value.Target.Hash == _repository.Head.Target.Hash).FirstOrDefault().Value;
         return true;
     }
     else
     {
         branch = new Branch(_repository, branchName);
         if (branch.IsBranch)
         {
             return true;
         }
     }
     branch = null;
     return false;
 }
        private Commit GetLastCommit(AbstractTreeNode item, Branch branch, Commit commit)
        {
            if (branch != null)
            {
                return item.GetLastCommit(branch);
            }
            else if (commit != null)
            {
                return item.GetLastCommitBefore(commit);
            }

            return null;
        }
 private RepositoryTreeDetailModel ConvertToRepositoryDetailModel(AbstractTreeNode item, Commit lastCommit, string treeName, Branch branch)
 {
     return new RepositoryTreeDetailModel
     {
         Name = item.Name,
         IsTree = item.IsTree,
         CommitDate = lastCommit != null ? new DateTime?(lastCommit.AuthorDate.LocalDateTime) : null,
         CommitMessage = lastCommit != null ? lastCommit.Message : null,
         Author = lastCommit != null ? lastCommit.Author.Name : null,
         Tree = String.IsNullOrEmpty(treeName) ? branch.Name : treeName,
         Path = item.Path,
         Hash = item.Hash,
     };
 }
 public Commit GetLastCommit(Branch branch)
 {
     return GetLastCommitBefore(branch.CurrentCommit);
 }