public GitRepository(TextWriter stdout, string gitDir, IContainer container) : base(stdout) { _container = container; GitDir = gitDir; _repository = new Repository(new DirectoryInfo(gitDir)); }
/// <summary> /// Parsed reflog entry. /// </summary> public ReflogReader(Repository db, string refName) { _logName = new FileInfo( Path.Combine( db.Directory.FullName, Path.Combine("logs", refName)).Replace('/', Path.DirectorySeparatorChar)); }
public IgnoreHandler(Repository repo) { if (repo == null) { throw new ArgumentNullException("repo"); } _repo = repo; try { string excludeFile = repo.Config.getCore().getExcludesFile(); if (!string.IsNullOrEmpty(excludeFile)) { ReadPatternsFromFile(Path.Combine(repo.WorkingDirectory.FullName, excludeFile), _excludePatterns); } } catch (Exception) { //optional } try { ReadPatternsFromFile(Path.Combine(repo.Directory.FullName, "info/exclude"), _excludePatterns); } catch (Exception) { // optional } }
/// <summary> /// Construct an object writer for the specified repository. /// </summary> /// <param name="repo"> </param> public ObjectWriter(Repository repo) { _r = repo; _buf = new byte[0x2000]; _md = new MessageDigest(); _def = new Deflater(_r.Config.getCore().getCompression()); }
public static void close(Repository db) { if (db == null) throw new System.ArgumentNullException ("db"); Cache.unregisterRepository(FileKey.exact(db.Directory)); }
public void Checked_cloned_local_dotGit_suffixed_repo() { //setup of .git directory var resource = new DirectoryInfo(PathUtil.Combine(Path.Combine(Environment.CurrentDirectory, "Resources"), "OneFileRepository")); var tempRepository = new DirectoryInfo(Path.Combine(trash.FullName, "OneFileRepository" + Path.GetRandomFileName() + Constants.DOT_GIT_EXT)); CopyDirectory(resource.FullName, tempRepository.FullName); var repositoryPath = new DirectoryInfo(Path.Combine(tempRepository.FullName, Constants.DOT_GIT)); Directory.Move(repositoryPath.FullName + "ted", repositoryPath.FullName); using (var repo = new Repository(repositoryPath.FullName)) { Assert.IsTrue(Repository.IsValid(repo.Directory)); Commit headCommit = repo.Head.CurrentCommit; Assert.AreEqual("f3ca78a01f1baa4eaddcc349c97dcab95a379981", headCommit.Hash); } string toPath = Path.Combine(trash.FullName, "to.git"); using (var repo = Git.Clone(repositoryPath.FullName, toPath)) { Assert.IsTrue(Repository.IsValid(repo.Directory)); Commit headCommit = repo.Head.CurrentCommit; Assert.AreEqual("f3ca78a01f1baa4eaddcc349c97dcab95a379981", headCommit.Hash); } }
public RepositoryConfig(Repository repo) : this(SystemReader.getInstance().openUserConfig(), new FileInfo(Path.Combine(repo.Directory.FullName, "config"))) { if (repo == null) throw new System.ArgumentNullException ("repo"); }
public RefDatabase(Repository repo) { Repository = repo; _gitDir = repo.Directory; _refsDir = PathUtil.CombineDirectoryPath(_gitDir, "refs"); _packedRefsFile = PathUtil.CombineFilePath(_gitDir, "packed-refs"); ClearCache(); }
/// <summary> /// Create a checkout class for checking out one tree, merging with the index /// </summary> /// <param name="repo"> </param> /// <param name="root"> workdir </param> /// <param name="index"> current index </param> /// <param name="merge"> tree to check out </param> public WorkDirCheckout(Repository repo, DirectoryInfo root, GitIndex index, Tree merge) : this() { this._repo = repo; this._root = root; this._index = index; this._merge = merge; }
internal WorkDirCheckout(Repository repo, DirectoryInfo workDir, GitIndex oldIndex, GitIndex newIndex) : this() { _repo = repo; _root = workDir; _index = oldIndex; _merge = repo.MapTree(newIndex.writeTree()); }
private readonly int tzOffset; // offset in minutes to UTC #endregion Fields #region Constructors /// <summary> /// Creates new PersonIdent from config info in repository, with current time. /// This new PersonIdent gets the info from the default committer as available /// from the configuration. /// </summary> /// <param name="repo"></param> public PersonIdent(Repository repo) { RepositoryConfig config = repo.Config; Name = config.getCommitterName(); EmailAddress = config.getCommitterEmail(); When = SystemReader.getInstance().getCurrentTime(); tzOffset = SystemReader.getInstance().getTimezone(When); }
public void AlternativeCallbackApiTest() { using (var repo = new Repository(trash.FullName)) { repo.Head.Reset(ResetBehavior.Mixed); writeTrashFile("untracked", ""); writeTrashFile("added", ""); repo.Index.Add("added"); writeTrashFile("a/a1", "modified"); repo.Index.AddContent("a/a1.txt", "staged"); repo.Index.Remove("b/b2.txt"); var status = repo.Status; Assert.AreEqual(1, status.Added.Count); Assert.AreEqual(1, status.Staged.Count); Assert.AreEqual(6, status.Missing.Count); Assert.AreEqual(1, status.Modified.Count); Assert.AreEqual(1, status.Removed.Count); Assert.AreEqual(1, status.Untracked.Count); var stati = new List<PathStatus>(); var s = new RepositoryStatus(repo, new RepositoryStatusOptions { PerPathNotificationCallback = path_status => { stati.Add(path_status); switch (path_status.WorkingPathStatus) { case WorkingPathStatus.Missing: Assert.IsTrue(status.Missing.Contains(path_status.Path)); break; case WorkingPathStatus.Modified: Assert.IsTrue(status.Modified.Contains(path_status.Path)); break; case WorkingPathStatus.Untracked: Assert.IsTrue(status.Untracked.Contains(path_status.Path)); break; } switch (path_status.IndexPathStatus) { case IndexPathStatus.Added: Assert.IsTrue(status.Added.Contains(path_status.Path)); break; case IndexPathStatus.Removed: Assert.IsTrue(status.Removed.Contains(path_status.Path)); break; case IndexPathStatus.Staged: Assert.IsTrue(status.Staged.Contains(path_status.Path)); break; } } }); var dict = stati.ToDictionary(p => p.Path); Assert.IsTrue(dict.ContainsKey("untracked")); Assert.IsTrue(dict.ContainsKey("added")); Assert.IsTrue(dict.ContainsKey("a/a1")); Assert.IsTrue(dict.ContainsKey("a/a1.txt")); Assert.IsTrue(dict.ContainsKey("b/b2.txt")); } }
/// <summary> /// Parsed reflog entry. /// </summary> public ReflogReader(Repository db, string refName) { if (db == null) throw new ArgumentNullException ("db"); _logName = new FileInfo( Path.Combine( db.Directory.FullName, Path.Combine("logs", refName)).Replace('/', Path.DirectorySeparatorChar)); }
/// <summary> * The constructor from object identifier /// </summary> /// <param name="base">the base configuration file </param> /// <param name="r">the repository</param> /// <param name="objectid">the object identifier</param> /// <exception cref="IOException"> /// the blob cannot be read from the repository. </exception> /// <exception cref="ConfigInvalidException"> /// the blob is not a valid configuration format. /// </exception> public BlobBasedConfig(Config @base, Repository r, ObjectId objectid) : base(@base) { ObjectLoader loader = r.OpenBlob(objectid); if (loader == null) { throw new IOException("Blob not found: " + objectid); } fromText(RawParseUtils.decode(loader.Bytes)); }
public RepositoryWalker(CoreRepository repo) { if (repo == null) { throw new ArgumentNullException(nameof(repo)); } _walker = new RevWalk(repo); _assistantWalker = new RevWalk(repo); _initCommit = new RevCommit(repo.Head.ObjectId); }
private IEnumerable <string> GetPackRefs(GitSharp.Core.Repository repository) { var packDir = repository.ObjectsDirectory.GetDirectories().SingleOrDefault(x => x.Name == "pack"); if (packDir == null) { return(Enumerable.Empty <string>()); } return(packDir.GetFiles("*.pack").Select(x => x.Name).ToList()); }
public GitRepository(TextWriter stdout, string gitDir, IContainer container, Globals globals) : base(stdout, container) { _container = container; _globals = globals; DirectoryInfo GitDirectoryInfo = GitHelpers.ResolveRepositoryLocation(); GitDir = GitDirectoryInfo.ToString(); _repository = new Repository(GitDirectoryInfo); }
public void TracksAddedFiles() { //setup of .git directory var resource = new DirectoryInfo(Path.Combine(Path.Combine(Environment.CurrentDirectory, "Resources"), "CorruptIndex")); var tempRepository = new DirectoryInfo(Path.Combine(trash.FullName, "CorruptIndex" + Path.GetRandomFileName())); CopyDirectory(resource.FullName, tempRepository.FullName); var repositoryPath = new DirectoryInfo(Path.Combine(tempRepository.FullName, Constants.DOT_GIT)); Directory.Move(repositoryPath.FullName + "ted", repositoryPath.FullName); using (var repository = new Repository(repositoryPath.FullName)) { var status = repository.Status; Assert.IsTrue(status.AnyDifferences); Assert.AreEqual(1, status.Added.Count); Assert.IsTrue(status.Added.Contains("b.txt")); // the file already exists in the index (eg. has been previously git added) Assert.AreEqual(0, status.Staged.Count); Assert.AreEqual(0, status.Missing.Count); Assert.AreEqual(0, status.Modified.Count); Assert.AreEqual(0, status.Removed.Count); Assert.AreEqual(0, status.Untracked.Count); string filepath = Path.Combine(repository.WorkingDirectory, "c.txt"); writeTrashFile(filepath, "c"); repository.Index.Add(filepath); status.Update(); Assert.IsTrue(status.AnyDifferences); Assert.AreEqual(2, status.Added.Count); Assert.IsTrue(status.Added.Contains("b.txt")); Assert.IsTrue(status.Added.Contains("c.txt")); Assert.AreEqual(0, status.Staged.Count); Assert.AreEqual(0, status.Missing.Count); Assert.AreEqual(0, status.Modified.Count); Assert.AreEqual(0, status.Removed.Count); Assert.AreEqual(0, status.Untracked.Count); repository.Commit("after that no added files should remain", Author.Anonymous); status.Update(); Assert.AreEqual(0, status.Added.Count); Assert.AreEqual(0, status.Staged.Count); Assert.AreEqual(0, status.Missing.Count); Assert.AreEqual(0, status.Modified.Count); Assert.AreEqual(0, status.Removed.Count); Assert.AreEqual(0, status.Untracked.Count); Assert.AreEqual(0, status.Untracked.Count); } }
public RepositoryWalker(CoreRepository repo) { if (repo == null) { throw new ArgumentNullException(nameof(repo)); } _walker = new RevWalk(repo); _assistantWalker = new RevWalk(repo); _initCommit = new RevCommit(repo.Head.ObjectId); }
/// <summary> * The constructor from object identifier /// </summary> /// <param name="base">the base configuration file </param> /// <param name="repo">the repository</param> /// <param name="objectid">the object identifier</param> /// <exception cref="IOException"> /// the blob cannot be read from the repository. </exception> /// <exception cref="ConfigInvalidException"> /// the blob is not a valid configuration format. /// </exception> public BlobBasedConfig(Config @base, Repository repo, ObjectId objectid) : base(@base) { if (repo == null) { throw new System.ArgumentNullException("repo"); } ObjectLoader loader = repo.OpenBlob(objectid); if (loader == null) { throw new IOException("Blob not found: " + objectid); } fromText(RawParseUtils.decode(loader.Bytes)); }
/** * Construct a Tag representing an existing with a known name referencing an known object. * This could be either a simple or annotated tag. * * @param db {@link Repository} * @param id target id. * @param refName tag name or null * @param raw data of an annotated tag. */ public Tag(Repository db, ObjectId id, string refName, byte[] raw) { Repository = db; if (raw != null) { TagId = id; Id = ObjectId.FromString(raw, 7); } else Id = id; if (refName != null && refName.StartsWith("refs/tags/")) refName = refName.Substring(10); TagName = refName; this.raw = raw; }
public override void Execute() { if (Source.Length <= 0) { throw new ArgumentNullException("Repository", "fatal: You must specify a repository to clone."); } URIish source = new URIish(Source); if (Mirror) { Bare = true; } if (Bare) { if (OriginName != null) { throw new ArgumentException("Bare+Origin", "--bare and --origin " + OriginName + " options are incompatible."); } NoCheckout = true; } if (OriginName == null) { OriginName = "origin"; } var repo = new GitSharp.Core.Repository(new DirectoryInfo(ActualDirectory)); repo.Create(Bare); repo.Config.setBoolean("core", null, "bare", Bare); repo.Config.save(); Repository = new Repository(repo); if (!Quiet) { OutputStream.WriteLine("Initialized empty Git repository in " + repo.Directory.FullName); OutputStream.Flush(); } saveRemote(source); FetchResult r = runFetch(); GitSharp.Core.Ref branch = guessHEAD(r); if (!NoCheckout) { doCheckout(branch); } }
private void WriteInfoPacks(IEnumerable <string> packs, GitSharp.Core.Repository repository) { var w = new StringBuilder(); foreach (string pack in packs) { w.Append("P "); w.Append(pack); w.Append('\n'); } var infoPacksPath = Path.Combine(repository.ObjectsDirectory.FullName, "info/packs"); var encoded = Encoding.ASCII.GetBytes(w.ToString()); using (Stream fs = File.Create(infoPacksPath)) { fs.Write(encoded, 0, encoded.Length); } }
public void CanReadFromMsysGitJapaneseRepository() { //setup of .git directory var resource = new DirectoryInfo(Path.Combine(Path.Combine(Environment.CurrentDirectory, "Resources"), "JapaneseRepo")); var tempRepository = new DirectoryInfo(Path.Combine(trash.FullName, "JapaneseRepo" + Path.GetRandomFileName())); CopyDirectory(resource.FullName, tempRepository.FullName); var repositoryPath = new DirectoryInfo(Path.Combine(tempRepository.FullName, Constants.DOT_GIT)); Directory.Move(repositoryPath.FullName + "ted", repositoryPath.FullName); using (Repository repo = new Repository(tempRepository.FullName)) { string commitHash = "24ed0e20ceff5e2cdf768345b6853213f840ff8f"; var commit = new Commit(repo, commitHash); Assert.AreEqual("コミットのメッセージも日本語でやてみました。\n", commit.Message); } }
public void CanAddAFileToAMSysGitIndexWhereAFileIsAlreadyWaitingToBeCommitted() { //setup of .git directory var resource = new DirectoryInfo(Path.Combine(Path.Combine(Environment.CurrentDirectory, "Resources"), "CorruptIndex")); var tempRepository = new DirectoryInfo(Path.Combine(trash.FullName, "CorruptIndex" + Path.GetRandomFileName())); CopyDirectory(resource.FullName, tempRepository.FullName); var repositoryPath = new DirectoryInfo(Path.Combine(tempRepository.FullName, ".git")); Directory.Move(repositoryPath.FullName + "ted", repositoryPath.FullName); var repository = new Repository(repositoryPath); GitIndex index = repository.Index; Assert.IsNotNull(index); writeTrashFile(Path.Combine(repository.WorkingDirectory.FullName, "c.txt"), "c"); var tree = new Tree(repository); index.add(repository.WorkingDirectory, new FileInfo(Path.Combine(repository.WorkingDirectory.FullName, "c.txt"))); var diff = new IndexDiff(tree, index); diff.Diff(); index.write(); Assert.AreEqual(3, diff.Added.Count); Assert.IsTrue(diff.Added.Contains("a.txt")); Assert.IsTrue(diff.Added.Contains("b.txt")); Assert.IsTrue(diff.Added.Contains("c.txt")); Assert.AreEqual(0, diff.Changed.Count); Assert.AreEqual(0, diff.Modified.Count); Assert.AreEqual(0, diff.Removed.Count); }
public void CanReadMsysgitIndex() { //setup of .git directory var resource = new DirectoryInfo(Path.Combine(Path.Combine(Environment.CurrentDirectory, "Resources"), "OneFileRepository")); var tempRepository = new DirectoryInfo(Path.Combine(trash.FullName, "OneFileRepository" + Path.GetRandomFileName())); CopyDirectory(resource.FullName, tempRepository.FullName); var repositoryPath = new DirectoryInfo(Path.Combine(tempRepository.FullName, ".git")); Directory.Move(repositoryPath.FullName + "ted", repositoryPath.FullName); var repository = new Repository(repositoryPath); GitIndex index = repository.Index; Assert.IsNotNull(index); List<GitIndex.Entry> entries = index.Members.ToList(); Assert.AreEqual(1, entries.Count); GitIndex.Entry entry = entries[0]; Assert.AreEqual("dummy.txt", entry.Name); Ref headRef = repository.Head; Assert.AreEqual("refs/heads/master", headRef.Name); Assert.AreEqual("f3ca78a01f1baa4eaddcc349c97dcab95a379981", headRef.ObjectId.Name); object obj = repository.MapObject(headRef.ObjectId, headRef.OriginalName); Assert.IsInstanceOfType(typeof(Commit), obj); var commit = (Commit) obj; Assert.AreEqual("f3ca78a01f1baa4eaddcc349c97dcab95a379981", commit.CommitId.Name); Assert.AreEqual(commit.Committer, commit.Author); Assert.AreEqual("nulltoken <*****@*****.**> 1255117188 +0200", commit.Committer.ToExternalString()); Assert.AreEqual(0, commit.ParentIds.Length); }
public GitRepository(TextWriter stdout, string gitDir) : base(stdout) { GitDir = gitDir; _repository = new Repository(new DirectoryInfo(gitDir)); }
/// <summary> /// Create a checkout class for merging and checking our two trees and the index. /// </summary> /// <param name="repo"> </param> /// <param name="root"> workdir </param> /// <param name="head"> </param> /// <param name="index"> </param> /// <param name="merge"> </param> public WorkDirCheckout(Repository repo, DirectoryInfo root, Core.Tree head, GitIndex index, Core.Tree merge) : this(repo, root, index, merge) { this._head = head; }
public void UntrackedFiles() { using (var repo = new Repository(trash.FullName)) { var a = writeTrashFile("untracked.txt", ""); var b = writeTrashFile("someDirectory/untracked2.txt", ""); repo.Index.Add(writeTrashFile("untracked2.txt", "").FullName); // <-- adding a file with same name in higher directory to test the file name comparison. var status = repo.Status; Assert.AreEqual(2, status.Untracked.Count); Assert.IsTrue(status.Untracked.Contains("untracked.txt")); Assert.IsTrue(status.Untracked.Contains("someDirectory/untracked2.txt")); Assert.IsTrue(status.Added.Contains("untracked2.txt")); Assert.AreEqual(0, status.Staged.Count); Assert.AreEqual(0, status.Missing.Count); Assert.AreEqual(0, status.Modified.Count); Assert.AreEqual(8, status.Removed.Count); } }
public void IgnoreUntrackedFilesAndDirectories() { using (var repo = new Repository(trash.FullName)) { repo.Head.Reset(ResetBehavior.Hard); writeTrashFile("untracked.txt", ""); writeTrashFile("image.png", ""); writeTrashFile("someDirectory/untracked2.txt", ""); writeTrashFile("someDirectory/untracked", ""); writeTrashFile("some/other/directory/.svn/format", ""); writeTrashFile("some/other/README", ""); writeTrashFile("some/other/directory/README", ""); // ignore patterns: writeTrashFile(".gitignore", "*.txt\n.svn"); writeTrashFile("some/other/.gitignore", "README\n"); var status = repo.Status; Assert.IsTrue(status.Untracked.Contains("image.png")); Assert.IsTrue(status.Untracked.Contains("someDirectory/untracked")); Assert.AreEqual(0, status.Added.Count); Assert.AreEqual(0, status.Staged.Count); Assert.AreEqual(0, status.Missing.Count); Assert.AreEqual(0, status.Modified.Count); Assert.AreEqual(0, status.Removed.Count); Assert.AreEqual(0, status.MergeConflict.Count); Assert.AreEqual(4, status.Untracked.Count); writeTrashFile(".gitignore", "other"); writeTrashFile("some/other/.gitignore", ""); status.Update(); Assert.IsTrue(status.Untracked.Contains("untracked.txt")); Assert.IsTrue(status.Untracked.Contains("someDirectory/untracked2.txt")); Assert.IsTrue(status.Untracked.Contains("someDirectory/untracked")); Assert.IsTrue(status.Untracked.Contains("image.png")); Assert.AreEqual(0, status.Added.Count); Assert.AreEqual(0, status.Staged.Count); Assert.AreEqual(0, status.Missing.Count); Assert.AreEqual(0, status.Modified.Count); Assert.AreEqual(0, status.Removed.Count); Assert.AreEqual(0, status.MergeConflict.Count); Assert.AreEqual(5, status.Untracked.Count); } }
internal Repository(CoreRepository repo) { //PreferredEncoding = Encoding.UTF8; _internal_repo = repo; }
/// <summary> /// Construct a Tree with a known SHA-1 under another tree. Data is not yet /// specified and will have to be loaded on demand. /// </summary> /// <param name="parent"></param> /// <param name="id"></param> /// <param name="nameUTF8"></param> public Tree(Tree parent, ObjectId id, byte[] nameUTF8) : base(parent, id, nameUTF8) { _db = parent.Repository; }
/// <summary> /// Construct a new Tree under another Tree /// </summary> /// <param name="parent"></param> /// <param name="nameUTF8"></param> public Tree(Tree parent, byte[] nameUTF8) : base(parent, null, nameUTF8) { _db = parent.Repository; _contents = EmptyTree; }
/// <summary> /// Construct a Tree object with known content and hash value /// </summary> /// <param name="repo"></param> /// <param name="id"></param> /// <param name="raw"></param> /// <exception cref="IOException"></exception> public Tree(Repository repo, ObjectId id, byte[] raw) : base(null, id, null) { _db = repo; ReadTree(raw); }
/// <summary> /// Constructor for a new Tree /// </summary> /// <param name="repo">The repository that owns the Tree.</param> public Tree(Repository repo) : base(null, null, null) { _db = repo; _contents = EmptyTree; }
/// <summary> /// Construct an object writer for the specified repository. /// </summary> /// <param name="repo"> </param> public ObjectWriter(Repository repo) { _r = repo; _buf = new byte[0x2000]; _md = Constants.newMessageDigest(); }
public SimpleRefWriter(GitSharp.Core.Repository db, IEnumerable <Ref> refs) : base(refs) { _db = db; }
/// <summary> /// Check validity of a ref name. It must not contain a character that has /// a special meaning in a Git object reference expression. Some other /// dangerous characters are also excluded. /// </summary> /// <param name="refName"></param> /// <returns> /// Returns true if <paramref name="refName"/> is a valid ref name. /// </returns> public static bool IsValidName(string refName) { return(CoreRepository.IsValidRefName(refName)); }