コード例 #1
0
        public static IEnumerable<Change> GetChanges(string path, string firstIdentifier, string secondIdentifier, string repositoryPath = "Backend.git")
        {
            var repo = new Repository(repositoryPath);

            var firstCommit = repo.Get<Commit>(firstIdentifier);
            var secondCommit = repo.Get<Commit>(secondIdentifier);
            if (firstCommit == null || secondCommit == null) return null;

            return secondCommit.CompareAgainst(firstCommit).ToArray();
        }
コード例 #2
0
 public void access_git_objects()
 {
     // standard access of git objects, supported by gitsharp.core
     using (var repo = new Repository(@"L:\Documents and Settings\All Users\Application Data\Smeedee_dummy"))
     {
         Assert.IsTrue(repo.Get<Commit>("master").IsCommit);
         (repo.Get<Branch>("master")).ShouldNotBeNull();
         (repo.Get<Branch>("master").Target).ShouldNotBeNull();
         Assert.IsTrue(repo.Get<Commit>("HEAD^^").IsCommit);
         /*
         Assert.IsTrue(repo.Get<Tag>("A").IsTag);
         Assert.IsTrue(repo.Get<Branch>("a").Target.IsCommit);
         Assert.IsTrue(repo.Get<Commit>("a").IsCommit);
         Assert.IsTrue(repo.Get<Commit>("prefix/a").IsCommit);
         Assert.IsTrue(repo.Get<Commit>("68cb1f232964f3cd698afc1dafe583937203c587").IsCommit);
         Assert.NotNull(repo.Get<Blob>("a")); // <--- returns a blob containing the raw representation of tree "a" on master
         Assert.IsTrue(repo.Get<Tree>("a").IsTree); // <--- there is a directory "a" on master
         Assert.IsTrue(repo.Get<Tree>("a/").IsTree);
         Assert.NotNull(repo.Get<Blob>("a/a1"));
         Assert.NotNull(repo.Get<Leaf>("a/a1"));*/
     }
 }
コード例 #3
0
        public static string GetTemplate(string path, string repository = "Backend.git", string branch = "template")
        {
            var repo = new Repository(repository);

            var commit = repo.Get<Commit>(branch);
            if (commit == null) return null;
            var blob = commit.Tree[path];

            if (blob == null || !blob.IsBlob)
            {
                return null;
            }

            return new Blob(repo, blob.Hash).Data;
        }
コード例 #4
0
        public static Blob GetData(string path, string identifier, string repositoryPath = "Backend.git")
        {
            var repo = new Repository(repositoryPath);

            var commit = repo.Get<Commit>(identifier);
            if (commit == null) return null;
            var blob = commit.Tree[path];

            if (blob == null || !blob.IsBlob)
            {
                return null;
            }

            return new Blob(repo, blob.Hash);
        }
コード例 #5
0
        public void see_if_we_get_a_not_disposed_warning()
        {
            Repository repository = new Repository(_localDirectory_cloned);
            var head = repository.Get<Commit>("HEAD");
            var log = new Collection<Commit>();

            Console.WriteLine(head.Message);
            log.Add(head);
            log.Add(head.Parent);

            for (int i=0; i<log.Count(); i++)
                Console.WriteLine(log.ElementAt(i).Message);

            GitChangesetRepository gcr = new GitChangesetRepository(_localDirectory_cloned);
            var testGet = gcr.Get(new ChangesetsAfterRevisionSpecification(65));
        }
コード例 #6
0
        public static IEnumerable<Commit> GetHistory(string path, string identifier, string repositoryPath = "Backend.git")
        {
            var repo = new Repository(repositoryPath);

            var commit = repo.Get<Commit>(identifier);
            if (commit == null) yield break;

            while (commit != null)
            {
                if (commit.Tree[path] != null)
                {
                    yield return commit;
                }
                commit = commit.HasParents ? commit.Parent : null;
            }
        }
コード例 #7
0
ファイル: Versioning.cs プロジェクト: starry-au/vixen
        private void btnRestore_Click(object sender, EventArgs e)
        {
            //messageBox Arguments are (Text, Title, No Button Visible, Cancel Button Visible)
            MessageBoxForm.msgIcon = SystemIcons.Hand;             //this is used if you want to add a system icon to the message form.
            var messageBox = new MessageBoxForm("Are you sure you want to restore this version?  \n\rIf you have not saved the current file, all changes will be lost!", "Restore File", true, false);

            messageBox.ShowDialog();
            if (messageBox.DialogResult == DialogResult.OK)
            {
                var commit = _repo.Get <Commit>(this.txtChangeHash.Text);
                var tree   = commit.Tree;
                foreach (Tree subtree in tree.Trees)
                {
                    var leaf = subtree.Leaves.Where(l => l.Path.Equals(treeViewFiles.SelectedNode.Tag as string)).FirstOrDefault();
                    if (leaf != null)
                    {
                        var            rawData  = leaf.RawData;
                        var            fileName = System.IO.Path.Combine(_repo.WorkingDirectory, treeViewFiles.SelectedNode.Tag as string).Replace('/', '\\');
                        var            b        = fileName;
                        var            c        = b;
                        var            fi       = new FileInfo(fileName);
                        SaveFileDialog dlg      = new SaveFileDialog();
                        dlg.FileName         = fi.Name;
                        dlg.AddExtension     = true;
                        dlg.DefaultExt       = fi.Extension;
                        dlg.InitialDirectory = fi.DirectoryName;
                        dlg.Filter           = "All files (*.*)|*.*";

                        var ddd = dlg.ShowDialog();
                        if (ddd == System.Windows.Forms.DialogResult.OK)
                        {
                            lock (Module.fileLockObject)
                            {
                                Module.restoringFile = true;
                                File.WriteAllBytes(fileName, rawData);
                            }
                        }
                    }
                }
            }
        }
コード例 #8
0
        public void FillFromRepository(Repository repository, RepositoryNavigationRequest request)
        {
            Branches.AddRange(repository.Branches.Keys.Select(x =>
                new BranchViewModel(x, new RepositoryNavigationRequest()
                {
                    RepositoryName = request.RepositoryName,
                    Treeish = x,
                    RepositoryLocation = request.RepositoryLocation
                })));

            Tags.AddRange(repository.Tags.Keys.Select(x =>
                new BranchViewModel(x, new RepositoryNavigationRequest()
                {
                    RepositoryName = request.RepositoryName,
                    Treeish = x,
                    RepositoryLocation = request.RepositoryLocation
                })));

            var obj = repository.Get<AbstractObject>(Treeish);

            if (obj.IsTag)
            {
                obj = (obj as Tag).Target;
            }

            if (obj.IsCommit)
            {
                CurrentCommit = new CommitViewModel(repository, request, obj as Commit, true);
            }
        }
コード例 #9
0
ファイル: Stash.cs プロジェクト: akrisiun/GitSharp
        internal void Apply(Stash stash)
        {
            Commit wip   = _repo.Get <Commit> (stash.CommitId);
            Commit index = wip.Parents.Last();

            Tree     wipTree          = wip.Tree;
            Tree     headTree         = _repo.CurrentBranch.CurrentCommit.Tree;
            GitIndex currentIndex     = _repo.Index.GitIndex;
            Tree     currentIndexTree = new Tree(_repo, _repo._internal_repo.MapTree(currentIndex.writeTree()));

            WorkDirCheckout co = new WorkDirCheckout(_repo._internal_repo, _repo._internal_repo.WorkingDirectory, headTree.InternalTree, currentIndex, wip.Tree.InternalTree);

            co.checkout();

            currentIndex.write();

            List <DirCacheEntry> toAdd = new List <DirCacheEntry> ();

            DirCache dc = DirCache.Lock(_repo._internal_repo);

            try {
                var cacheEditor = dc.editor();

                // The WorkDirCheckout class doesn't check if there are conflicts in modified files,
                // so we have to do it here.

                foreach (var c in co.Updated)
                {
                    var baseEntry   = wip.Parents.First().Tree[c.Key] as Leaf;
                    var oursEntry   = wipTree [c.Key] as Leaf;
                    var theirsEntry = headTree [c.Key] as Leaf;

                    if (baseEntry != null && oursEntry != null && currentIndexTree [c.Key] == null)
                    {
                        // If a file was reported as updated but that file is not present in the stashed index,
                        // it means that the file was scheduled to be deleted.
                        cacheEditor.@add(new DirCacheEditor.DeletePath(c.Key));
                        File.Delete(_repo.FromGitPath(c.Key));
                    }
                    else if (baseEntry != null && oursEntry != null && theirsEntry != null)
                    {
                        MergeResult    res = MergeAlgorithm.merge(new RawText(baseEntry.RawData), new RawText(oursEntry.RawData), new RawText(theirsEntry.RawData));
                        MergeFormatter f   = new MergeFormatter();
                        using (BinaryWriter bw = new BinaryWriter(File.OpenWrite(_repo.FromGitPath(c.Key)))) {
                            f.formatMerge(bw, res, "Base", "Stash", "Head", Constants.CHARSET.WebName);
                        }
                        if (res.containsConflicts())
                        {
                            // Remove the entry from the index. It will be added later on.
                            cacheEditor.@add(new DirCacheEditor.DeletePath(c.Key));

                            // Generate index entries for each merge stage
                            // Those entries can't be added right now to the index because a DirCacheEditor
                            // can't be used at the same time as a DirCacheBuilder.
                            var e = new DirCacheEntry(c.Key, DirCacheEntry.STAGE_1);
                            e.setObjectId(baseEntry.InternalEntry.Id);
                            e.setFileMode(baseEntry.InternalEntry.Mode);
                            toAdd.Add(e);

                            e = new DirCacheEntry(c.Key, DirCacheEntry.STAGE_2);
                            e.setObjectId(oursEntry.InternalEntry.Id);
                            e.setFileMode(oursEntry.InternalEntry.Mode);
                            toAdd.Add(e);

                            e = new DirCacheEntry(c.Key, DirCacheEntry.STAGE_3);
                            e.setObjectId(theirsEntry.InternalEntry.Id);
                            e.setFileMode(theirsEntry.InternalEntry.Mode);
                            toAdd.Add(e);
                        }
                    }
                }

                cacheEditor.finish();

                if (toAdd.Count > 0)
                {
                    // Add the index entries generated above
                    var cacheBuilder = dc.builder();
                    for (int n = 0; n < dc.getEntryCount(); n++)
                    {
                        cacheBuilder.@add(dc.getEntry(n));
                    }
                    foreach (var entry in toAdd)
                    {
                        cacheBuilder.@add(entry);
                    }
                    cacheBuilder.finish();
                }

                dc.write();
                dc.commit();
            } catch {
                dc.unlock();
                throw;
            }
        }