public void CanCommitALittleBit() { using (var scd = new SelfCleaningDirectory()) { var dir = Repository.Init(scd.DirectoryPath); Path.IsPathRooted(dir).ShouldBeTrue(); Directory.Exists(dir).ShouldBeTrue(); using (var repo = new Repository(dir)) { string filePath = Path.Combine(repo.Info.WorkingDirectory, "new.txt"); File.WriteAllText(filePath, "null"); repo.Index.Stage("new.txt"); File.AppendAllText(filePath, "token\n"); repo.Index.Stage("new.txt"); var author = new Signature("Author N. Ame", "*****@*****.**", DateTimeOffset.Now.AddSeconds(-10)); var commit = repo.Commit(author, author, "Initial egotistic commit"); commit.Parents.Count().ShouldEqual(0); repo.Info.IsEmpty.ShouldBeFalse(); File.WriteAllText(filePath, "nulltoken commits!\n"); repo.Index.Stage("new.txt"); var author2 = new Signature(author.Name, author.Email, author.When.AddSeconds(5)); var commit2 = repo.Commit(author2, author2, "Are you trying to fork me?"); commit2.Parents.Count().ShouldEqual(1); commit2.Parents.First().Id.ShouldEqual(commit.Id); repo.CreateBranch("davidfowl-rules", commit.Id.Sha); //TODO: This cries for a shortcut method :-/ repo.Branches.Checkout("davidfowl-rules"); //TODO: This cries for a shortcut method :-/ File.WriteAllText(filePath, "davidfowl commits!\n"); var author3 = new Signature("David Fowler", "*****@*****.**", author.When.AddSeconds(2)); repo.Index.Stage("new.txt"); var commit3 = repo.Commit(author3, author3, "I'm going to branch you backwards in time!"); commit3.Parents.Count().ShouldEqual(1); commit3.Parents.First().Id.ShouldEqual(commit.Id); } } }
private static RepositoryOptions BuildFakeRepositoryOptions(SelfCleaningDirectory scd) { string confs = Path.Combine(scd.DirectoryPath, "confs"); Directory.CreateDirectory(confs); string globalLocation = Path.Combine(confs, "my-global-config"); string xdgLocation = Path.Combine(confs, "my-xdg-config"); string systemLocation = Path.Combine(confs, "my-system-config"); return(new RepositoryOptions { GlobalConfigurationLocation = globalLocation, XdgConfigurationLocation = xdgLocation, SystemConfigurationLocation = systemLocation, }); }
public void CanCreateBareRepo() { using (var scd = new SelfCleaningDirectory()) { var dir = Repository.Init(scd.DirectoryPath, true); Path.IsPathRooted(dir).ShouldBeTrue(); Directory.Exists(dir).ShouldBeTrue(); using (var repo = new Repository(dir)) { repo.Info.WorkingDirectory.ShouldBeNull(); repo.Info.Path.ShouldEqual(scd.RootedDirectoryPath + @"\"); repo.Info.IsBare.ShouldBeTrue(); AssertInitializedRepository(repo); } } }
public void CanCreateStandardRepo() { using (var scd = new SelfCleaningDirectory()) { var dir = Repository.Init(scd.DirectoryPath); Path.IsPathRooted(dir).ShouldBeTrue(); Directory.Exists(dir).ShouldBeTrue(); using (var repo = new Repository(dir)) { repo.Info.WorkingDirectory.ShouldNotBeNull(); repo.Info.Path.ShouldEqual(Path.Combine(scd.RootedDirectoryPath, ".git" + @"\")); repo.Info.IsBare.ShouldBeFalse(); AssertInitializedRepository(repo); } } }
protected string CreateConfigurationWithDummyUser(string name, string email) { SelfCleaningDirectory scd = BuildSelfCleaningDirectory(); string configFilePath = Touch(scd.DirectoryPath, "fake-config"); using (Configuration config = Configuration.BuildFrom(configFilePath)) { if (name != null) { config.Set("user.name", name); } if (email != null) { config.Set("user.email", email); } } return(configFilePath); }
protected string CreateConfigurationWithDummyUser(string name, string email) { SelfCleaningDirectory scd = BuildSelfCleaningDirectory(); Directory.CreateDirectory(scd.DirectoryPath); string configFilePath = Path.Combine(scd.DirectoryPath, "global-config"); using (Configuration config = new Configuration(configFilePath)) { if (name != null) { config.Set("user.name", name, ConfigurationLevel.Global); } if (email != null) { config.Set("user.email", email, ConfigurationLevel.Global); } } return(configFilePath); }
public RepositoryOptions BuildFakeConfigs(SelfCleaningDirectory scd) { var options = BuildFakeRepositoryOptions(scd); StringBuilder sb = new StringBuilder() .AppendFormat("[Woot]{0}", Environment.NewLine) .AppendFormat("this-rocks = global{0}", Environment.NewLine) .AppendFormat("[Wow]{0}", Environment.NewLine) .AppendFormat("Man-I-am-totally-global = 42{0}", Environment.NewLine); File.WriteAllText(options.GlobalConfigurationLocation, sb.ToString()); sb = new StringBuilder() .AppendFormat("[Woot]{0}", Environment.NewLine) .AppendFormat("this-rocks = system{0}", Environment.NewLine); File.WriteAllText(options.SystemConfigurationLocation, sb.ToString()); sb = new StringBuilder() .AppendFormat("[Woot]{0}", Environment.NewLine) .AppendFormat("this-rocks = xdg{0}", Environment.NewLine); File.WriteAllText(options.XdgConfigurationLocation, sb.ToString()); return options; }
public RepositoryOptions BuildFakeConfigs(SelfCleaningDirectory scd) { var options = BuildFakeRepositoryOptions(scd); StringBuilder sb = new StringBuilder() .AppendFormat("[Woot]{0}", Environment.NewLine) .AppendFormat("this-rocks = global{0}", Environment.NewLine) .AppendFormat("[Wow]{0}", Environment.NewLine) .AppendFormat("Man-I-am-totally-global = 42{0}", Environment.NewLine); File.WriteAllText(options.GlobalConfigurationLocation, sb.ToString()); sb = new StringBuilder() .AppendFormat("[Woot]{0}", Environment.NewLine) .AppendFormat("this-rocks = system{0}", Environment.NewLine); File.WriteAllText(options.SystemConfigurationLocation, sb.ToString()); sb = new StringBuilder() .AppendFormat("[Woot]{0}", Environment.NewLine) .AppendFormat("this-rocks = xdg{0}", Environment.NewLine); File.WriteAllText(options.XdgConfigurationLocation, sb.ToString()); return(options); }
public static void BuildFakeConfigs(IPostTestDirectoryRemover dirRemover) { var scd = new SelfCleaningDirectory(dirRemover); string global = null, xdg = null, system = null, programData = null; BuildFakeRepositoryOptions(scd, out global, out xdg, out system, out programData); StringBuilder sb = new StringBuilder() .AppendFormat("[Woot]{0}", Environment.NewLine) .AppendFormat("this-rocks = global{0}", Environment.NewLine) .AppendFormat("[Wow]{0}", Environment.NewLine) .AppendFormat("Man-I-am-totally-global = 42{0}", Environment.NewLine); File.WriteAllText(Path.Combine(global, ".gitconfig"), sb.ToString()); sb = new StringBuilder() .AppendFormat("[Woot]{0}", Environment.NewLine) .AppendFormat("this-rocks = system{0}", Environment.NewLine); File.WriteAllText(Path.Combine(system, "gitconfig"), sb.ToString()); sb = new StringBuilder() .AppendFormat("[Woot]{0}", Environment.NewLine) .AppendFormat("this-rocks = xdg{0}", Environment.NewLine); File.WriteAllText(Path.Combine(xdg, "config"), sb.ToString()); sb = new StringBuilder() .AppendFormat("[Woot]{0}", Environment.NewLine) .AppendFormat("this-rocks = programdata{0}", Environment.NewLine); File.WriteAllText(Path.Combine(programData, "config"), sb.ToString()); GlobalSettings.SetConfigSearchPaths(ConfigurationLevel.Global, global); GlobalSettings.SetConfigSearchPaths(ConfigurationLevel.Xdg, xdg); GlobalSettings.SetConfigSearchPaths(ConfigurationLevel.System, system); GlobalSettings.SetConfigSearchPaths(ConfigurationLevel.ProgramData, programData); }
public void CanLookupWhithShortIdentifers() { const string expectedAbbrevSha = "edfecad"; const string expectedSha = expectedAbbrevSha + "02d96c9dbf64f6e238c45ddcfa762eef0"; using (var scd = new SelfCleaningDirectory()) { var dir = Repository.Init(scd.DirectoryPath); using (var repo = new Repository(dir)) { string filePath = Path.Combine(repo.Info.WorkingDirectory, "new.txt"); File.WriteAllText(filePath, "one "); repo.Index.Stage(filePath); var author = Constants.Signature; var commit = repo.Commit(author, author, "Initial commit"); commit.Sha.ShouldEqual(expectedSha); var lookedUp1 = repo.Lookup(expectedSha); lookedUp1.ShouldEqual(commit); var lookedUp2 = repo.Lookup(expectedAbbrevSha); lookedUp2.ShouldEqual(commit); } } }
protected string InitNewRepository(bool isBare = false) { SelfCleaningDirectory scd = BuildSelfCleaningDirectory(); return(Repository.Init(scd.DirectoryPath, isBare)); }
public void CanListAllTagsInAEmptyRepository() { using (var scd = new SelfCleaningDirectory()) { var dir = Repository.Init(scd.DirectoryPath); using (var repo = new Repository(dir)) { repo.Info.IsEmpty.ShouldBeTrue(); repo.Tags.Count().ShouldEqual(0); } } }
private static RepositoryOptions BuildFakeRepositoryOptions(SelfCleaningDirectory scd) { string confs = Path.Combine(scd.DirectoryPath, "confs"); Directory.CreateDirectory(confs); string globalLocation = Path.Combine(confs, "my-global-config"); string xdgLocation = Path.Combine(confs, "my-xdg-config"); string systemLocation = Path.Combine(confs, "my-system-config"); return new RepositoryOptions { GlobalConfigurationLocation = globalLocation, XdgConfigurationLocation = xdgLocation, SystemConfigurationLocation = systemLocation, }; }
private RepositoryOptions BuildFakeSystemConfigFilemodeOption( SelfCleaningDirectory scd, bool value) { Directory.CreateDirectory(scd.DirectoryPath); var options = new RepositoryOptions { SystemConfigurationLocation = Path.Combine( scd.RootedDirectoryPath, "fake-system.config") }; StringBuilder sb = new StringBuilder() .AppendFormat("[core]{0}", Environment.NewLine) .AppendFormat("filemode = {1}{0}", Environment.NewLine, value); File.WriteAllText(options.SystemConfigurationLocation, sb.ToString()); return options; }
public void CreatingATagInAEmptyRepositoryThrows() { using (var scd = new SelfCleaningDirectory()) { var dir = Repository.Init(scd.DirectoryPath); using (var repo = new Repository(dir)) { Assert.Throws<ApplicationException>(() => repo.ApplyTag("mynotag")); } } }
private static RepositoryOptions BuildFakeRepositoryOptions(SelfCleaningDirectory scd, RepositoryOptions options = null) { options = options ?? new RepositoryOptions(); string confs = Path.Combine(scd.DirectoryPath, "confs"); Directory.CreateDirectory(confs); options.GlobalConfigurationLocation = Path.Combine(confs, "my-global-config"); options.XdgConfigurationLocation = Path.Combine(confs, "my-xdg-config"); options.SystemConfigurationLocation = Path.Combine(confs, "my-system-config"); return options; }
public void StagingANewFileWithAFullPathWhichEscapesOutOfTheWorkingDirThrows() { using (var scd = new SelfCleaningDirectory()) using (var path = new TemporaryCloneOfTestRepo(Constants.StandardTestRepoWorkingDirPath)) using (var repo = new Repository(path.RepositoryPath)) { var di = Directory.CreateDirectory(scd.DirectoryPath); const string filename = "unit_test.txt"; string fullPath = Path.Combine(di.FullName, filename); File.WriteAllText(fullPath, "some contents"); Assert.Throws<ArgumentException>(() => repo.Index.Stage(fullPath)); } }
public void StagingANewVersionOfAFileThenUnstagingRevertsTheBlobToTheVersionOfHead() { using (var scd = new SelfCleaningDirectory()) { string dir = Repository.Init(scd.DirectoryPath); using (var repo = new Repository(dir)) { repo.Index.Count.ShouldEqual(0); const string fileName = "myFile.txt"; var fullpath = Path.Combine(repo.Info.WorkingDirectory, fileName); const string initialContent = "Hello?"; File.AppendAllText(fullpath, initialContent); repo.Index.Stage(fileName); var blobId = repo.Index[fileName].Id; repo.Commit(Constants.Signature, Constants.Signature, "Initial commit"); repo.Index.Count.ShouldEqual(1); File.AppendAllText(fullpath, "Is there there anybody out there?"); repo.Index.Stage(fileName); repo.Index.Count.ShouldEqual(1); repo.Index[fileName].Id.ShouldNotEqual((blobId)); repo.Index.Unstage(fileName); repo.Index.Count.ShouldEqual(1); repo.Index[fileName].Id.ShouldEqual((blobId)); } } }
public void CanRenameAFile() { using (var scd = new SelfCleaningDirectory()) { string dir = Repository.Init(scd.DirectoryPath); using (var repo = new Repository(dir)) { repo.Index.Count.ShouldEqual(0); const string oldName = "polite.txt"; string oldPath = Path.Combine(repo.Info.WorkingDirectory, oldName); File.WriteAllText(oldPath, "hello test file\n", Encoding.ASCII); repo.Index.Stage(oldName); // Generated through // $ echo "hello test file" | git hash-object --stdin const string expectedHash = "88df547706c30fa19f02f43cb2396e8129acfd9b"; repo.Index[oldName].Id.Sha.ShouldEqual((expectedHash)); repo.Index.Count.ShouldEqual(1); Signature who = Constants.Signature; repo.Commit(who, who, "Initial commit"); const string newName = "being.frakking.polite.txt"; repo.Index.Move(oldName, newName); repo.Index.Count.ShouldEqual(1); repo.Index[newName].Id.Sha.ShouldEqual((expectedHash)); who = who.TimeShift(TimeSpan.FromMinutes(5)); Commit commit = repo.Commit(who, who, "Fix file name"); commit.Tree[newName].Target.Id.Sha.ShouldEqual(expectedHash); } } }