示例#1
0
 /// <summary>
 /// Unstage overwrites staged files in the index with their current version in HEAD. In case of newly added files they are removed from the index.
 /// </summary>
 /// <param name="paths">Relative paths to files you want to unstage.</param>
 public void Unstage(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 = Core.Util.PathUtil.RelativePath(_repo.WorkingDirectory, absolute_or_relative_path);
         }
         if (this[path] == null)
         {
             return;
         }
         var blob = _repo.Get <Leaf>(path);                // <--- we wouldn't want to stage something that is not representing a file
         if (blob == null)
         {
             GitIndex.Remove(path);
         }
         else
         {
             GitIndex.add(Core.Repository.GitInternalSlash(PathEncoding.GetBytes(path)), blob.RawData);
         }
     }
     GitIndex.write();
 }
示例#2
0
 /// <summary>
 /// Add a file to index (without relying on the working directory) by specifying the file's content as string.
 /// The added file doesn't need to exist in the working directory.
 /// </summary>
 /// <param name="path">Relative path in the working directory. Note: the path is encoded using PathEncoding</param>
 /// <param name="content">The content as string. Note: the content is encoded using ContentEncoding</param>
 public void AddContent(string path, string content)
 {
     AddContent(PathEncoding.GetBytes(path), ContentEncoding.GetBytes(content));
 }