Beispiel #1
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);
        }
Beispiel #2
0
        public static List <string> GetConflictedFiles(NGit.Repository repo)
        {
            List <string> list     = new List <string> ();
            TreeWalk      treeWalk = new TreeWalk(repo);

            treeWalk.Reset();
            treeWalk.Recursive = true;
            DirCache dc = repo.ReadDirCache();

            treeWalk.AddTree(new DirCacheIterator(dc));
            while (treeWalk.Next())
            {
                DirCacheIterator dirCacheIterator = treeWalk.GetTree <DirCacheIterator>(0);
                var ce = dirCacheIterator.GetDirCacheEntry();
                if (ce != null && ce.Stage == 1)
                {
                    list.Add(ce.PathString);
                }
            }
            return(list);
        }
Beispiel #3
0
        public static void Checkout(NGit.Repository repo, RevCommit commit, string working_directory)
        {
            DirCacheCheckout co = new DirCacheCheckout(repo, null, repo.ReadDirCache(), commit.Tree);

            co.Checkout();
        }