Example #1
0
        public virtual void TestPush()
        {
            // create other repository
            Repository db2 = CreateWorkRepository();
            // setup the first repository
            StoredConfig config       = ((FileBasedConfig)db.GetConfig());
            RemoteConfig remoteConfig = new RemoteConfig(config, "test");
            URIish       uri          = new URIish(db2.Directory.ToURI().ToURL());

            remoteConfig.AddURI(uri);
            remoteConfig.Update(config);
            config.Save();
            Git git1 = new Git(db);
            // create some refs via commits and tag
            RevCommit commit = git1.Commit().SetMessage("initial commit").Call();
            RevTag    tag    = git1.Tag().SetName("tag").Call();

            try
            {
                db2.Resolve(commit.Id.GetName() + "^{commit}");
                NUnit.Framework.Assert.Fail("id shouldn't exist yet");
            }
            catch (MissingObjectException)
            {
            }
            // we should get here
            RefSpec spec = new RefSpec("refs/heads/master:refs/heads/x");

            git1.Push().SetRemote("test").SetRefSpecs(spec).Call();
            NUnit.Framework.Assert.AreEqual(commit.Id, db2.Resolve(commit.Id.GetName() + "^{commit}"
                                                                   ));
            NUnit.Framework.Assert.AreEqual(tag.Id, db2.Resolve(tag.Id.GetName()));
        }
        private static void AssertStandardCcLibrariesContentInBusinessLibrary(Repository repository, string modelName,
                                                                              string bLibraryName)
        {
            Assert.IsNotNull(repository.Resolve <Element>((Path)modelName / bLibraryName / "PRIMLibrary" / "Boolean"),
                             "The PRIM library \"PRIMLibrary\" is missing a primitive type named \"Boolean\".");
            Assert.IsNotNull(repository.Resolve <Element>((Path)modelName / bLibraryName / "PRIMLibrary" / "Date"),
                             "The PRIM library \"PRIMLibrary\" is missing a primitive type named \"Date\".");
            Assert.IsNotNull(repository.Resolve <Element>((Path)modelName / bLibraryName / "PRIMLibrary" / "Decimal"),
                             "The PRIM library \"PRIMLibrary\" is missing a primitive type named \"Decimal\".");
            Assert.IsNotNull(repository.Resolve <Element>((Path)modelName / bLibraryName / "PRIMLibrary" / "String"),
                             "The PRIM library \"PRIMLibrary\" is missing a primitive type named \"String\".");

            Assert.IsNotNull(repository.Resolve <Element>((Path)modelName / bLibraryName / "CDTLibrary" / "DateTime"),
                             "The CDT library \"CDTLibrary\" is missing a primitive type named \"DateTime\".");
            Assert.IsNotNull(repository.Resolve <Element>((Path)modelName / bLibraryName / "CDTLibrary" / "Name"),
                             "The CDT library \"CDTLibrary\" is missing a primitive type named \"Name\".");
            Assert.IsNotNull(repository.Resolve <Element>((Path)modelName / bLibraryName / "CDTLibrary" / "Text"),
                             "The CDT library \"CDTLibrary\" is missing a primitive type named \"Text\".");
            Assert.IsNotNull(repository.Resolve <Element>((Path)modelName / bLibraryName / "CDTLibrary" / "Time"),
                             "The CDT library \"CDTLibrary\" is missing a primitive type named \"Time\".");

            Assert.IsNotNull(repository.Resolve <Element>((Path)modelName / bLibraryName / "CCLibrary" / "Address"),
                             "The CC library \"CCLibrary\" is missing a primitive type named \"Address\".");
            Assert.IsNotNull(repository.Resolve <Element>((Path)modelName / bLibraryName / "CCLibrary" / "Person"),
                             "The CC library \"CCLibrary\" is missing a primitive type named \"Person\".");
        }
        public byte[] GetFileContent(string fileName)
        {
            if (!HasGitRepository || string.IsNullOrEmpty(fileName))
            {
                return(null);
            }

            fileName = GetRelativeFileNameForGit(fileName);

            try
            {
                var     head    = repository.Resolve(Constants.HEAD);
                RevTree revTree = head == null ? null : new RevWalk(repository).ParseTree(head);
                if (revTree != null)
                {
                    var entry = TreeWalk.ForPath(repository, fileName, revTree);
                    if (entry != null && !entry.IsSubtree)
                    {
                        var blob = repository.Open(entry.GetObjectId(0));
                        if (blob != null)
                        {
                            return(blob.GetCachedBytes());
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log.WriteLine("Get File Content: {0}\r\n{1}", fileName, ex.ToString());
            }

            return(null);
        }
Example #4
0
        public Commit GetCommit(string commitId)
        {
            //commitId = repository.Resolve(commitId).Name;
            //return Commits.Where(c => c.Id.StartsWith(commitId)).FirstOrDefault();
            var id = repository.Resolve(commitId);

            if (id == null)
            {
                return(null);
            }

            RevWalk   walk   = new RevWalk(repository);
            RevCommit commit = walk.ParseCommit(id);

            walk.Dispose();
            return(commit == null || commit.Tree == null ? null : new Commit
            {
                Id = commit.Id.Name,
                ParentIds = commit.Parents.Select(p => p.Id.Name).ToList(),
                CommitDateRelative = RelativeDateFormatter.Format(commit.GetAuthorIdent().GetWhen()),
                CommitterName = commit.GetCommitterIdent().GetName(),
                CommitterEmail = commit.GetCommitterIdent().GetEmailAddress(),
                CommitDate = commit.GetCommitterIdent().GetWhen(),
                Message = commit.GetShortMessage(),
            });
        }
Example #5
0
        /// <summary>
        /// Does the initial refresh of the list of files that has merge conflicts.
        /// </summary>
        private void InitialRefresh()
        {
            IEnumerable <MergeConflict> conflicts = _Repository.Resolve(new ResolveCommand()
                                                                        .WithAction(ResolveAction.List));

            _Conflicts.AddRange(
                from conflict in conflicts
                select new MergeJobConflict(this, conflict.Path, conflict.State));
        }
 private static void AssertEmptyBieLibrariesinBusinessLibrary(Repository repository, string modelName,
                                                              string bLibraryName)
 {
     Assert.IsNotNull(repository.Resolve <Package>((Path)modelName / bLibraryName / "BDTLibrary"),
                      "The business library \"{0}\" is missing an BDT library named \"BDTLibrary\".",
                      bLibraryName);
     Assert.IsNotNull(repository.Resolve <Package>((Path)modelName / bLibraryName / "BIELibrary"),
                      "The business library \"{0}\" is missing a BIE library named \"BIELibrary\".", bLibraryName);
     Assert.IsNotNull(repository.Resolve <Package>((Path)modelName / bLibraryName / "DOCLibrary"),
                      "The business library \"{0}\" is missing a DOC library named \"DOCLibrary\".", bLibraryName);
 }
 private static void AssertNonExistenceOfBieLibrariesinBusinessLibrary(Repository repository, string modelName,
                                                                       string bLibraryName)
 {
     Assert.IsNull(repository.Resolve <Package>((Path)modelName / bLibraryName / "BDTLibrary"),
                   "The business library \"{0}\" contains a BDT library named \"BDTLibrary\" which is not supposed to be part of the business library.",
                   bLibraryName);
     Assert.IsNull(repository.Resolve <Package>((Path)modelName / bLibraryName / "BIELibrary"),
                   "The business library \"{0}\" contains a BIE library named \"BIELibrary\" which is not supposed to be part of the business library.",
                   bLibraryName);
     Assert.IsNull(repository.Resolve <Package>((Path)modelName / bLibraryName / "DOCLibrary"),
                   "The business library \"{0}\" contains a DOC library named \"DOCLibrary\" which is not supposed to be part of the business library.",
                   bLibraryName);
 }
        // Purpose: Test the import capability of the model creator to import the standard CC libraries
        // into a particular model which contains an empty business library named bLibrary.

        private static void AssertEmptyStandardCcLibrariesInBusinessLibrary(Repository repository, string modelName,
                                                                            string bLibraryName)
        {
            Assert.IsNotNull(repository.Resolve <Package>((Path)modelName / bLibraryName / "ENUMLibrary"),
                             "The business library \"{0}\" is missing an ENUM library named \"ENUMLibrary\".",
                             bLibraryName);
            Assert.IsNotNull(repository.Resolve <Package>((Path)modelName / bLibraryName / "PRIMLibrary"),
                             "The business library \"{0}\" is missing a PRIM library named \"PRIMLibrary\".",
                             bLibraryName);
            Assert.IsNotNull(repository.Resolve <Package>((Path)modelName / bLibraryName / "CDTLibrary"),
                             "The business library \"{0}\" is missing a CDT library named \"CDTLibrary\".", bLibraryName);
            Assert.IsNotNull(repository.Resolve <Package>((Path)modelName / bLibraryName / "CCLibrary"),
                             "The business library \"{0}\" is missing an CC library named \"CCLibrary\".", bLibraryName);
        }
Example #9
0
        public RemoteRefUpdate(Repository localDb, string srcRef, string remoteName, bool forceUpdate, string localName, ObjectId expectedOldObjectId)
        {
            if (remoteName == null)
            {
                throw new ArgumentException("Remote name can't be null.");
            }

            SourceRef   = srcRef;
            NewObjectId = (srcRef == null ? ObjectId.ZeroId : localDb.Resolve(srcRef));
            if (NewObjectId == null)
            {
                throw new IOException("Source ref " + srcRef + " doesn't resolve to any object.");
            }
            RemoteName  = remoteName;
            ForceUpdate = forceUpdate;
            if (localName != null && localDb != null)
            {
                TrackingRefUpdate = new TrackingRefUpdate(localDb, localName, remoteName, true, NewObjectId, "push");
            }
            else
            {
                TrackingRefUpdate = null;
            }
            this._localDb       = localDb;
            ExpectedOldObjectId = expectedOldObjectId;
            Status = UpdateStatus.NOT_ATTEMPTED;
        }
        public override void SetUp()
        {
            base.SetUp();
            src = CreateBareRepository();
            dst = CreateBareRepository();
            // Fill dst with a some common history.
            //
            TestRepository d = new TestRepository <Repository>(dst);

            a = d.Blob("a");
            A = d.Commit(d.Tree(d.File("a", a)));
            B = d.Commit().Parent(A).Create();
            d.Update(R_MASTER, B);
            // Clone from dst into src
            //
            NGit.Transport.Transport t = NGit.Transport.Transport.Open(src, UriOf(dst));
            try
            {
                t.Fetch(PM, Collections.Singleton(new RefSpec("+refs/*:refs/*")));
                NUnit.Framework.Assert.AreEqual(B, src.Resolve(R_MASTER));
            }
            finally
            {
                t.Close();
            }
            // Now put private stuff into dst.
            //
            b = d.Blob("b");
            P = d.Commit(d.Tree(d.File("b", b)), A);
            d.Update(R_PRIVATE, P);
        }
Example #11
0
        public RemoteRefUpdate(Repository localDb, string srcRef, string remoteName, bool forceUpdate, string localName, ObjectId expectedOldObjectId)
        {
            if (remoteName == null)
                throw new ArgumentException("Remote name can't be null.");

            SourceRef = srcRef;
            NewObjectId = (srcRef == null ? ObjectId.ZeroId : localDb.Resolve(srcRef));
            if (NewObjectId == null)
            {
                throw new IOException("Source ref " + srcRef + " doesn't resolve to any object.");
            }
            RemoteName = remoteName;
            ForceUpdate = forceUpdate;
            if (localName != null && localDb != null)
            {
                TrackingRefUpdate = new TrackingRefUpdate(localDb, localName, remoteName, true, NewObjectId, "push");
            }
            else
            {
                TrackingRefUpdate = null;
            }
            this.localDb = localDb;
            ExpectedOldObjectId = expectedOldObjectId;
            Status = UpdateStatus.NOT_ATTEMPTED;
        }
Example #12
0
        public async Task <ModpackInfo> GetLatestModpackInfo()
        {
            if (Repository == null)
            {
                return(await DownloadLatestModpackInfo());
            }

            return(await Task.Run(() => {
                var id = Repository.Resolve("origin/" + Settings.Branch);
                ObjectReader reader = null;
                try {
                    reader = Repository.NewObjectReader();
                    var walk = new RevWalk(reader);
                    var commit = walk.ParseCommit(id);
                    var treeWalk = TreeWalk.ForPath(reader, ModpackInfo.FileName, commit.Tree);
                    if (treeWalk == null)
                    {
                        return null;
                    }

                    byte[] data = reader.Open(treeWalk.GetObjectId(0)).GetBytes();
                    var modpackJson = Encoding.UTF8.GetString(data);
                    return ModpackInfo.Parse(modpackJson);
                } finally {
                    if (reader != null)
                    {
                        reader.Release();
                    }
                }
            }));
        }
Example #13
0
        } // End Function GetRepoPath 


        // https://github.com/mono/ngit/commits/master
        public static void GetCommitsByBranch(string branchName)
        {
            // D:\Stefan.Steiger\Documents\Visual Studio 2013\Projects
            string dir = GetRepoPath();
            System.Console.WriteLine(dir);
            // dir = "https://github.com/mono/ngit.git";


            // https://github.com/centic9/jgit-cookbook/blob/master/src/main/java/org/dstadler/jgit/porcelain/ListRemoteRepository.java
            // https://stackoverflow.com/questions/13667988/how-to-use-ls-remote-in-ngit
            // git.LsRemote();


            Git git = Git.Open(dir);
            Repository repo = git.GetRepository();
            
            ObjectId branchOid = repo.Resolve(branchName);
            
            System.Console.WriteLine("Commits of branch: '{0}' ({1})", branchName, branchOid);
            System.Console.WriteLine("-------------------------------------");


            Sharpen.Iterable<RevCommit> commits = git.Log().Add(branchOid).Call();

            int count = 0;

            RevCommit laterCommit = null;

            // Note: Apparently sorted DESCENDING by COMMIT DATE
            foreach (RevCommit earlierCommit in commits)
            {
                System.Console.WriteLine(earlierCommit.Name);
                System.Console.WriteLine(earlierCommit.GetAuthorIdent().GetName());

                System.DateTime dt = UnixTimeStampToDateTime(earlierCommit.CommitTime);
                System.Console.WriteLine(dt);

                System.Console.WriteLine(earlierCommit.GetFullMessage());

                if (laterCommit != null)
                {
                    GetChanges(git, repo, earlierCommit, laterCommit);
                } // End if (laterCommit != null)

                // https://github.com/gitblit/gitblit/blob/master/src/main/java/com/gitblit/utils/JGitUtils.java#L718
                laterCommit = earlierCommit;
                count++;
            } // Next earlierCommit 

            System.Console.WriteLine(count);


            // Handle disposing of NGit's locks
            repo.Close();
            repo.ObjectDatabase.Close();
            repo = null;
            git = null;

            // https://github.com/mono/ngit/blob/master/NGit/NGit.Revwalk/RevWalkUtils.cs
        } // End Sub GetCommitsByBranch 
 public void Refresh()
 {
     this.cache.Clear();
     this.changedFiles    = null;
     this.repositoryGraph = null;
     this.head            = null;
     this.remotes         = null;
     this.configs         = null;
     if (!string.IsNullOrEmpty(initFolder))
     {
         try
         {
             this.repository = Open(new DirectoryInfo(initFolder));
             if (this.repository != null)
             {
                 head = repository.Resolve(Constants.HEAD);
                 if (repository.IsBare)
                 {
                     throw new NoWorkTreeException();
                 }
             }
         }
         catch (Exception ex)
         {
             this.repository = null;
             Log.WriteLine("Refresh: {0}\r\n{1}", this.initFolder, ex.ToString());
         }
     }
 }
 public static ObjectId      resolve(this Repository repository, string sha1)
 {
     if (repository.notNull())
     {
         return(repository.Resolve(sha1));
     }
     return(null);
 }
        public void Refresh()
        {
            this.index      = null;
            this.commitTree = null;

            this.cache.Clear();
            this.changedFiles    = null;
            this.repositoryGraph = null;
            this.dirCache        = null;
            this.head            = null;
            this.ignoreRules     = null;
            this.remotes         = null;
            this.configs         = null;
            if (!string.IsNullOrEmpty(initFolder))
            {
                try
                {
                    this.repository = Open(new DirectoryInfo(initFolder));
                    dirCache        = repository.ReadDirCache();
                    head            = repository.Resolve(Constants.HEAD);

                    if (this.repository != null)
                    {
                        if (head == null)
                        {
                            this.commitTree = new Tree(repository);
                        }
                        else
                        {
                            var treeId = ObjectId.FromString(repository.Open(head).GetBytes(), 5);
                            this.commitTree = new Tree(repository, treeId, repository.Open(treeId).GetBytes());
                        }
                        this.index = repository.GetIndex();
                        this.index.RereadIfNecessary();

                        try
                        {
                            //load local .gitignore file
                            var ignoreFile = Path.Combine(this.initFolder,
                                                          Constants.GITIGNORE_FILENAME);
                            if (File.Exists(ignoreFile))
                            {
                                ignoreRules = File.ReadAllLines(ignoreFile)
                                              .Where(line => !line.StartsWith("#") && line.Trim().Length > 0)
                                              .Select(line => new IgnoreRule(line)).ToList();
                            }
                        }
                        catch { }
                    }
                }
                catch (Exception ex)
                {
                    this.repository = null;
                    Log.WriteLine("Refresh: {0}\r\n{1}", this.initFolder, ex.ToString());
                }
            }
        }
        private void AssertPackagePath(params string[] pathElements)
        {
            var path    = new Path(pathElements);
            var package = repository.Resolve <Package>(path);

            Assert.IsNotNull(package, "package path could not be resolved {0}", path);
            Assert.AreEqual(pathElements[pathElements.Length - 1], package.Name, "wrong package resolved");
        }
        public virtual void TestSuccess()
        {
            // Manually force a delta of an object so we reuse it later.
            //
            TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(1024);
            PackHeader(pack, 2);
            pack.Write((Constants.OBJ_BLOB) << 4 | 1);
            Deflate(pack, new byte[] { (byte)('a') });
            pack.Write((Constants.OBJ_REF_DELTA) << 4 | 4);
            a.CopyRawTo(pack);
            Deflate(pack, new byte[] { unchecked ((int)(0x1)), unchecked ((int)(0x1)), unchecked (
                                           (int)(0x1)), (byte)('b') });
            Digest(pack);
            OpenPack(pack);
            // Verify the only storage of b is our packed delta above.
            //
            ObjectDirectory od = (ObjectDirectory)src.ObjectDatabase;

            NUnit.Framework.Assert.IsTrue(src.HasObject(b), "has b");
            NUnit.Framework.Assert.IsFalse(od.FileFor(b).Exists(), "b not loose");
            // Now use b but in a different commit than what is hidden.
            //
            TestRepository s = new TestRepository <Repository>(src);
            RevCommit      N = s.Commit().Parent(B).Add("q", b).Create();

            s.Update(R_MASTER, N);
            // Push this new content to the remote, doing strict validation.
            //
            TransportLocal  t = new _TransportLocal_210(this, src, UriOf(dst), dst.Directory);
            RemoteRefUpdate u = new RemoteRefUpdate(src, R_MASTER, R_MASTER, false, null, null
                                                    );
            //
            //
            // src name
            // dst name
            // do not force update
            // local tracking branch
            // expected id
            PushResult r;

            try
            {
                t.SetPushThin(true);
                r = t.Push(PM, Sharpen.Collections.Singleton(u));
            }
            finally
            {
                t.Close();
            }
            NUnit.Framework.Assert.IsNotNull(r, "have result");
            NUnit.Framework.Assert.IsNull(r.GetAdvertisedRef(R_PRIVATE), "private not advertised"
                                          );
            NUnit.Framework.Assert.AreEqual(RemoteRefUpdate.Status.OK, u.GetStatus(), "master updated"
                                            );
            NUnit.Framework.Assert.AreEqual(N, dst.Resolve(R_MASTER));
        }
Example #19
0
 public IEnumerable <RevCommit> GetNewCommits()
 {
     if (Repository == null)
     {
         return(Enumerable.Empty <RevCommit>());
     }
     return(new Git(Repository).Log().AddRange(
                Repository.Resolve("HEAD"),
                Repository.Resolve("origin/" + Settings.Branch)).Call());
 }
        public virtual void TestWrite1()
        {
            byte[] bundle;
            // Create a small bundle, an early commit
            bundle = MakeBundle("refs/heads/aa", db.Resolve("a").Name, null);
            // Then we clone a new repo from that bundle and do a simple test. This
            // makes sure
            // we could read the bundle we created.
            Repository  newRepo       = CreateBareRepository();
            FetchResult fetchResult   = FetchFromBundle(newRepo, bundle);
            Ref         advertisedRef = fetchResult.GetAdvertisedRef("refs/heads/aa");

            NUnit.Framework.Assert.AreEqual(db.Resolve("a").Name, advertisedRef.GetObjectId()
                                            .Name);
            NUnit.Framework.Assert.AreEqual(db.Resolve("a").Name, newRepo.Resolve("refs/heads/aa"
                                                                                  ).Name);
            NUnit.Framework.Assert.IsNull(newRepo.Resolve("refs/heads/a"));
            // Next an incremental bundle
            bundle = MakeBundle("refs/heads/cc", db.Resolve("c").Name, new RevWalk(db).ParseCommit
                                    (db.Resolve("a").ToObjectId()));
            fetchResult   = FetchFromBundle(newRepo, bundle);
            advertisedRef = fetchResult.GetAdvertisedRef("refs/heads/cc");
            NUnit.Framework.Assert.AreEqual(db.Resolve("c").Name, advertisedRef.GetObjectId()
                                            .Name);
            NUnit.Framework.Assert.AreEqual(db.Resolve("c").Name, newRepo.Resolve("refs/heads/cc"
                                                                                  ).Name);
            NUnit.Framework.Assert.IsNull(newRepo.Resolve("refs/heads/c"));
            NUnit.Framework.Assert.IsNull(newRepo.Resolve("refs/heads/a"));
            // still unknown
            try
            {
                // Check that we actually needed the first bundle
                Repository newRepo2 = CreateBareRepository();
                fetchResult = FetchFromBundle(newRepo2, bundle);
                NUnit.Framework.Assert.Fail("We should not be able to fetch from bundle with prerequisites that are not fulfilled"
                                            );
            }
            catch (MissingBundlePrerequisiteException e)
            {
                NUnit.Framework.Assert.IsTrue(e.Message.IndexOf(db.Resolve("refs/heads/a").Name)
                                              >= 0);
            }
        }
Example #21
0
        public async Task <bool> IsUpdateAvailable()
        {
            if (Repository == null)
            {
                return(true);
            }

            await Fetch();

            return(Repository.Resolve("HEAD").Name !=
                   Repository.Resolve("origin/" + Settings.Branch).Name);
        }
        public void ShouldCreateMissingTaggedValuesForIdScheme()
        {
            Repository repo = CreateRepositoryWithoutTaggedValues();

            var synchStereotypes = new SynchTaggedValues(repo);

            synchStereotypes.FixTaggedValues();

            var element = repo.Resolve <Element>((Path)"Model" / "bLibrary" / "ENUMLibrary" / "IDSCHEME");

            Assert.That(element, Is.Not.Null, "Element not found");
            Assert.That(element, HasTaggedValues(new[] { "businessTerm", "definition", "dictionaryEntryName", "identifierSchemeAgencyIdentifier", "identifierSchemeAgencyName", "modificationAllowedIndicator", "pattern", "restrictedPrimitive", "uniqueIdentifier", "versionIdentifier", }), "missing tagged values");
        }
        public void ShouldCreateMissingTaggedValuesForPrim()
        {
            Repository repo = CreateRepositoryWithoutTaggedValues();

            var synchStereotypes = new SynchTaggedValues(repo);

            synchStereotypes.FixTaggedValues();

            var element = repo.Resolve <Element>((Path)"Model" / "bLibrary" / "PRIMLibrary" / "PRIM");

            Assert.That(element, Is.Not.Null, "Element not found");
            Assert.That(element, HasTaggedValues(new[] { "businessTerm", "definition", "dictionaryEntryName", "fractionDigits", "languageCode", "length", "maximumExclusive", "maximumInclusive", "maximumLength", "minimumExclusive", "minimumInclusive", "minimumLength", "pattern", "totalDigits", "uniqueIdentifier", "versionIdentifier", "whiteSpace", }), "missing tagged values");
        }
        public void ShouldCreateMissingTaggedValuesForBieLibrary()
        {
            Repository repo = CreateRepositoryWithoutTaggedValues();

            var synchStereotypes = new SynchTaggedValues(repo);

            synchStereotypes.FixTaggedValues();

            var package = repo.Resolve <Package>((Path)"Model" / "bLibrary" / "BIELibrary");

            Assert.That(package, Is.Not.Null, "Package not found");
            Assert.That(package, HasTaggedValues(new[] { "businessTerm", "copyright", "owner", "reference", "status", "uniqueIdentifier", "versionIdentifier", "baseURN", "namespacePrefix", }), "missing tagged values");
        }
        public void ShouldCreateMissingTaggedValuesForAbie()
        {
            Repository repo = CreateRepositoryWithoutTaggedValues();

            var synchStereotypes = new SynchTaggedValues(repo);

            synchStereotypes.FixTaggedValues();

            var element = repo.Resolve <Element>((Path)"Model" / "bLibrary" / "BIELibrary" / "ABIE");

            Assert.That(element, Is.Not.Null, "Element not found");
            Assert.That(element, HasTaggedValues(new[] { "businessTerm", "definition", "dictionaryEntryName", "languageCode", "uniqueIdentifier", "versionIdentifier", "usageRule", }), "missing tagged values");
        }
Example #26
0
        public virtual void CommitNewSubmodule()
        {
            Git git = new Git(db);

            WriteTrashFile("file.txt", "content");
            git.Add().AddFilepattern("file.txt").Call();
            RevCommit           commit  = git.Commit().SetMessage("create file").Call();
            SubmoduleAddCommand command = new SubmoduleAddCommand(db);
            string path = "sub";

            command.SetPath(path);
            string uri = db.Directory.ToURI().ToString();

            command.SetURI(uri);
            Repository repo = command.Call();

            NUnit.Framework.Assert.IsNotNull(repo);
            AddRepoToClose(repo);
            SubmoduleWalk generator = SubmoduleWalk.ForIndex(db);

            NUnit.Framework.Assert.IsTrue(generator.Next());
            NUnit.Framework.Assert.AreEqual(path, generator.GetPath());
            NUnit.Framework.Assert.AreEqual(commit, generator.GetObjectId());
            NUnit.Framework.Assert.AreEqual(uri, generator.GetModulesUrl());
            NUnit.Framework.Assert.AreEqual(path, generator.GetModulesPath());
            NUnit.Framework.Assert.AreEqual(uri, generator.GetConfigUrl());
            Repository subModRepo = generator.GetRepository();

            AddRepoToClose(subModRepo);
            NUnit.Framework.Assert.IsNotNull(subModRepo);
            NUnit.Framework.Assert.AreEqual(commit, repo.Resolve(Constants.HEAD));
            RevCommit submoduleCommit = git.Commit().SetMessage("submodule add").SetOnly(path
                                                                                         ).Call();

            NUnit.Framework.Assert.IsNotNull(submoduleCommit);
            TreeWalk walk = new TreeWalk(db);

            walk.AddTree(commit.Tree);
            walk.AddTree(submoduleCommit.Tree);
            walk.Filter = TreeFilter.ANY_DIFF;
            IList <DiffEntry> diffs = DiffEntry.Scan(walk);

            NUnit.Framework.Assert.AreEqual(1, diffs.Count);
            DiffEntry subDiff = diffs[0];

            NUnit.Framework.Assert.AreEqual(FileMode.MISSING, subDiff.GetOldMode());
            NUnit.Framework.Assert.AreEqual(FileMode.GITLINK, subDiff.GetNewMode());
            NUnit.Framework.Assert.AreEqual(ObjectId.ZeroId, subDiff.GetOldId().ToObjectId());
            NUnit.Framework.Assert.AreEqual(commit, subDiff.GetNewId().ToObjectId());
            NUnit.Framework.Assert.AreEqual(path, subDiff.GetNewPath());
        }
        public void ShouldCreateMissingTaggedValuesForBdtSup()
        {
            Repository repo = CreateRepositoryWithoutTaggedValues();

            var synchStereotypes = new SynchTaggedValues(repo);

            synchStereotypes.FixTaggedValues();

            var element = repo.Resolve <Element>((Path)"Model" / "bLibrary" / "BDTLibrary" / "BDT");

            Assert.That(element, Is.Not.Null, "Element not found");
            var attribute = (Attribute)element.Attributes.GetByName("SUP");

            Assert.That(attribute, Is.Not.Null, "Attribute not found");
            Assert.That(attribute, HasTaggedValues(new[] { "businessTerm", "definition", "dictionaryEntryName", "enumeration", "fractionDigits", "languageCode", "maximumExclusive", "maximumInclusive", "maximumLength", "minimumExclusive", "minimumInclusive", "minimumLength", "modificationAllowedIndicator", "pattern", "totalDigits", "uniqueIdentifier", "usageRule", "versionIdentifier", }), "missing tagged values");
        }
        public void ShouldCreateMissingTaggedValuesForCodelistEntries()
        {
            Repository repo = CreateRepositoryWithoutTaggedValues();

            var synchStereotypes = new SynchTaggedValues(repo);

            synchStereotypes.FixTaggedValues();

            var element = repo.Resolve <Element>((Path)"Model" / "bLibrary" / "ENUMLibrary" / "ENUM");

            Assert.That(element, Is.Not.Null, "Element not found");
            var attribute = (Attribute)element.Attributes.GetByName("CodelistEntry");

            Assert.That(attribute, Is.Not.Null, "Attribute not found");
            Assert.That(attribute, HasTaggedValues(new[] { "codeName", "status", }), "missing tagged values");
        }
Example #29
0
        /// <summary>Construct an IndexDiff</summary>
        /// <param name="repository"></param>
        /// <param name="revstr">
        /// symbolic name e.g. HEAD
        /// An EmptyTreeIterator is used if <code>revstr</code> cannot be resolved.
        /// </param>
        /// <param name="workingTreeIterator">iterator for working directory</param>
        /// <exception cref="System.IO.IOException">System.IO.IOException</exception>
        public IndexDiff(Repository repository, string revstr, WorkingTreeIterator workingTreeIterator
                         )
        {
            this.repository = repository;
            ObjectId objectId = repository.Resolve(revstr);

            if (objectId != null)
            {
                tree = new RevWalk(repository).ParseTree(objectId);
            }
            else
            {
                tree = null;
            }
            this.initialWorkingTreeIterator = workingTreeIterator;
        }
        public void ShouldCreateMissingTaggedValuesForAscc()
        {
            Repository repo = CreateRepositoryWithoutTaggedValues();

            var synchStereotypes = new SynchTaggedValues(repo);

            synchStereotypes.FixTaggedValues();

            var element = repo.Resolve <Element>((Path)"Model" / "bLibrary" / "CCLibrary" / "ACC");

            Assert.That(element, Is.Not.Null, "Element not found");
            var connector = (Connector)element.Connectors.GetByName("ASCC");

            Assert.That(connector, Is.Not.Null, "Connector not found");
            Assert.That(connector, HasTaggedValues(new[] { "businessTerm", "definition", "dictionaryEntryName", "languageCode", "sequencingKey", "uniqueIdentifier", "versionIdentifier", "usageRule", }), "missing tagged values");
        }
Example #31
0
        private ObjectId GetTreeIdFromCommitId(Repository repository, string commitId)
        {
            var id = repository.Resolve(commitId);

            if (id == null)
            {
                return(null);
            }

            RevWalk   walk   = new RevWalk(repository);
            RevCommit commit = walk.ParseCommit(id);

            walk.Dispose();
            return(commit == null || commit.Tree == null ? null :
                   commit.Tree.Id);
        }
        public void Refresh()
        {
            this.cache.Clear();
            this.changedFiles = null;

            if (!string.IsNullOrEmpty(initFolder))
            {
                try
                {
                    this.repository = Git.Open(initFolder).GetRepository();

                    if (this.repository != null)
                    {
                        var id = repository.Resolve(Constants.HEAD);
                        //var commit = repository.MapCommit(id);
                        //this.commitTree = (commit != null ? commit.TreeEntry : new Tree(repository));
                        if (id == null)
                        {
                            this.commitTree = new Tree(repository);
                        }
                        else
                        {
                            var treeId = ObjectId.FromString(repository.Open(id).GetBytes(), 5);
                            this.commitTree = new Tree(repository, treeId, repository.Open(treeId).GetBytes());
                        }
                        this.index = repository.GetIndex();
                        this.index.RereadIfNecessary();
                    }
                }
                catch (Exception ex)
                {
                }
            }
        }
        private ObjectId GetTreeIdFromCommitId(Repository repository, string commitId)
        {
            var id = repository.Resolve(commitId);
            if (id == null) return null;

            RevWalk walk = new RevWalk(repository);
            RevCommit commit = walk.ParseCommit(id);
            walk.Dispose();
            return commit == null || commit.Tree == null ? null :
                commit.Tree.Id;
        }
Example #34
0
        /// <summary>Construct remote ref update request by providing an update specification.
        /// 	</summary>
        /// <remarks>
        /// Construct remote ref update request by providing an update specification.
        /// Object is created with default
        /// <see cref="Status.NOT_ATTEMPTED">Status.NOT_ATTEMPTED</see>
        /// status and no
        /// message.
        /// </remarks>
        /// <param name="localDb">local repository to push from.</param>
        /// <param name="srcRef">
        /// source revision - any string resolvable by
        /// <see cref="NGit.Repository.Resolve(string)">NGit.Repository.Resolve(string)</see>
        /// . This resolves to the new
        /// object that the caller want remote ref to be after update. Use
        /// null or
        /// <see cref="NGit.ObjectId.ZeroId()">NGit.ObjectId.ZeroId()</see>
        /// string for delete request.
        /// </param>
        /// <param name="remoteName">
        /// full name of a remote ref to update, e.g. "refs/heads/master"
        /// (no wildcard, no short name).
        /// </param>
        /// <param name="forceUpdate">
        /// true when caller want remote ref to be updated regardless
        /// whether it is fast-forward update (old object is ancestor of
        /// new object).
        /// </param>
        /// <param name="localName">
        /// optional full name of a local stored tracking branch, to
        /// update after push, e.g. "refs/remotes/zawir/dirty" (no
        /// wildcard, no short name); null if no local tracking branch
        /// should be updated.
        /// </param>
        /// <param name="expectedOldObjectId">
        /// optional object id that caller is expecting, requiring to be
        /// advertised by remote side before update; update will take
        /// place ONLY if remote side advertise exactly this expected id;
        /// null if caller doesn't care what object id remote side
        /// advertise. Use
        /// <see cref="NGit.ObjectId.ZeroId()">NGit.ObjectId.ZeroId()</see>
        /// when expecting no
        /// remote ref with this name.
        /// </param>
        /// <exception cref="System.IO.IOException">
        /// when I/O error occurred during creating
        /// <see cref="TrackingRefUpdate">TrackingRefUpdate</see>
        /// for local tracking branch or srcRef
        /// can't be resolved to any object.
        /// </exception>
        /// <exception cref="System.ArgumentException">if some required parameter was null</exception>
        public RemoteRefUpdate(Repository localDb, string srcRef, string remoteName, bool
			 forceUpdate, string localName, ObjectId expectedOldObjectId)
            : this(localDb, srcRef
			, srcRef != null ? localDb.Resolve(srcRef) : ObjectId.ZeroId, remoteName, forceUpdate
			, localName, expectedOldObjectId)
        {
        }
Example #35
0
        public void testRenameBranchAlsoInPack()
        {
            ObjectId rb = db.Resolve("refs/heads/b");
            ObjectId rb2 = db.Resolve("refs/heads/b~1");
            Assert.AreEqual(Ref.Storage.Packed, db.getRef("refs/heads/b").StorageFormat);
            RefUpdate updateRef = db.UpdateRef("refs/heads/b");
            updateRef.NewObjectId = rb2;
            updateRef.IsForceUpdate = true;
            RefUpdate.RefUpdateResult update = updateRef.Update();
            Assert.AreEqual(RefUpdate.RefUpdateResult.Forced, update, "internal check new ref is loose");
            Assert.AreEqual(Ref.Storage.LoosePacked, db.getRef("refs/heads/b")
                    .StorageFormat);
            RefLogWriter.WriteReflog(db, rb, rb, "Just a message", "refs/heads/b");
            Assert.IsTrue(new FileInfo(Path.Combine(db.Directory.FullName, "logs/refs/heads/b")).Exists, "no log on old branch");
            RefRename renameRef = db.RenameRef("refs/heads/b",
                    "refs/heads/new/name");
            RefUpdate.RefUpdateResult result = renameRef.Rename();
            Assert.AreEqual(RefUpdate.RefUpdateResult.Renamed, result);
            Assert.AreEqual(rb2, db.Resolve("refs/heads/new/name"));
            Assert.IsNull(db.Resolve("refs/heads/b"));
            Assert.AreEqual("Branch: renamed b to new/name", db.ReflogReader(
                    "new/name").getLastEntry().getComment());
            Assert.IsFalse(new FileInfo(Path.Combine(db.Directory.FullName, "logs/refs/heads/b")).Exists);

            // Create new Repository instance, to reread caches and make sure our
            // assumptions are persistent.
            Repository ndb = new Repository(db.Directory);
            Assert.AreEqual(rb2, ndb.Resolve("refs/heads/new/name"));
            Assert.IsNull(ndb.Resolve("refs/heads/b"));
        }
		public override void SetUp()
		{
			base.SetUp();
			src = CreateBareRepository();
			dst = CreateBareRepository();
			// Fill dst with a some common history.
			//
			TestRepository d = new TestRepository<Repository>(dst);
			a = d.Blob("a");
			A = d.Commit(d.Tree(d.File("a", a)));
			B = d.Commit().Parent(A).Create();
			d.Update(R_MASTER, B);
			// Clone from dst into src
			//
			NGit.Transport.Transport t = NGit.Transport.Transport.Open(src, UriOf(dst));
			try
			{
				t.Fetch(PM, Collections.Singleton(new RefSpec("+refs/*:refs/*")));
				NUnit.Framework.Assert.AreEqual(B, src.Resolve(R_MASTER));
			}
			finally
			{
				t.Close();
			}
			// Now put private stuff into dst.
			//
			b = d.Blob("b");
			P = d.Commit(d.Tree(d.File("b", b)), A);
			d.Update(R_PRIVATE, P);
		}
        public void Refresh()
        {
            this.index = null;
            this.commitTree = null;

            this.cache.Clear();
            this.changedFiles = null;
            this.repositoryGraph = null;
            this.dirCache = null;
            this.head = null;
            this.ignoreRules = null;
            this.remotes = null;
            this.configs = null;
            if (!string.IsNullOrEmpty(initFolder))
            {
                try
                {
                    this.repository = Open(new DirectoryInfo(initFolder));
                    if (this.repository != null)
                    {
                        dirCache = repository.ReadDirCache();
                        head = repository.Resolve(Constants.HEAD);

                        if (head == null)
                        {
                            this.commitTree = new Tree(repository);
                        }
                        else
                        {
                            var treeId = ObjectId.FromString(repository.Open(head).GetBytes(), 5);
                            this.commitTree = new Tree(repository, treeId, repository.Open(treeId).GetBytes());
                        }

                        if (repository.IsBare)
                            throw new NoWorkTreeException();

                        this.index = new GitIndex(repository);
                        this.index.Read();
                        this.index.RereadIfNecessary();

                        try
                        {
                            //load local .gitignore file
                            var ignoreFile = Path.Combine(this.initFolder,
                                Constants.GITIGNORE_FILENAME);
                            if (File.Exists(ignoreFile))
                            {
                                ignoreRules = File.ReadAllLines(ignoreFile)
                                                  .Where(line => !line.StartsWith("#") && line.Trim().Length > 0)
                                                  .Select(line => new IgnoreRule(line)).ToList();
                            }
                        }
                        catch (Exception ex)
                        {
                            Log.WriteLine("ReadIgnoreFile: {0}\r\n{1}", this.initFolder, ex.ToString());
                        }
                    }
                }
                catch (Exception ex)
                {
                    this.repository = null;
                    Log.WriteLine("Refresh: {0}\r\n{1}", this.initFolder, ex.ToString());
                }
            }
        }
Example #38
0
		/// <summary>Construct an IndexDiff</summary>
		/// <param name="repository"></param>
		/// <param name="revstr">
		/// symbolic name e.g. HEAD
		/// An EmptyTreeIterator is used if <code>revstr</code> cannot be resolved.
		/// </param>
		/// <param name="workingTreeIterator">iterator for working directory</param>
		/// <exception cref="System.IO.IOException">System.IO.IOException</exception>
		public IndexDiff(Repository repository, string revstr, WorkingTreeIterator workingTreeIterator
			)
		{
			this.repository = repository;
			ObjectId objectId = repository.Resolve(revstr);
			if (objectId != null)
			{
				tree = new RevWalk(repository).ParseTree(objectId);
			}
			else
			{
				tree = null;
			}
			this.initialWorkingTreeIterator = workingTreeIterator;
		}
 public void Refresh()
 {
     this.cache.Clear();
     this.changedFiles = null;
     this.repositoryGraph = null;
     this.head = null;
     this.remotes = null;
     this.configs = null;
     if (!string.IsNullOrEmpty(initFolder))
     {
         try
         {
             this.repository = Open(new DirectoryInfo(initFolder));
             if (this.repository != null)
             {
                 head = repository.Resolve(Constants.HEAD);
                 if (repository.IsBare)
                     throw new NoWorkTreeException();
             }
         }
         catch (Exception ex)
         {
             this.repository = null;
             Log.WriteLine("Refresh: {0}\r\n{1}", this.initFolder, ex.ToString());
         }
     }
 }
        public void Refresh()
        {
            this.cache.Clear();
            this.changedFiles = null;
            this.repositoryGraph = null;

            if (!string.IsNullOrEmpty(initFolder))
            {
                try
                {
                    this.repository = Git.Open(initFolder).GetRepository();

                    if (this.repository != null)
                    {
                        var id = repository.Resolve(Constants.HEAD);
                        //var commit = repository.MapCommit(id);
                        //this.commitTree = (commit != null ? commit.TreeEntry : new Tree(repository));
                        if (id == null)
                        {
                            this.commitTree = new Tree(repository);
                        }
                        else
                        {
                            var treeId = ObjectId.FromString(repository.Open(id).GetBytes(), 5);
                            this.commitTree = new Tree(repository, treeId, repository.Open(treeId).GetBytes());
                        }
                        this.index = repository.GetIndex();
                        this.index.RereadIfNecessary();

                        ignoreRules = File.ReadAllLines(Path.Combine(this.initFolder, Constants.GITIGNORE_FILENAME))
                                          .Where(line => !line.StartsWith("#") && line.Trim().Length > 0)
                                          .Select(line => new IgnoreRule(line)).ToList();
                    }
                }
                catch (Exception ex)
                {
                }
            }
        }
		/// <summary>Construct remote ref update request by providing an update specification.
		/// 	</summary>
		/// <remarks>
		/// Construct remote ref update request by providing an update specification.
		/// Object is created with default
		/// <see cref="Status.NOT_ATTEMPTED">Status.NOT_ATTEMPTED</see>
		/// status and no
		/// message.
		/// </remarks>
		/// <param name="localDb">local repository to push from.</param>
		/// <param name="srcRef">
		/// source revision - any string resolvable by
		/// <see cref="NGit.Repository.Resolve(string)">NGit.Repository.Resolve(string)</see>
		/// . This resolves to the new
		/// object that the caller want remote ref to be after update. Use
		/// null or
		/// <see cref="NGit.ObjectId.ZeroId()">NGit.ObjectId.ZeroId()</see>
		/// string for delete request.
		/// </param>
		/// <param name="remoteName">
		/// full name of a remote ref to update, e.g. "refs/heads/master"
		/// (no wildcard, no short name).
		/// </param>
		/// <param name="forceUpdate">
		/// true when caller want remote ref to be updated regardless
		/// whether it is fast-forward update (old object is ancestor of
		/// new object).
		/// </param>
		/// <param name="localName">
		/// optional full name of a local stored tracking branch, to
		/// update after push, e.g. "refs/remotes/zawir/dirty" (no
		/// wildcard, no short name); null if no local tracking branch
		/// should be updated.
		/// </param>
		/// <param name="expectedOldObjectId">
		/// optional object id that caller is expecting, requiring to be
		/// advertised by remote side before update; update will take
		/// place ONLY if remote side advertise exactly this expected id;
		/// null if caller doesn't care what object id remote side
		/// advertise. Use
		/// <see cref="NGit.ObjectId.ZeroId()">NGit.ObjectId.ZeroId()</see>
		/// when expecting no
		/// remote ref with this name.
		/// </param>
		/// <exception cref="System.IO.IOException">
		/// when I/O error occurred during creating
		/// <see cref="TrackingRefUpdate">TrackingRefUpdate</see>
		/// for local tracking branch or srcRef
		/// can't be resolved to any object.
		/// </exception>
		/// <exception cref="System.ArgumentException">if some required parameter was null</exception>
		public RemoteRefUpdate(Repository localDb, string srcRef, string remoteName, bool
			 forceUpdate, string localName, ObjectId expectedOldObjectId)
		{
			if (remoteName == null)
			{
				throw new ArgumentException(JGitText.Get().remoteNameCantBeNull);
			}
			this.srcRef = srcRef;
			this.newObjectId = (srcRef == null ? ObjectId.ZeroId : localDb.Resolve(srcRef));
			if (newObjectId == null)
			{
				throw new IOException(MessageFormat.Format(JGitText.Get().sourceRefDoesntResolveToAnyObject
					, srcRef));
			}
			this.remoteName = remoteName;
			this.forceUpdate = forceUpdate;
			if (localName != null && localDb != null)
			{
				trackingRefUpdate = new TrackingRefUpdate(localDb, localName, remoteName, true, newObjectId
					, "push");
			}
			else
			{
				trackingRefUpdate = null;
			}
			this.localDb = localDb;
			this.expectedOldObjectId = expectedOldObjectId;
			this.status = RemoteRefUpdate.Status.NOT_ATTEMPTED;
		}