Esempio n. 1
0
 /// <summary>
 /// Adds untracked files or directories to the index and writes the index to the disk (like "git add").
 /// For tracked files that were modified, it stages the modification. Is a no-op for tracked files that were
 /// not modified.
 ///
 /// Note: Add as many files as possible by one call of this method for best performance.
 /// </summary>
 /// <param name="paths">Paths to add to the index</param>
 public void Add(params string[] paths)
 {
     GitIndex.RereadIfNecessary();
     foreach (var absolute_or_relative_path in paths)
     {
         string path = absolute_or_relative_path;
         if (!Path.IsPathRooted(absolute_or_relative_path))
         {
             path = Path.Combine(_repo.WorkingDirectory, path);
         }
         if (new FileInfo(path).Exists)
         {
             AddFile(new FileInfo(path));
         }
         else if (new DirectoryInfo(path).Exists)
         {
             AddDirectory(new DirectoryInfo(path));
         }
         else
         {
             throw new ArgumentException("File or directory at <" + path + "> doesn't seem to exist.", "path");
         }
     }
     GitIndex.write();
 }
Esempio n. 2
0
 /// <summary>
 /// Adds untracked files or directories to the index and writes the index to the disk (like "git add").
 /// For tracked files that were modified, it stages the modification. Is a no-op for tracked files that were
 /// not modified.
 ///
 /// Note: Add as many files as possible by one call of this method for best performance.
 /// </summary>
 /// <param name="paths">Paths to add to the index</param>
 public void Add(params string[] paths)
 {
     GitIndex.RereadIfNecessary();
     foreach (var path in paths)
     {
         if (new FileInfo(path).Exists)
         {
             AddFile(new FileInfo(path));
         }
         else if (new DirectoryInfo(path).Exists)
         {
             AddDirectory(new DirectoryInfo(path));
         }
         else
         {
             throw new ArgumentException("File or directory at <" + path + "> doesn't seem to exist.", "path");
         }
     }
     GitIndex.write();
 }
Esempio n. 3
0
 /// <summary>
 /// Checkout this commit into the given directory. Does not reset HEAD!
 /// </summary>
 /// <param name="working_directory">The directory to put the sources into</param>
 public void Checkout(string working_directory)
 {
     // Todo: what happens with a bare repo here ??
     if (InternalCommit == null)
         throw new InvalidOperationException("Unable to checkout this commit. It was not initialized properly (i.e. the hash is not pointing to a commit object).");
     if (working_directory == null)
         throw new ArgumentException("Path to checkout directory must not be null");
     if (new DirectoryInfo(working_directory).Exists == false)
         throw new IOException("Cannot checkout into non-existent directory: " + working_directory);
     var db = _repo._internal_repo;
     var index = new GitSharp.Core.GitIndex(db);
     CoreTree tree = InternalCommit.TreeEntry;
     var co = new GitSharp.Core.WorkDirCheckout(db, new DirectoryInfo(working_directory), index, tree);
     co.checkout();
     if (working_directory == Repository.WorkingDirectory) // we wouldn't want to write index if the checkout was not done into the working directory or if the repo is bare, right?
         index.write();
 }