private void AssertRepositoryViewModel(RepositoryViewModel vm, string type, string name, string path)
 {
     Assert.That(vm, Is.Not.Null);
     Assert.That(vm.Type, Is.EqualTo(type));
     Assert.That(vm.Name, Is.EqualTo(name));
     Assert.That(vm.Path, Is.EqualTo(path));
 }
        public void HideBranch(RepositoryViewModel repositoryViewModel, Branch branch)
        {
            List <Branch> currentlyShownBranches = repositoryViewModel.SpecifiedBranches.ToList();

            bool isShowing = currentlyShownBranches.Contains(branch);

            if (isShowing)
            {
                IEnumerable <Branch> closingBranches = GetBranchAndDescendants(
                    currentlyShownBranches, branch);

                if (branch.IsLocalPart)
                {
                    closingBranches = closingBranches.Concat(GetBranchAndDescendants(
                                                                 currentlyShownBranches,
                                                                 currentlyShownBranches.First(b => b.LocalSubBranch == branch)));
                    ;
                }

                currentlyShownBranches.RemoveAll(b => b.Name != BranchName.Master && closingBranches.Contains(b));

                repositoryViewModel.SpecifiedBranches = currentlyShownBranches;
                UpdateViewModel(repositoryViewModel);

                repositoryViewModel.VirtualItemsSource.DataChanged(repositoryViewModel.Width);
            }
        }
Ejemplo n.º 3
0
        public RepositoryViewController(string username, string slug, string name)
        {
            Title     = name;
            ViewModel = new RepositoryViewModel(username, slug);

            _header = new HeaderView(View.Bounds.Width)
            {
                Title = name, ShadowImage = false
            };

            NavigationItem.RightBarButtonItem         = new UIBarButtonItem(NavigationButton.Create(Theme.CurrentTheme.GearButton, ShowExtraMenu));
            NavigationItem.RightBarButtonItem.Enabled = false;

            ViewModel.Bind(x => x.Repository, x => {
                NavigationItem.RightBarButtonItem.Enabled = true;
                Render(x);
            });

            ViewModel.Bind(x => x.Readme, () => {
                // Not very efficient but it'll work for now.
                if (ViewModel.Repository != null)
                {
                    Render(ViewModel.Repository);
                }
            });
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Obtem um repositorio pelo ID
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public RepositoryViewModel GetById(int id)
        {
            var repository = new RepositoryViewModel();

            try
            {
                var request = WebRequest.CreateHttp(Constants.URL_REPOSITORY_BY_ID.Replace("{ID}", id.ToString()));
                request.Method    = Constants.METHOD_GET;
                request.UserAgent = Constants.MY_USER;
                using (var resposta = request.GetResponse())
                {
                    var          streamDados = resposta.GetResponseStream();
                    StreamReader reader      = new StreamReader(streamDados);
                    object       objResponse = reader.ReadToEnd();
                    repository = JsonConvert.DeserializeObject <RepositoryViewModel>(objResponse.ToString());
                    streamDados.Close();
                    resposta.Close();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            return(repository);
        }
Ejemplo n.º 5
0
        public RepositoryPage()
        {
            InitializeComponent();
            repVm = new RepositoryViewModel();

            BindingContext = repVm;

            repVm.GetRepoCommand.Execute(null);

            lstRepository.ItemsSource = repVm.Repo;
            tempdata = repVm.Repo;
            lstRepository.ItemAppearing += (sender, e) =>
            {
                if (repVm.IsBusy || repVm.Repo.Count == 0)
                {
                    return;
                }

                //hit bottom!
                if ((Models.Repository)e.Item == repVm.Repo[repVm.Repo.Count - 1])
                {
                    repVm.GetRepoCommand.Execute(null);
                }
            };

            lstRepository.ItemSelected += LstRepository_ItemSelected;
        }
Ejemplo n.º 6
0
        public IActionResult SavePost(RepositoryViewModel model)
        {
            if (ModelState.IsValid)
            {
                ICmsManager manager = new CmsManager();
                IRepository repo;

                if (model.IsItANewRepository())
                {
                    repo = model.MapToModel(new Repository());
                    model.ApplyTemplate(repo);
                    manager.AddRepository(repo);
                }
                else
                {
                    try
                    {
                        int repoindex = manager.GetIndexById(model.Id.Value);
                        repo = manager.Data.Repositories[repoindex];
                        model.MapToModel(repo);
                    }
                    catch (InvalidOperationException)
                    {
                        throw new Exception("The content definition not found");
                    }
                }
                manager.Save();
                return(Redirect("/fcmsmanager/" + ViewModelHelpers.GetRepositoryBaseUrl(repo)));
            }

            return(View("Edit", new RepositoryViewModel()));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Adiciona um novo repositorio favorito
        /// </summary>
        /// <param name="repositoryFavorite"></param>
        /// <returns></returns>
        public bool CreateFavorite(RepositoryViewModel repositoryFavorite)
        {
            var  json      = new JavaScriptSerializer().Serialize(repositoryFavorite) + ",";
            bool resultado = true;

            try
            {
                string path = Path.GetTempPath();

                path = Path.Combine(path, "Favorites.txt");
                if (!File.Exists(path))
                {
                    using (StreamWriter sw = File.CreateText(path))
                    {
                        sw.WriteLine(json);
                    }
                }
                else
                {
                    using (StreamWriter sw = File.AppendText(path))
                    {
                        sw.WriteLine(json);
                    }
                }
            }
            catch (Exception e)
            {
                resultado = false;
                Console.WriteLine(e.Message);
            }

            return(resultado);
        }
Ejemplo n.º 8
0
        public IActionResult Index()
        {
            var repositories = (from repository in context.Repository
                                select repository).ToList();

            var repositoryViewModels = new List <RepositoryViewModel>();

            foreach (var repository in repositories)
            {
                var repositoryViewModel = new RepositoryViewModel {
                    Name = repository.Name
                };

                var metrics = (from metric in context.Metric
                               join measurement in context.Measurement on metric.Id equals measurement.MetricId
                               where measurement.RepositoryId == repository.Id
                               select metric.Name).Distinct().ToList();

                foreach (var metric in metrics)
                {
                    repositoryViewModel.Badges.Add(new BadgeViewModel
                    {
                        Name = metric,
                        Url  = Url.Action("Index", "Badge", new { repositoryName = repository.Name, metricName = metric })
                    });
                }

                repositoryViewModels.Add(repositoryViewModel);
            }

            return(View(repositoryViewModels));
        }
Ejemplo n.º 9
0
        internal MainWindowViewModel(
            WorkingFolder workingFolder,
            WindowOwner owner,
            IRepositoryCommands repositoryCommands,
            IRemoteService remoteService,
            ICommitsService commitsService,
            ILatestVersionService latestVersionService,
            IStartInstanceService startInstanceService,
            IRecentReposService recentReposService,
            IGitInfoService gitInfoService,
            IMessage message,
            IMainWindowService mainWindowService,
            MainWindowIpcService mainWindowIpcService,
            RepositoryViewModel repositoryViewModel)
        {
            this.workingFolder        = workingFolder;
            this.owner                = owner;
            this.repositoryCommands   = repositoryCommands;
            this.remoteService        = remoteService;
            this.commitsService       = commitsService;
            this.startInstanceService = startInstanceService;
            this.recentReposService   = recentReposService;
            this.gitInfoService       = gitInfoService;
            this.message              = message;
            this.mainWindowService    = mainWindowService;
            this.mainWindowIpcService = mainWindowIpcService;

            RepositoryViewModel = repositoryViewModel;

            workingFolder.OnChange += (s, e) => Notify(nameof(WorkingFolder));
            latestVersionService.OnNewVersionAvailable += (s, e) => IsNewVersionVisible = true;
            latestVersionService.StartCheckForLatestVersion();
            IsRepoView = true;
        }
Ejemplo n.º 10
0
        public void ObservableRepository_gets_ViewModel_of_Model()
        {
            // ARRANGE

            var model      = new Tag();
            var repository = this.mocks.Create <ITagRepository>();

            repository
            .Setup(r => r.FindAll())
            .Returns(model.Yield());

            var observableRepository = new RepositoryViewModel <TagViewModel, Tag>(repository.Object, m => new TagViewModel(m));

            observableRepository.FillAll();

            // ACT

            var result = observableRepository.GetViewModel(new Tag {
                Id = model.Id
            });

            // ASSERT

            Assert.Same(observableRepository.Single(), result);
        }
Ejemplo n.º 11
0
        public void ObservableRepository_deletes_removed_items()
        {
            // ARRANGE

            var model      = new Tag();
            var repository = this.mocks.Create <ITagRepository>();

            repository
            .Setup(r => r.Upsert(model))
            .Returns(model);
            repository
            .Setup(r => r.Delete(model.Id))
            .Returns(true);

            var observableRepository = new RepositoryViewModel <TagViewModel, Tag>(repository.Object, m => new TagViewModel(m));
            var viewModel            = new TagViewModel(model);

            observableRepository.Add(viewModel);

            // ACT

            observableRepository.Remove(viewModel);

            // ASSERT

            Assert.Empty(observableRepository);
        }
Ejemplo n.º 12
0
        public IActionResult SavePost(RepositoryViewModel model)
        {
            if (ModelState.IsValid)
            {
                ICmsManager manager = CmsManager.Load();

                if (model.IsItANewRepository())
                {
                    var newRrepository = model.MapToModel(new Repository());
                    manager.AddRepository(newRrepository);
                }
                else
                {
                    try
                    {
                        int repoindex = manager.GetIndexById(model.Id.Value);
                        model.MapToModel(manager.Repositories[repoindex]);
                    }
                    catch (InvalidOperationException)
                    {
                        throw new Exception("The content definition not found");
                    }
                }
                manager.Save();
                return(Redirect("/fcmsmanager/repository"));
            }

            return(View("Edit", new RepositoryViewModel()));
        }
Ejemplo n.º 13
0
        protected override void OnViewModelChanged(RepositoryViewModel oldModel, RepositoryViewModel newModel)
        {
            base.OnViewModelChanged(oldModel, newModel);

            newModel.Listen(x => x.SelectedItem).Then(OnSelectedItemChanged);

            OnSelectedItemChanged();
        }
Ejemplo n.º 14
0
 public RepositoryViewController(string owner, string repository)
     : this()
 {
     ViewModel = new RepositoryViewModel();
     ViewModel.Init(new RepositoryViewModel.NavObject {
         Username = owner, Repository = repository
     });
 }
        private void UpdateMerges(
            IEnumerable <Branch> sourceBranches,
            RepositoryViewModel repositoryViewModel)
        {
            var branches    = repositoryViewModel.Branches;
            var commits     = repositoryViewModel.Commits;
            var commitsById = repositoryViewModel.CommitsById;
            var merges      = repositoryViewModel.Merges;

            var mergePoints = commits
                              .Where(c => c.IsMergePoint && c.Commit.HasSecondParent && sourceBranches.Contains(c.Commit.SecondParent.Branch))
                              .ToList();

            var branchStarts = branches.Where(b =>
                                              b.Branch.HasParentBranch && sourceBranches.Contains(b.Branch.ParentCommit.Branch))
                               .Select(b => b.Branch.FirstCommit)
                               .ToList();

            bool isMergeInProgress =
                repositoryMgr.Repository.Status.IsMerging &&
                branches.Any(b => b.Branch == repositoryMgr.Repository.CurrentBranch) &&
                repositoryViewModel.MergingBranch != null &&
                branches.Any(b => b.Branch.Id == repositoryViewModel.MergingBranch.Id) &&
                repositoryMgr.Repository.UnComitted != null;

            int mergeCount = mergePoints.Count + branchStarts.Count + (isMergeInProgress ? 1 : 0);

            SetNumberOfItems(merges, mergeCount, _ => new MergeViewModel());

            int index = 0;

            foreach (CommitViewModel childCommit in mergePoints)
            {
                CommitViewModel parentCommit = commitsById[childCommit.Commit.SecondParent.Id];

                MergeViewModel merge = merges[index++];

                SetMerge(merge, branches, childCommit, parentCommit);
            }

            foreach (Commit childCommit in branchStarts)
            {
                CommitViewModel parentCommit = commitsById[childCommit.FirstParent.Id];

                MergeViewModel merge = merges[index++];

                SetMerge(merge, branches, commitsById[childCommit.Id], parentCommit, false);
            }

            if (isMergeInProgress)
            {
                CommitId        mergeSourceId = new CommitId(repositoryViewModel.MergingCommitSha);
                CommitViewModel parentCommit  = commitsById[mergeSourceId];
                MergeViewModel  merge         = merges[index++];
                SetMerge(merge, branches, commitsById[parentCommit.Commit.Repository.UnComitted.Id], parentCommit);
            }
        }
Ejemplo n.º 16
0
        // GET: Repository
        public async Task <ActionResult> Index(long id, string name, string referrer = "edit", string reason = "",
                                               string user = "")
        {
            if (Session["OAuthToken"] is string accessToken)
            {
                // This allows the client to make requests to the GitHub API on the user's behalf
                // without ever having the user's OAuth credentials.
                Client.Credentials = new Credentials(accessToken);
            }
            else
            {
                return(Redirect(GetOauthLoginUrl()));
            }

            try
            {
                if (string.IsNullOrEmpty(user))
                {
                    var githubUser = await Client.User.Current();

                    user = githubUser.Login;
                }

                IReadOnlyList <RepositoryContributor> contributors =
                    await Client.Repository.GetAllContributors(RepoForTestingOwner, RepoForTesting);

                if (contributors.All(c => c.Login != user))
                {
                    referrer = "not_authorized";
                    reason   =
                        $"{user} is not a contributor for {RepoForTesting} repository. Please send request to " +
                        $"{RepoForTestingOwner} at <a href=" +
                        $"'https://github.com/{RepoForTestingOwner}/{RepoForTesting}/graphs/contributors'>" +
                        $"https://github.com/{RepoForTestingOwner}/{RepoForTesting}/graphs/contributors</a> ";
                }

                var originContent = await GitHubHelper.GetOriginContentForRepo(Client,
                                                                               RepoForTesting,
                                                                               RepoForTestingOwner,
                                                                               FileNameForTesting);

                var model = new RepositoryViewModel(id, name,
                                                    new List <RepositoryFileViewModel> {
                    originContent
                }, referrer, reason, user);

                return(View(model));
            }
            catch (AuthorizationException)
            {
                // Either the accessToken is null or it's invalid. This redirects
                // to the GitHub OAuth login page. That page will redirect back to the
                // Authorize action.
                return(Redirect(GetOauthLoginUrl()));
            }
        }
        public void TestNameGetter_ReturnsModelName()
        {
            const string testName   = "Any name here";
            var          repository = Substitute.For <ITfGitRepository>();

            repository.Name.Returns(testName);
            var systemUnderTest = new RepositoryViewModel(repository);

            Assert.That(systemUnderTest.Name, Is.EqualTo(testName));
        }
Ejemplo n.º 18
0
        public RepositoryViewModel MapperToViewModel(RepositoryModel repositoryModel)
        {
            RepositoryViewModel repositoryViewModel = new RepositoryViewModel
            {
                TotalCount   = repositoryModel.TotalCount,
                Repositories = repositoryModel.Repositories
            };

            return(repositoryViewModel);
        }
        private void UpdateCommits(
            IReadOnlyList <Commit> sourceCommits,
            RepositoryViewModel repositoryViewModel)
        {
            List <CommitViewModel> commits = repositoryViewModel.Commits;
            var commitsById = repositoryViewModel.CommitsById;

            SetNumberOfItems(
                commits,
                sourceCommits.Count,
                i => new CommitViewModel(
                    branchService, diffService, themeService, repositoryCommands, commitsService, tagService));

            commitsById.Clear();
            int graphWidth = repositoryViewModel.GraphWidth;

            int index = 0;

            foreach (Commit commit in sourceCommits)
            {
                CommitViewModel commitViewModel = commits[index];
                commitsById[commit.Id] = commitViewModel;

                commitViewModel.Commit   = commit;
                commitViewModel.RowIndex = index++;

                commitViewModel.BranchViewModel = GetBranchViewModel(repositoryViewModel, commit.Branch);

                int x = commitViewModel.BranchViewModel?.X ?? -20;
                int y = Converters.ToY(commitViewModel.RowIndex);

                commitViewModel.XPoint = commitViewModel.IsEndPoint
                                        ? 3 + x
                                        : commitViewModel.IsMergePoint ? 2 + x : 4 + x;

                commitViewModel.GraphWidth = graphWidth;
                commitViewModel.Width      = repositoryViewModel.Width - 35;

                commitViewModel.Rect = new Rect(0, y, commitViewModel.Width, CommitHeight);

                commitViewModel.Brush      = themeService.GetBranchBrush(commit.Branch);
                commitViewModel.BrushInner = commitViewModel.Brush;
                commitViewModel.SetNormal(GetSubjectBrush(commit));
                commitViewModel.BranchToolTip = GetBranchToolTip(commit.Branch);

                if (commitViewModel.IsMergePoint &&
                    !commit.HasSecondParent &&
                    (commit == commit.Branch.TipCommit || commit == commit.Branch.FirstCommit))
                {
                    commitViewModel.BrushInner = themeService.Theme.GetDarkerBrush(commitViewModel.Brush);
                }

                commitViewModel.NotifyAll();
            }
        }
Ejemplo n.º 20
0
        //view the bookmarked repositories by iterating over the session keys
        public ActionResult viewBookmarked()
        {
            List <RepositoryViewModel> repList = new List <RepositoryViewModel>();

            for (int i = 0; i < Session.Contents.Count; i++)
            {
                RepositoryViewModel rep = (RepositoryViewModel)Session[Session.Keys[i]];
                repList.Add(rep);
            }
            return(View(repList));
        }
Ejemplo n.º 21
0
 public RepositoryViewController(
     string owner,
     string repositoryName,
     Octokit.Repository repository = null)
     : this()
 {
     ViewModel = new RepositoryViewModel();
     ViewModel.Init(new RepositoryViewModel.NavObject {
         Username = owner, Repository = repositoryName
     });
     ViewModel.Repository = repository;
 }
Ejemplo n.º 22
0
        public ActionResult Index(
            string path)
        {
            var repository = new GitVersioningSystem(path);

            var model = new RepositoryViewModel {
                RepositoryPath = repository.RootPath,
                Branches       = repository.GetBranches(),
                ReadMe         = repository.FindAndReadFile(_isReadMe)
            };

            return(View(model));
        }
Ejemplo n.º 23
0
        //bookmark repository by save it in current session
        public ActionResult BookMark(int id, string avatar, string name)
        {
            RepositoryViewModel repoVm = new RepositoryViewModel();

            repoVm.id     = id;
            repoVm.name   = name;
            repoVm.avatar = avatar;
            if (Session[name] == null)
            {
                Session[name] = repoVm;
            }
            return(View(repoVm));
        }
        private BranchViewModel GetBranchViewModel(
            RepositoryViewModel repositoryViewModel, Branch branch)
        {
            foreach (BranchViewModel current in repositoryViewModel.Branches)
            {
                if (current.Branch == branch)
                {
                    return(current);
                }
            }

            return(null);
        }
        private void UpdateViewModel(
            RepositoryViewModel repositoryViewModel,
            IReadOnlyList <Branch> branches,
            List <Commit> commits)
        {
            UpdateBranches(branches, commits, repositoryViewModel);

            UpdateCommits(commits, repositoryViewModel);

            UpdateMerges(branches, repositoryViewModel);

            repositoryViewModel.SpecifiedBranches    = branches.ToList();
            repositoryViewModel.SpecifiedBranchNames = new BranchName[0];
        }
Ejemplo n.º 26
0
 public RepositoryViewModel MapRepoDTOToRepoViewModel(Repository repo, RepositoryViewModel repoVM)
 {
     if (repoVM == null)
     {
         repoVM = new RepositoryViewModel();
     }
     repoVM.Name            = repo.name;
     repoVM.Description     = !string.IsNullOrWhiteSpace(repo.description) ? repo.description : Constants.NO_INFO_STRING;
     repoVM.Repo_URL        = repo.html_url;
     repoVM.Language        = repo.language;
     repoVM.StargazersCount = repo.stargazers_count;
     repoVM.ForksCount      = repo.forks_count;
     return(repoVM);
 }
Ejemplo n.º 27
0
        public async Task CanSelectBranches()
        {
            var schedulers            = new TestSchedulers();
            var repositoryFactory     = new SimpleRepositoryFactoryMock();
            var repositoryDescription = new RepositoryDescription("Name", "PATH TO REPO");
            var res = await RepositoryViewModel.Create(
                schedulers,
                CancellationToken.None,
                repositoryFactory,
                new TestFileSystem(),
                repositoryDescription,
                Observable.Return(new CompareOptions()));

            Assert.IsTrue(res.Is <RepositoryViewModel>());
            using var repo = res.Get <RepositoryViewModel>();
            var refs = repo.References.Value;

            Assert.IsNotNull(refs);
            Assert.AreEqual(2, refs !.Branches.Refs.Count);
            var master = refs.Branches.Refs.Where(b => b.FriendlyName == "master").FirstOrDefault()
                         ?? throw new InvalidOperationException("Branch master not found.");
            var work = refs.Branches.Refs.Where(b => b.FriendlyName == "work").FirstOrDefault()
                       ?? throw new InvalidOperationException("Branch work not found.");

            Assert.IsTrue(master.Selected.Value, "Branch master (HEAD) should be selected.");
            Assert.IsFalse(work.Selected.Value, "Branch work should not be selected.");
            Assert.IsTrue(repo.Graph.LogGraphNodes.Value.VariantIndex == 0);
            var logGraphNodes = repo.Graph.LogGraphNodes.Value.First;

            using var _1 = repo.Graph.LogGraphNodes
                           .Subscribe(nodes => logGraphNodes = nodes.VariantIndex == 0
                        ? nodes.First : throw new InvalidOperationException(nodes.Second.Message));
            IList <RefSelection>?selectedBranches = null;

            refs         = repo.References.Value;
            using var _2 = refs !.Branches.SelectedRefs
                           .Subscribe(sb => selectedBranches = sb);
            Assert.AreEqual(1, selectedBranches.Where(b => b.Selected).Count());
            Assert.AreEqual(7, logGraphNodes.Count); // The mock doesn't filter unreachable commits.
            var nodesWithBranch = logGraphNodes.Where(c => c.Branches.Any());

            Assert.AreEqual(2, nodesWithBranch.Count());
            Assert.AreEqual("master", nodesWithBranch.First().Branches.First().FirendlyName);
            work.SelectCommand.Execute(true);
            Assert.AreEqual(2, logGraphNodes.Where(c => c.Branches.Any()).Count());
            _ = selectedBranches ?? throw new InvalidOperationException("Selected branches were not set.");
            Assert.AreEqual(2, selectedBranches.Where(b => b.Selected).Count());
        }
Ejemplo n.º 28
0
        public void CreateRepository(RepositoryViewModel repositoryViewModel, string userId)
        {
            var owner     = this.db.Users.FirstOrDefault(x => x.Id == userId);
            var ownerName = owner.Username;

            var repository = new Repository
            {
                Name      = repositoryViewModel.Name,
                CreatedOn = DateTime.UtcNow,
                IsPublic  = repositoryViewModel.RepositoryType == "Public",
                OwnerId   = userId,
            };

            this.db.Repositories.Add(repository);
            this.db.SaveChanges();
        }
Ejemplo n.º 29
0
 public Repository(RepositoryViewModel repository)
 {
     this.ID          = repository.ID;
     this.OriginalID  = repository.OriginalID;
     this.Name        = repository.Name;
     this.URL         = repository.URL;
     this.Description = repository.Description;
     this.Language    = repository.Language;
     this.Stars       = repository.Stars;
     this.Private     = repository.Private;
     this.OwnerLogin  = repository.OwnerLogin;
     this.Created     = repository.Created;
     this.IssuesCount = repository.IssuesCount;
     this.ForksCount  = repository.ForksCount;
     this.OriginalID  = repository.OriginalID;
 }
Ejemplo n.º 30
0
        public async Task CanCreateRepositoryViewModel()
        {
            var schedulers            = new TestSchedulers();
            var repositoryFactory     = new TestRepositoryFactory();
            var repositoryDescription = new RepositoryDescription("Name", "PATH TO REPO");
            var res = await RepositoryViewModel.Create(
                schedulers,
                CancellationToken.None,
                repositoryFactory,
                new TestFileSystem(),
                repositoryDescription,
                Observable.Return(new CompareOptions()));

            Assert.IsTrue(res.Is <RepositoryViewModel>());
            using var repo = res.Get <RepositoryViewModel>();
            Assert.AreEqual(repositoryDescription, repo.RepositoryDescription);
        }
Ejemplo n.º 31
0
        /// <summary>
        /// A helper method for opening a new repository for the given path.
        /// 
        /// This will bring up a question regarding the name to use and initialize the repository view model and load it up in the tab control.
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        private bool OpenNewRepository(string path)
        {
            var repository = new RepositoryViewModel
            {
                NotOpened = false,
                RepositoryFullPath = path
            };

            // Try loading the repository information and see if it worked.
            var result = repository.Init();
            if (result)
            {
                var mainWindowViewModel = (MainWindowViewModel) Application.Current.MainWindow.DataContext;

                // Ask the user for the Name.
                var nameDialog = new PromptDialog
                {
                    ResponseText = repository.RepositoryFullPath.Split(System.IO.Path.DirectorySeparatorChar).Last(),
                    Message = "Give a name for this repository:",
                    Title = "Information needed"
                };

                repository.Name = nameDialog.ShowDialog() == true ? nameDialog.ResponseText : repository.RepositoryFullPath;

                // Open the repository and display it visually.
                mainWindowViewModel.RepositoryViewModels.Add(repository);
                mainWindowViewModel.RecentRepositories.Add(repository);

                repository.SetThisRepositoryAsTheActiveTab();
            }
            else
            {
                return false;
            }

            return true;
        }
Ejemplo n.º 32
0
        /// <summary>
        /// Creates a new branch model.
        /// </summary>
        /// <returns></returns>
        public static Branch Create(RepositoryViewModel repositoryViewModel, LibGit2Sharp.Repository repo, LibGit2Sharp.Branch branch)
        {
            Branch newBranch = new Branch
            {
                CanonicalName = branch.CanonicalName,
                Name = branch.Name,
                IsRemote = branch.IsRemote,
                IsTracking = branch.IsTracking,
                TipHash = branch.Tip.Sha.ToString(),
                AheadBy = branch.AheadBy,
                BehindBy = branch.BehindBy,
                TrackedBranchName = branch.TrackedBranch != null ? branch.TrackedBranch.Name : null
            };

            newBranch.repositoryViewModel = repositoryViewModel;

            // Loop through the first N commits and let them know about me.
            foreach (LibGit2Sharp.Commit branchCommit in branch.Commits.Take(repositoryViewModel.CommitsPerPage))
            {
                Commit commit = repositoryViewModel.Commits.Where(c => c.Hash == branchCommit.Sha.ToString()).FirstOrDefault();

                if (commit != null)
                {
                    commit.Branches.Add(newBranch); // Let the commit know that I am one of her branches.

                    // Process commit DisplayTags (tags to display next to the commit description, in this case = branch Tips).
                    if (newBranch.TipHash == commit.Hash)
                    {
                        commit.DisplayTags.Add(branch.Name);
                        newBranch.Tip = commit;
                    }
                }
            }

            return newBranch;
        }
Ejemplo n.º 33
0
 public ChangesetGraph(RepositoryViewModel repositoryViewModel, Canvas graph)
 {
     this.repositoryViewModel = repositoryViewModel;
     this.graph = graph;
 }