Beispiel #1
0
 public DbVersioning(ParametersParser parameters)
 {
     this.parameters = parameters;
     directory       = System.IO.Path.Combine(Environment.CurrentDirectory, parameters["Folder"]);
 }
Beispiel #2
0
        static void Main(string[] args)
        {
            var parameters = new ParametersParser(args);

            if (parameters.IsMissingMandatory)
            {
                Console.WriteLine(parameters.CommandLineUse);
                Environment.Exit(0);
            }

            var db = new DbVersioning(parameters);

            try
            {
                var path = parameters["Folder"];
                if (!Directory.Exists(path))
                {
                    path = Path.Combine(Environment.CurrentDirectory, parameters["Folder"]);
                }

                var isGit = Directory.Exists(Path.Combine(path, ".git"));

                if (!isGit)
                {
                    Repository.Init(path);
                    using (var repo = new Repository(path))
                    {
                        var readmePath = Path.Combine(path, "README");
                        using (var file = File.CreateText(readmePath))
                        {
                            file.WriteLine("Db Versioning.");
                        }
                        Commands.Stage(repo, readmePath);

                        Signature author    = new Signature("Felipe Correa", "*****@*****.**", DateTime.Now);
                        Signature committer = author;

                        var committed = repo.Commit($"Initial Commit", author, committer);
                    }
                }

                using (var repo = new Repository(path))
                {
                    if (repo.Branches.Any())
                    {
                        Branch originMaster = repo.Branches["master"];
                        repo.Reset(ResetMode.Hard, originMaster.Tip);
                    }

                    db.Connect()
                    .Setup(null)
                    .Export()
                    .ShowDifference();
                    var b = 0;
                    if (repo.Diff != null && repo.Diff.Compare <TreeChanges>(repo.Head.Tip.Tree,
                                                                             DiffTargets.Index | DiffTargets.WorkingDirectory) != null)
                    {
                        Console.Clear();
                        foreach (TreeEntryChanges c in repo.Diff.Compare <TreeChanges>(repo.Head.Tip.Tree,
                                                                                       DiffTargets.Index | DiffTargets.WorkingDirectory))
                        {
                            Console.WriteLine($"File: {System.IO.Path.GetFileName(c.Path)} status is: {c.Status}");
                        }
                        Console.Write("Would you like to commit this?: [NO/yes] ");
                        var input = Console.ReadLine();
                        if (input.ToLowerInvariant().Equals("yes") || input.ToLowerInvariant().Equals("y"))
                        {
                            Console.WriteLine("Type a commit message: ");
                            var message = Console.ReadLine();
                            Commands.Stage(repo, "*");

                            Signature author    = new Signature("Felipe Correa", "*****@*****.**", DateTime.Now);
                            Signature committer = author;

                            var committed = repo.Commit($"Auto: {message}", author, committer);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }