/// <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(); }
/// <summary> /// Removes files or directories from the index which are no longer to be tracked. /// Does not delete files from the working directory. Use <seealso cref="Delete"/> to remove and delete files. /// </summary> /// <param name="paths"></param> public void Remove(params string[] paths) { GitIndex.RereadIfNecessary(); foreach (var absolute_or_relative_path in paths) { string path = absolute_or_relative_path; string relative_path = absolute_or_relative_path; if (!Path.IsPathRooted(absolute_or_relative_path)) { path = Path.Combine(_repo.WorkingDirectory, absolute_or_relative_path); } else { relative_path = Core.Util.PathUtil.RelativePath(_repo.WorkingDirectory, absolute_or_relative_path); } if (new FileInfo(path).Exists) { RemoveFile(new FileInfo(path), false); } else if (new DirectoryInfo(path).Exists) { RemoveDirectory(new DirectoryInfo(path), false); } else { GitIndex.Remove(relative_path); } } GitIndex.write(); }
/// <summary> /// Requires absolute path /// </summary> /// <param name="fileName"></param> public void UnStageFile(string fileName) { if (!this.HasGitRepository) { return; } var fileNameRel = GetRelativeFileName(fileName); if (GitBash.Exists) { if (head == null) { GitBash.Run(string.Format("rm --cached -- \"{0}\"", fileNameRel), this.GitWorkingDirectory); } else { GitBash.Run(string.Format("reset -- \"{0}\"", fileNameRel), this.GitWorkingDirectory); } } else { TreeEntry treeEntry = null; if (commitTree != null) { treeEntry = commitTree.FindBlobMember(fileNameRel); } //var index = repository.GetIndex(); //index.RereadIfNecessary(); index.Remove(repository.WorkTree, fileName); if (treeEntry != null) { index.AddEntry(treeEntry); } index.Write(); } this.cache.Remove(GetCacheKey(fileName)); this.changedFiles = null; }