예제 #1
1
 /// <summary>
 /// Get's the latest and greatest from remote
 /// </summary>
 /// <param name="gitUser">
 /// The Git User.
 /// </param>
 /// <param name="gitPass">
 /// The Git Pass.
 /// </param>
 /// <returns>
 /// A boolean that signals success
 /// </returns>
 public bool Fetch(string gitUser, string gitPass)
 {
     log.Debug("Fetch on remote repo");
     if (File.Exists(ExternalGitPath))
     {
         string GitOutput = ExecuteGitCommand("pull");
         bool result = Regex.IsMatch(GitOutput, "\\bfatal\\b", RegexOptions.IgnoreCase);
         if (result == true)
         {
             return false;
         }
     }
     else
     {
         try
         {
             var signature = new Signature(
                 "pass4win",
                 "*****@*****.**",
                 new DateTimeOffset(2011, 06, 16, 10, 58, 27, TimeSpan.FromHours(2)));
             var fetchOptions = new FetchOptions
             {
                 CredentialsProvider =
                                            (url, user, cred) =>
                                            new UsernamePasswordCredentials
                                            {
                                                Username = gitUser,
                                                Password = gitPass
                                            }
             };
             var mergeOptions = new MergeOptions();
             var pullOptions = new PullOptions { FetchOptions = fetchOptions, MergeOptions = mergeOptions };
             this.gitRepo.Network.Pull(signature, pullOptions);
         }
         catch (Exception message)
         {
             log.Debug(message);
             return false;
         }
     }
     return true;
 }
예제 #2
0
 public MergeResult Merge(string committish, Signature merger, MergeOptions options = null)
 {
     throw new NotImplementedException();
 }
예제 #3
0
 public MergeResult Merge(Branch branch, Signature merger, MergeOptions options = null)
 {
     throw new NotImplementedException();
 }
예제 #4
0
파일: Main.cs 프로젝트: bazmecode/Pass4Win
 /// <summary>
 ///     Get's the latest and greatest from remote
 /// </summary>
 /// <returns></returns>
 public bool GitFetch()
 {
     if (Cfg["UseGitRemote"] == true && this.gitRepoOffline == false)
     {
         toolStripOffline.Visible = false;
         using (var repo = new Repository(Cfg["PassDirectory"]))
         {
             var signature = new Signature("pass4win", "*****@*****.**",
                 new DateTimeOffset(2011, 06, 16, 10, 58, 27, TimeSpan.FromHours(2)));
             var fetchOptions = new FetchOptions
             {
                 CredentialsProvider = (url, user, cred) => new UsernamePasswordCredentials
                 {
                     Username = Cfg["GitUser"],
                     Password = DecryptConfig(Cfg["GitPass"], "pass4win")
                 }
             };
             var mergeOptions = new MergeOptions();
             var pullOptions = new PullOptions
             {
                 FetchOptions = fetchOptions,
                 MergeOptions = mergeOptions
             };
             try
             {
                 repo.Network.Pull(signature, pullOptions);
             }
             catch (Exception)
             {
                 return false;
             }
         }
     }
     return true;
 }
예제 #5
0
        public MergeResult UpstreamSync()
        {
            // Need to check status before doing this
            MergeResult mergeResult;
            var mergeOptions = new MergeOptions ();
            mergeOptions.FastForwardStrategy = FastForwardStrategy.FastForwardOnly;
            var signature = new Signature ("x", "x", DateTime.Now);
            var checkoutOptions = new CheckoutOptions ();
            checkoutOptions.CheckoutModifiers = CheckoutModifiers.Force;

            try {
                Console.WriteLine ("Checkout master");
                repo.Checkout (master);
                Console.Write ("Any Key");
                Console.ReadKey ();
                Console.WriteLine ("Fetch Upstream");
                Remote remote = repo.Network.Remotes ["upstream"];
                repo.Network.Fetch (remote);
                Console.Write ("Any Key");
                Console.ReadKey ();
                Console.WriteLine ("Merge the fetched Upstream");
                mergeResult = repo.MergeFetchedRefs (signature, mergeOptions);
                Console.WriteLine (mergeResult.Status);
                Console.Write ("Any Key");
                Console.ReadKey ();
            } finally {
                Console.WriteLine ("Checkout prior head");
                repo.Checkout (head);
                Console.Write ("Any Key");
                Console.ReadKey ();
            }
            return mergeResult;
        }
예제 #6
0
파일: Main.cs 프로젝트: kageurufu/Pass4Win
        public frmMain()
        {
            InitializeComponent();
            // Checking for appsettings

            // Do we have a valid password store
            if (Properties.Settings.Default.PassDirectory == "firstrun")
            {
                if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
                {
                    Properties.Settings.Default.PassDirectory = folderBrowserDialog1.SelectedPath;
                }
                else
                {
                    MessageBox.Show("We need a place to store stuff. Restart the program and try again.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    System.Environment.Exit(1);
                }
            }

            // GPG exe location
            if (Properties.Settings.Default.GPGEXE == "firstrun")
            {
                if (openFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    Properties.Settings.Default.GPGEXE = openFileDialog1.FileName;
                }
                else
                {
                    MessageBox.Show("We really need GPG2.exe. Restart the program and try again.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    System.Environment.Exit(1);
                }
            }

            //checking git status
            if (!Repository.IsValid(Properties.Settings.Default.PassDirectory))
            {
                string value = "";
                // Do we have a remote
                if (InputBox.Show("Enter the remote git repo or blank for no remote", "Remote Git (HTTPS):", ref value) == DialogResult.OK)
                {
                    Properties.Settings.Default.GitRemote = value;
                    if (Properties.Settings.Default.GitRemote != "")
                    {
                        // Get username and password
                        value = "";
                        if (InputBox.Show("Username", "Remote Username:"******"";
                            if (InputBox.Show("Password", "Remote Password:"******"Couldn't connect to remote git repository. Restart the program and try again.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                    System.Environment.Exit(1);
                                }
                                // save encrypted version of user and pass for git
                                Properties.Settings.Default.GitUser = EncryptConfig(GitUsername, "pass4win");
                                Properties.Settings.Default.GitPass = EncryptConfig(GitPassword, "pass4win");
                            }
                        }
                    }
                }
                // Checking if the remote is cloned succesfull
                if (!Repository.IsValid(Properties.Settings.Default.PassDirectory))
                {
                    // creating new Git
                    Repository.Init(Properties.Settings.Default.PassDirectory);
                    Properties.Settings.Default.GitUser = EncryptConfig("RandomGarbage", "pass4win");
                    Properties.Settings.Default.GitPass = EncryptConfig("RandomGarbage", "pass4win");
                }
            }
            else
            {
                // so we have a repository let's load the user/pass
                if (Properties.Settings.Default.GitUser != "")
                {
                    GitUsername = DecryptConfig(Properties.Settings.Default.GitUser, "pass4win");
                    GitPassword = DecryptConfig(Properties.Settings.Default.GitPass, "pass4win");
                }
                else
                {
                    string value = "";
                    if (InputBox.Show("Username", "Remote Username:"******"";
                        if (InputBox.Show("Password", "Remote Password:"******"We really need a username. Restart the program and try again.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        System.Environment.Exit(1);
                    }
                    if (GitPassword == null)
                    {
                        MessageBox.Show("We really need a password. Restart the program and try again.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        System.Environment.Exit(1);
                    }
                    Properties.Settings.Default.GitUser = EncryptConfig(GitUsername, "pass4win");
                    Properties.Settings.Default.GitPass = EncryptConfig(GitPassword, "pass4win");
                }

                // Check if we have the latest
                using (var repo = new Repository(Properties.Settings.Default.PassDirectory))
                {
                    Signature Signature = new Signature("pass4win","*****@*****.**", new DateTimeOffset(2011, 06, 16, 10, 58, 27, TimeSpan.FromHours(2)));
                    FetchOptions fetchOptions = new FetchOptions();
                    fetchOptions.CredentialsProvider = (_url, _user, _cred) => new UsernamePasswordCredentials
                                        {
                                            Username = GitUsername,
                                            Password = GitPassword
                                        };
                    MergeOptions mergeOptions = new MergeOptions();
                    PullOptions pullOptions = new PullOptions();
                    pullOptions.FetchOptions = fetchOptions;
                    pullOptions.MergeOptions = mergeOptions;
                    MergeResult mergeResult = repo.Network.Pull(Signature, pullOptions);
                }

            }

            // Init GPG if needed
            string gpgfile = Properties.Settings.Default.PassDirectory;
            gpgfile += "\\.gpg-id";
            // Check if we need to init the directory
            if (!File.Exists(gpgfile))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(gpgfile));
                KeySelect newKeySelect = new KeySelect();
                if (newKeySelect.ShowDialog() == DialogResult.OK)
                {
                    using (StreamWriter w = new StreamWriter(gpgfile))
                    {
                        w.Write(newKeySelect.gpgkey);
                    }
                    using (var repo = new Repository(Properties.Settings.Default.PassDirectory))
                    {
                        repo.Stage(gpgfile);
                        repo.Commit("gpgid added", new Signature("pass4win", "pass4win", System.DateTimeOffset.Now), new Signature("pass4win", "pass4win", System.DateTimeOffset.Now));
                    }
                }
                else
                {
                    MessageBox.Show("Need key...... Restart the program and try again.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    System.Environment.Exit(1);
                }
            }
            // Setting the exe location for the GPG Dll
            GpgInterface.ExePath = Properties.Settings.Default.GPGEXE;

            // saving settings
            Properties.Settings.Default.Save();

            // Setting up datagrid
            dt.Columns.Add("colPath", typeof(string));
            dt.Columns.Add("colText", typeof(string));

            ListDirectory(new DirectoryInfo(Properties.Settings.Default.PassDirectory), "");

            dataPass.DataSource = dt.DefaultView;
            dataPass.Columns[0].Visible=false;
        }
예제 #7
0
        public MergeResult StalkUpTo(IReadOnlyList<Commit> commits)
        {
            var mergeFiles = new List<String> ();
            var startingCommit = head.Tip;
            var newCommits = new List<Commit> ();
            MergeResult mergeResult = null;
            var mergeOptions = new MergeOptions ();
            var signature = new Signature (userName, userEmail, DateTime.Now);
            //var checkoutOptions = new CheckoutOptions ();
            //			var commitMsg = new List<String> ();

            commitMsg = (String.Format ("Automated Stalker (StalkUpTo) merge commit from: '{0}' to: '{1}' into {2}", commits.First ().Sha.Substring (0, 6), commits.Last ().Sha.Substring (0, 6), head.Tip.Sha.Substring (0, 6)));
            //			Console.WriteLine ("Working on {0} commits", commits.Count);

            var commit = commits.Last ();
            Array.ForEach (CommitLog (commit, true).ToArray(), Console.WriteLine);

            mergeOptions.FastForwardStrategy = FastForwardStrategy.FastForwardOnly;
            mergeOptions.CommitOnSuccess = true;

            //checkoutOptions.CheckoutModifiers = CheckoutModifiers.None;
            try {
                Console.WriteLine ("Merge FF: {0} : {1}", commit.Sha.Substring (0,6), commit.MessageShort);
                mergeResult = repo.Merge (commit, signature, mergeOptions);
                var tmpMsg = mergeResult.Commit.Message;
                var commitOptions = new CommitOptions ();
                commitOptions.AmendPreviousCommit = true;
                repo.Commit (commitMsg + "\n\n" + tmpMsg, signature, commitOptions);
            } catch {
                Console.WriteLine ("Merge FF Failed: CheckoutFileConflictStrategy.Theirs");
                //commitMsg = CommitLog (commit, true, commitMsg);
                // this will happen as libgit2sharp throws ex if fast forward not possible
                // so lets get a commit message ready
                mergeFiles.AddRange (FilesToMerge (commit));

                mergeOptions.FastForwardStrategy = FastForwardStrategy.NoFastForward;
                mergeOptions.FileConflictStrategy = CheckoutFileConflictStrategy.Theirs;
                mergeOptions.CommitOnSuccess = true;
                try {
                    var fgColor = Console.ForegroundColor;
                    var bgColor = Console.BackgroundColor;
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.WriteLine ("Merging commit : {0}", commit.Sha);
                    Console.WriteLine (" - Info : {0} / {1} / {2}", commit.Author.When, commit.Author.Name, commit.Author.Email);
                    Console.WriteLine (" - Msg : {0}", commit.Message);
                    Console.ForegroundColor = fgColor;
                    Console.BackgroundColor = bgColor;
                    mergeResult = repo.Merge (commit, signature, mergeOptions);
                    var tmpMsg = mergeResult.Commit.Message;
                    var commitOptions = new CommitOptions ();
                    commitOptions.AmendPreviousCommit = true;
                    repo.Commit (commitMsg + "\n\n" + tmpMsg, signature, commitOptions);
                    //Array.ForEach (MergeResultLog (mergeResult).ToArray (), Console.WriteLine);
                } catch (Exception e) {
                    Console.WriteLine (e.Message);
                }
            }
            return mergeResult;
        }
예제 #8
0
        public MergeResult StalkMerge(Commit commit)
        {
            MergeResult mergeResult = null;
            var mergeOptions = new MergeOptions ();
            var signature = new Signature (userName, userEmail, DateTime.Now);

            commitMsg = String.Format ("Automated Stalker (StalkMerge) merge commit from: '{0}' into {1}", commit.Sha.Substring (0, 6), head.Tip.Sha.Substring (0, 6));
            //commitMsg = String.Format ("Stalker merge commit from: '{0}' into {1}", commit.Sha.Substring (0, 6), head.Tip.Sha.Substring (0, 6));

            mergeOptions.FastForwardStrategy = FastForwardStrategy.NoFastForward;
            mergeOptions.FileConflictStrategy = CheckoutFileConflictStrategy.Normal;
            mergeOptions.FindRenames = true;
            mergeOptions.CommitOnSuccess = false;

            try {
                var fgColor = Console.ForegroundColor;
                var bgColor = Console.BackgroundColor;
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine ("Stalker - Merging commit : {0}", commit.Sha);
                Console.WriteLine (" - Info : {0} / {1} / {2}", commit.Author.When, commit.Author.Name, commit.Author.Email);
                Console.WriteLine (" - Msg : {0}", commit.Message);
                Console.ForegroundColor = fgColor;
                Console.BackgroundColor = bgColor;

                mergeResult = repo.Merge (commit, signature, mergeOptions);
                Console.WriteLine ("Merge results: {0}", mergeResult.Status);
            } catch (Exception e) {
                if (mergeResult != null) {
                    Console.WriteLine ("Merge failed: {0}", mergeResult.Status);
                } else {
                    Console.WriteLine (e);
                    Console.WriteLine (Environment.StackTrace);
                }
            }
            return mergeResult;
        }
예제 #9
0
 public MergeResult MergeFetchedRefs(Signature merger, MergeOptions options)
 {
     throw new NotImplementedException();
 }
예제 #10
0
파일: Main.cs 프로젝트: Moones/OpenEnsage
 private void loadWorker_DoWork(object sender, DoWorkEventArgs e)
 {
     try
     {
         if (File.Exists("ensage.log"))
         {
             string[] strArray = File.ReadAllLines("ensage.log");
             int count = strArray.Length - 1000;
             if (count > 0)
                 File.WriteAllLines("ensage.log", Enumerable.Skip<string>(strArray, count));
         }
     }
     catch (Exception)
     {
     }
     try
     {
         using (WebClient webClient = new WebClient())
         {
             if (Program.IsContributor())
                 newsBox.Text = webClient.DownloadString("http://zynox.net/ensage/news2.php");
             else
                 loadWorker.ReportProgress(1, webClient.DownloadString("http://zynox.net/ensage/news.php"));
         }
     }
     catch (Exception)
     {
         if (newsBox.Text == string.Empty)
             loadWorker.ReportProgress(1, "Can't download news content.");
     }
     if (!Directory.Exists(_userPath))
         return;
     string[] directories = Directory.GetDirectories(_userPath);
     if (directories.Length == 0)
     {
         loadWorker.ReportProgress(9);
     }
     else
     {
         foreach (string path1 in directories)
         {
             foreach (string path2 in Directory.GetDirectories(path1))
             {
                 try
                 {
                     LibGit2Sharp.Signature merger = new LibGit2Sharp.Signature("local", "localhost", new DateTimeOffset());
                     using (LibGit2Sharp.Repository repository = new LibGit2Sharp.Repository(path2, null))
                     {
                         MergeOptions mergeOptions = new MergeOptions()
                         {
                             MergeFileFavor = MergeFileFavor.Theirs
                         };
                         repository.Network.Pull(merger, new PullOptions()
                         {
                             MergeOptions = mergeOptions
                         });
                     }
                 }
                 catch (Exception ex)
                 {
                     int num = (int)MessageBox.Show(ex.Message);
                     continue;
                 }
                 string str1 = path2.Substring(_userPath.Length + 1);
                 loadWorker.ReportProgress(2, str1);
                 foreach (string path3 in Directory.GetDirectories(path2))
                 {
                     string str2 = path3.Substring(path3.LastIndexOf('\\') + 1);
                     bool flag;
                     if (str2 == "Libraries")
                     {
                         flag = true;
                         loadWorker.ReportProgress(3, str1);
                     }
                     else if (str2 == "Scripts")
                     {
                         flag = false;
                         loadWorker.ReportProgress(4, str1);
                     }
                     else
                         continue;
                     foreach (string str3 in Directory.GetFiles(path3))
                     {
                         string str4 = str3.Substring(str3.LastIndexOf('\\') + 1);
                         string path4 = flag ? Path.Combine("Scripts", "libs", str4) : Path.Combine("Scripts", str4);
                         loadWorker.ReportProgress(flag ? 5 : 6, new string[2]
                         {
           str1,
           str4
                         });
                         if (File.Exists(path4))
                             loadWorker.ReportProgress(flag ? 7 : 8, new string[2]
                             {
             str1,
             str4
                             });
                     }
                 }
             }
         }
     }
 }
예제 #11
0
파일: Main.cs 프로젝트: Rrego6/Pass4Win
 /// <summary>
 /// Get's the latest and greatest from remote
 /// </summary>
 /// <returns></returns>
 public bool GitFetch()
 {
     if (cfg["UseGitRemote"] == true && GITRepoOffline == false)
     {
         toolStripOffline.Visible = false;
         using (var repo = new LibGit2Sharp.Repository(cfg["PassDirectory"]))
         {
             LibGit2Sharp.Signature Signature = new LibGit2Sharp.Signature("pass4win", "*****@*****.**", new DateTimeOffset(2011, 06, 16, 10, 58, 27, TimeSpan.FromHours(2)));
             FetchOptions fetchOptions = new FetchOptions();
             fetchOptions.CredentialsProvider = (_url, _user, _cred) => new UsernamePasswordCredentials
             {
                 Username = cfg["GitUser"],
                 Password = DecryptConfig(cfg["GitPass"], "pass4win")
             };
             MergeOptions mergeOptions = new MergeOptions();
             PullOptions pullOptions = new PullOptions();
             pullOptions.FetchOptions = fetchOptions;
             pullOptions.MergeOptions = mergeOptions;
             try
             {
                 MergeResult mergeResult = repo.Network.Pull(Signature, pullOptions);
             }
             catch
             {
                 return false;
             }
         }
     }
     return true;
 }