Reset unstaged files.

11 views
Skip to first unread message

Gaurav Shah

unread,
Jun 21, 2011, 4:26:19 PM6/21/11
to gits...@googlegroups.com
Hi Folks,
I am creating a branch and cherry-picking commits which satisfy certain condition. I am looping through all commits and reading commit affected files to check if it satisfies a condition. For that I need to checkout commits. For some commits , when I am reading the affected files, somehow they get modified and while checking out next commit it throws an exception. I tried to reset the branch but in vain. Here is the sample code. Any suggestions??

public List<Commit> GetCommits(string keyword, Repository repo)
        {
          
                List<Commit> commitList = new List<Commit>();

                foreach (KeyValuePair<string, GitSharp.Branch> kvp in repo.Branches)
                {
                    foreach (var commit in kvp.Value.CurrentCommit.Ancestors)
                    {
                            kvp.Value.Reset(ResetBehavior.Hard);   
                            commit.Checkout();
                           
                            foreach (Change c in commit.Changes)
                            {
                                if (c.ChangeType != ChangeType.Deleted)
                                {
                                    FileInfo file = new FileInfo(workingDir + "/" + c.Path);
                                    if (ReadFile(file, keyword))
                                    {
                                        break;
                                    }
                                }
                                   
                        }
                    }

                }
                               return commitList;
                   }
FIGHT 2 LIVE & LIVE 2 WIN

Meinrad Recheis

unread,
Jun 27, 2011, 3:31:51 AM6/27/11
to gits...@googlegroups.com
Hi Gaurav,
I don't see anything wrong in your code. Can you break after the reset before the exception is thrown (if it is a deterministic problem) and check the repo (for instance using MSYS-git doing a "git status") if it has been cleanly reset? That should give us info if the problem lies in the Reset implementation or not.
Please also post the exception you are getting and the stacktrace.
Cheers,
-- henon

--
For infos about GitSharp visit http://www.eqqon.com/index.php/GitSharp
To join this group visit http://groups.google.com/group/gitsharp

Reply all
Reply to author
Forward
0 new messages