public void GetCommitChanges_Modifications()
        {
            var commit       = "c6798c34577";
            var changedFiles = new [] {
                "EditActions.cs",
                "SourceEditorView.cs",
                "SourceEditorWidget.cs",
                "DeleteActions.cs",
                "DocumentUpdateRequest.cs",
                "FoldMarkerMargin.cs",
                "HeightTree.cs",
                "LineSplitter.cs",
                "TextDocument.cs",
                "TextEditor.cs",
                "TextViewMargin.cs",
            };

            var changes = GitUtil.CompareCommits(repo, repo.Resolve(commit), repo.Resolve(commit + "^")).ToArray();

            Assert.AreEqual(11, changes.Length, "#1");

            foreach (var file in changedFiles)
            {
                Assert.IsTrue(changes.Any(f => f.GetNewPath().EndsWith(".cs")), "#2." + file);
            }
        }
Example #2
0
        public Stash Create(string message)
        {
            UserConfig config = _repo.GetConfig().Get(UserConfig.KEY);
            RevWalk    rw     = new RevWalk(_repo);
            ObjectId   headId = _repo.Resolve(Constants.HEAD);
            var        parent = rw.ParseCommit(headId);

            PersonIdent author = new PersonIdent(config.GetAuthorName() ?? "unknown", config.GetAuthorEmail() ?? "unknown@(none).");

            if (string.IsNullOrEmpty(message))
            {
                // Use the commit summary as message
                message = parent.Abbreviate(7).ToString() + " " + parent.GetShortMessage();
                int i = message.IndexOfAny(new char[] { '\r', '\n' });
                if (i != -1)
                {
                    message = message.Substring(0, i);
                }
            }

            // Create the index tree commit
            ObjectInserter inserter = _repo.NewObjectInserter();
            DirCache       dc       = _repo.ReadDirCache();
            var            tree_id  = dc.WriteTree(inserter);

            inserter.Release();

            string   commitMsg   = "index on " + _repo.GetBranch() + ": " + message;
            ObjectId indexCommit = GitUtil.CreateCommit(_repo, commitMsg + "\n", new ObjectId[] { headId }, tree_id, author, author);

            // Create the working dir commit
            tree_id   = WriteWorkingDirectoryTree(parent.Tree, dc);
            commitMsg = "WIP on " + _repo.GetBranch() + ": " + message;
            var wipCommit = GitUtil.CreateCommit(_repo, commitMsg + "\n", new ObjectId[] { headId, indexCommit }, tree_id, author, author);

            string   prevCommit = null;
            FileInfo sf         = StashRefFile;

            if (sf.Exists)
            {
                prevCommit = File.ReadAllText(sf.FullName).Trim(' ', '\t', '\r', '\n');
            }

            Stash s = new Stash(prevCommit, wipCommit.Name, author, commitMsg);

            FileInfo stashLog = StashLogFile;

            File.AppendAllText(stashLog.FullName, s.FullLine + "\n");
            File.WriteAllText(sf.FullName, s.CommitId + "\n");

            // Wipe all local changes
            GitUtil.HardReset(_repo, Constants.HEAD);

            s.StashCollection = this;
            return(s);
        }
Example #3
0
 void CheckSensitive()
 {
     if (!String.IsNullOrWhiteSpace(tagNameEntry.Text) && GitUtil.IsValidBranchName(tagNameEntry.Text) &&
         revisionList.SelectedRow != -1)
     {
         buttonOk.Sensitive = true;
         return;
     }
     buttonOk.Sensitive = false;
 }
Example #4
0
        internal MergeCommandResult Apply(Stash stash)
        {
            ObjectId  cid     = _repo.Resolve(stash.CommitId);
            RevWalk   rw      = new RevWalk(_repo);
            RevCommit wip     = rw.ParseCommit(cid);
            RevCommit oldHead = wip.Parents.First();

            rw.ParseHeaders(oldHead);
            return(GitUtil.MergeTrees(_repo, oldHead, wip, "Stash", false));
        }
Example #5
0
        static void OnSolutionSaved(object o, EventArgs a)
        {
            Solution sol = (Solution)o;

            sol.Saved -= OnSolutionSaved;
            GitUtil.Init(sol.BaseDirectory, null, null);

            GitRepository gitRepo = new GitRepository(sol.BaseDirectory, null);

            gitRepo.Add(sol.GetItemFiles(true).ToArray(), false, new MonoDevelop.Core.ProgressMonitoring.NullProgressMonitor());
        }
        public void GetCommitChanges_AddedRemoved()
        {
            var commit  = "9ed729ee";
            var changes = GitUtil.CompareCommits(repo, repo.Resolve(commit), repo.Resolve(commit + "^")).ToArray();

            var add    = changes.Where(c => c.GetNewPath().EndsWith("DocumentLine.cs")).First();
            var remove = changes.Where(c => c.GetOldPath().EndsWith("LineSegment.cs")).First();

            Assert.AreEqual(NGit.Diff.DiffEntry.ChangeType.ADD, add.GetChangeType(), "#1");
            Assert.AreEqual("/dev/null", add.GetOldPath(), "#2");
            Assert.AreEqual(NGit.Diff.DiffEntry.ChangeType.DELETE, remove.GetChangeType(), "#3");
            Assert.AreEqual("/dev/null", remove.GetNewPath(), "#4");
        }
Example #7
0
        internal MergeCommandResult Apply(ProgressMonitor monitor, Stash stash)
        {
            monitor.Start(1);
            monitor.BeginTask("Applying stash", 100);
            ObjectId  cid     = _repo.Resolve(stash.CommitId);
            RevWalk   rw      = new RevWalk(_repo);
            RevCommit wip     = rw.ParseCommit(cid);
            RevCommit oldHead = wip.Parents.First();

            rw.ParseHeaders(oldHead);
            MergeCommandResult res = GitUtil.MergeTrees(monitor, _repo, oldHead, wip, "Stash", false);

            monitor.EndTask();
            return(res);
        }
Example #8
0
        RevCommit[] GetBlameForFile(string revision, string filePath)
        {
            RevCommit[] blame = null;
            string      path  = PROJECT_ROOT + filePath;
            string      key   = path + revision;

            blames.TryGetValue(key, out blame);

            if (blame == null)
            {
                ObjectId  objectId = repo.Resolve(revision);
                RevCommit commit   = walker.ParseCommit(objectId);
                blame = GitUtil.Blame(repo, commit, new FileInfo(path).FullName);
                blames.Add(key, blame);
            }

            return(blame);
        }
Example #9
0
        public static IEnumerable <DiffEntry> GetChangedFiles(NGit.Repository repo, string refRev)
        {
            // Get a list of files that are different in the target branch
            RevWalk  rw          = new RevWalk(repo);
            ObjectId remCommitId = repo.Resolve(refRev);

            if (remCommitId == null)
            {
                return(null);
            }
            RevCommit remCommit = rw.ParseCommit(remCommitId);

            ObjectId headId = repo.Resolve(Constants.HEAD);

            if (headId == null)
            {
                return(null);
            }
            RevCommit headCommit = rw.ParseCommit(headId);

            return(GitUtil.CompareCommits(repo, headCommit, remCommit));
        }
Example #10
0
        void UpdateStatus()
        {
            comboSources.Sensitive = checkTrack.Active;
            buttonOk.Sensitive     = entryName.Text.Length > 0;
            if (oldName != entryName.Text && repo.GetBranches().Any(b => b.Name == entryName.Text))
            {
                labelError.Markup = "<span color='red'>" + GettextCatalog.GetString("A branch with this name already exists") + "</span>";
                labelError.Show();
                buttonOk.Sensitive = false;
            }
            else if (!GitUtil.IsValidBranchName(entryName.Text))
            {
                labelError.Markup = "<span color='red'>" + GettextCatalog.GetString(@"A branch name can not:
Start with '.' or end with '/' or '.lock'
Contain a ' ', '..', '~', '^', ':', '\', '?', '['") + "</span>";
                labelError.Show();
                buttonOk.Sensitive = false;
            }
            else
            {
                labelError.Hide();
            }
        }
Example #11
0
 void CreateGitRepository(FilePath solutionPath)
 {
     using (var repo = GitUtil.Init(solutionPath, null))
         LibGit2Sharp.Commands.Stage(repo, "*");
 }
Example #12
0
 public static TreeChanges GetChangedFiles(LibGit2Sharp.Repository repo, string refRev)
 {
     return(GitUtil.CompareCommits(repo, repo.Lookup <Commit> (refRev), repo.Head.Tip));
 }
Example #13
0
 void CreateGitRepository(FilePath solutionPath)
 {
     using (var repo = GitUtil.Init(solutionPath, null))
         repo.Stage("*");
 }
Example #14
0
 void CreateGitRepository(FilePath solutionPath)
 {
     using (var repo = GitUtil.Init(solutionPath, null))
         repo.Stage("*", new LibGit2Sharp.StageOptions());
 }