Ejemplo n.º 1
0
        private void OnCheckout(RepositoryItemViewModel item)
        {
            var repository = Repo;
            var branch     = (Branch)item.Value;

            if (!branch.IsRemote)
            {
                Commands.Checkout(repository, branch);
            }
            else
            {
                var origin = repository.Branches[$"origin/{branch}"];
                var local  = repository.CreateBranch(branch.CanonicalName, origin.Tip);
                repository.Branches.Update(local, x => x.TrackedBranch = origin.CanonicalName);
                Commands.Checkout(repository, local);
            }

            if (CheckedOutItem != null)
            {
                CheckedOutItem.IsCheckedOut = false;
            }

            item.IsCheckedOut = true;
            CheckedOutItem    = item;
        }
Ejemplo n.º 2
0
//        public IAsyncCommand Commit { get; set; }

        public NodeViewModel(RepositoryItemViewModel item, Repository repository, AccountModel account, Branch branch)
        {
            Item       = item;
            Repository = repository;
            Account    = account;
            Branch     = branch;

//            this.Listen(x => x.SelectedItemViewModel).Then(WhenSelectedItemViewModelChanged);

            var commits = new List <NodeItemViewModel>();

            if (repository.Head.CanonicalName == branch.CanonicalName)
            {
                var status = repository.RetrieveStatus(new StatusOptions()
                {
                });
                if (status.IsDirty)
                {
                    commits.Add(new ChangesNodeItemViewModel(status, account));
                }
            }

            commits.AddRange(branch.Commits.Select(x => new CommitNodeItemViewModel(x)));

            Items = commits.ToImmutableList();
//            Commit = this.CreateCommand(OnCommit, this.Listen(x => x.SelectedItemViewModel.IsCommittable));
        }
Ejemplo n.º 3
0
        public RepositoryViewModel(RepositoryModel repository)
        {
            Repository = repository;
            Repo       = new Repository(repository.Path);
            Checkout   = this.CreateCommand <RepositoryItemViewModel>(OnCheckout);

            Repo.DisposeWith(this);

            var items = new List <RepositoryItemViewModel>();

            var branchesNode = new RepositoryItemViewModel
            {
                Name       = "Branches",
                IsExpanded = true
            };

            items.Add(branchesNode);

            var branches = new List <RepositoryItemViewModel>();

            foreach (var branch in Repo.Branches.Where(x => !x.IsRemote))
            {
                var branchNode = new RepositoryItemViewModel
                {
                    Name  = branch.FriendlyName,
                    Value = branch
                };
                branches.Add(branchNode);

                if (branch.CanonicalName == Repo.Head.CanonicalName)
                {
                    branchNode.IsSelected   = true;
                    branchNode.IsCheckedOut = true;
                    SelectedItem            = branchNode;
                    CheckedOutItem          = branchNode;
                }
            }
            branchesNode.Children = branches.ToImmutableList();

            if (Repo.Branches.Any(x => x.IsRemote))
            {
                var remotesNode = new RepositoryItemViewModel
                {
                    Name = "Remotes"
                };

                var branchesByRemote = Repo.Branches.Where(x => x.IsRemote).ToLookup(x => x.RemoteName);
                var remotes          = new List <RepositoryItemViewModel>();

                foreach (var remote in Repo.Network.Remotes)
                {
                    var remoteNode = new RepositoryItemViewModel
                    {
                        Name = remote.Name
                    };
                    remotes.Add(remoteNode);

                    var remoteBranches = new List <RepositoryItemViewModel>();
                    foreach (var branch in branchesByRemote[remote.Name])
                    {
                        var branchNode = new RepositoryItemViewModel
                        {
                            Name  = branch.FriendlyName.ChopStart($"{remote.Name}/"),
                            Value = branch
                        };
                        remoteBranches.Add(branchNode);
                    }

                    remoteNode.Children = remoteBranches.ToImmutableList();
                }

                remotesNode.Children = remotes.ToImmutableList();
                items.Add(remotesNode);
            }

            Items = items.ToImmutableList();
        }