public string CommitGitIgnore(string pathToGitIgnoreFile) { if (!File.Exists(pathToGitIgnoreFile)) { Trace.TraceWarning("warning: the .gitignore file specified '{0}' does not exist!", pathToGitIgnoreFile); } var gitTreeBuilder = new GitTreeBuilder(_repository.ObjectDatabase); gitTreeBuilder.Add(".gitignore", pathToGitIgnoreFile, LibGit2Sharp.Mode.NonExecutableFile); var tree = gitTreeBuilder.GetTree(); var signature = new Signature("git-tfs", "*****@*****.**", new DateTimeOffset(2000, 1, 1, 0, 0, 0, new TimeSpan(0))); var sha = _repository.ObjectDatabase.CreateCommit(signature, signature, ".gitignore", tree, new Commit[0], false).Sha; Trace.WriteLine(".gitignore commit created: " + sha); // Point our tfs remote branch to the .gitignore commit var defaultRef = ShortToTfsRemoteName("default"); _repository.Refs.Add(defaultRef, new ObjectId(sha)); // Also point HEAD to the .gitignore commit, if it isn't already. This // ensures a common initial commit for the git-tfs init --gitignore case. if (_repository.Head.CanonicalName != defaultRef) { _repository.Refs.Add(_repository.Head.CanonicalName, new ObjectId(sha)); } return(sha); }
public IGitTreeBuilder GetTreeBuilder(string commit) { if (commit == null) { var treeBuilder = new GitTreeBuilder(_repository.ObjectDatabase); if (!string.IsNullOrEmpty(_pathToGitIgnoreFile)) { treeBuilder.Add(".gitignore", _pathToGitIgnoreFile, LibGit2Sharp.Mode.NonExecutableFile); } return(treeBuilder); } else { return(new GitTreeBuilder(_repository.ObjectDatabase, _repository.Lookup <Commit>(commit).Tree)); } }
public string CommitGitIgnore(string pathToGitIgnoreFile) { if (!File.Exists(pathToGitIgnoreFile)) { Trace.TraceWarning("warning: the .gitignore file specified '{0}' does not exist!", pathToGitIgnoreFile); } var gitTreeBuilder = new GitTreeBuilder(_repository.ObjectDatabase); gitTreeBuilder.Add(".gitignore", pathToGitIgnoreFile, LibGit2Sharp.Mode.NonExecutableFile); var tree = gitTreeBuilder.GetTree(); var signature = new Signature("git-tfs", "*****@*****.**", new DateTimeOffset(2000, 1, 1, 0, 0, 0, new TimeSpan(0))); var sha = _repository.ObjectDatabase.CreateCommit(signature, signature, ".gitignore", tree, new Commit[0], false).Sha; Trace.WriteLine(".gitignore commit created: " + sha); _repository.Refs.Add(ShortToTfsRemoteName("default"), new ObjectId(sha)); _repository.Refs.Add(ShortToLocalName("master"), new ObjectId(sha)); return(sha); }
public string CommitGitIgnore(string pathToGitIgnoreFile) { if (!File.Exists(pathToGitIgnoreFile)) { Trace.TraceWarning("warning: the .gitignore file specified '{0}' does not exist!", pathToGitIgnoreFile); } _pathToGitIgnoreFile = pathToGitIgnoreFile; var gitTreeBuilder = new GitTreeBuilder(_repository.ObjectDatabase); gitTreeBuilder.Add(".gitignore", pathToGitIgnoreFile, LibGit2Sharp.Mode.NonExecutableFile); var tree = gitTreeBuilder.GetTree(); var signature = new Signature("git-tfs", "*****@*****.**", new DateTimeOffset(2000, 1, 1, 0, 0, 0, new TimeSpan(0))); var sha = _repository.ObjectDatabase.CreateCommit(signature, signature, ".gitignore", tree, new Commit[0], false).Sha; Trace.WriteLine(".gitignore commit created: " + sha); _repository.Refs.Add(ShortToTfsRemoteName("default"), new ObjectId(sha)); _repository.Refs.Add(ShortToLocalName("master"), new ObjectId(sha)); //Should add ourself the rules to the temporary rules because committing directly to the git database //prevent libgit2sharp to detect the new .gitignore file _repository.Ignore.AddTemporaryRules(File.ReadLines(pathToGitIgnoreFile)); return(sha); }