Beispiel #1
0
        private static GitResult Git(string repositoryPath, string command)
        {
            var procInfo = new ProcessStartInfo("git", command)
            {
                RedirectStandardOutput = true,
                RedirectStandardError  = true,
            };

            string gitDirectory = Path.Combine(repositoryPath, ".git");

            procInfo.Environment["GIT_DIR"] = gitDirectory;

            Process proc = Process.Start(procInfo);

            if (proc is null)
            {
                throw new Exception("Failed to start Git process");
            }

            proc.WaitForExit();

            var result = new GitResult
            {
                ExitCode       = proc.ExitCode,
                StandardOutput = proc.StandardOutput.ReadToEnd(),
                StandardError  = proc.StandardError.ReadToEnd()
            };

            return(result);
        }
Beispiel #2
0
        public static GitResult ExecGit(string repositoryPath, string workingDirectory, string command)
        {
            var procInfo = new ProcessStartInfo("git", command)
            {
                RedirectStandardOutput = true,
                RedirectStandardError  = true,
                WorkingDirectory       = workingDirectory
            };

            procInfo.Environment["GIT_DIR"] = repositoryPath;

            Process proc = Process.Start(procInfo);

            if (proc is null)
            {
                throw new Exception("Failed to start Git process");
            }

            proc.WaitForExit();

            var result = new GitResult
            {
                ExitCode       = proc.ExitCode,
                StandardOutput = proc.StandardOutput.ReadToEnd(),
                StandardError  = proc.StandardError.ReadToEnd()
            };

            return(result);
        }
        public void GitConfiguration_Unset_Local_UnsetsLocalConfig()
        {
            string repoPath = CreateRepository(out string workDirPath);

            try
            {
                Git(repoPath, workDirPath, "config --global core.foobar alice").AssertSuccess();
                Git(repoPath, workDirPath, "config --local core.foobar bob").AssertSuccess();

                string            gitPath = GetGitPath();
                var               trace   = new NullTrace();
                var               git     = new GitProcess(trace, gitPath, repoPath);
                IGitConfiguration config  = git.GetConfiguration(GitConfigurationLevel.Local);

                config.Unset("core.foobar");

                GitResult globalResult = Git(repoPath, workDirPath, "config --global core.foobar");
                GitResult localResult  = Git(repoPath, workDirPath, "config --local core.foobar");

                Assert.Equal("alice", globalResult.StandardOutput.Trim());
                Assert.Equal(string.Empty, localResult.StandardOutput.Trim());
            }
            finally
            {
                // Cleanup global config changes
                Git(repoPath, workDirPath, "config --global --unset core.foobar");
            }
        }
        public void GitConfiguration_Set_Local_SetsLocalConfig()
        {
            string repoPath = CreateRepository(out string workDirPath);

            string            gitPath = GetGitPath();
            var               trace   = new NullTrace();
            var               git     = new GitProcess(trace, gitPath, repoPath);
            IGitConfiguration config  = git.GetConfiguration(GitConfigurationLevel.Local);

            config.Set("core.foobar", "foo123");

            GitResult localResult = Git(repoPath, workDirPath, "config --local core.foobar");

            Assert.Equal("foo123", localResult.StandardOutput.Trim());
        }
        public void GitConfiguration_UnsetAll_UnsetsAllConfig()
        {
            string repoPath = CreateRepository(out string workDirPath);

            Git(repoPath, workDirPath, "config --local --add core.foobar foo1").AssertSuccess();
            Git(repoPath, workDirPath, "config --local --add core.foobar foo2").AssertSuccess();
            Git(repoPath, workDirPath, "config --local --add core.foobar bar1").AssertSuccess();

            string            gitPath = GetGitPath();
            var               trace   = new NullTrace();
            var               git     = new GitProcess(trace, gitPath, repoPath);
            IGitConfiguration config  = git.GetConfiguration(GitConfigurationLevel.Local);

            config.UnsetAll("core.foobar", "foo*");

            GitResult result = Git(repoPath, workDirPath, "config --local --get-all core.foobar");

            Assert.Equal("bar1", result.StandardOutput.Trim());
        }
        public async Task GitSync()
        {
            if (!IsDestinationFolderSet())
            {
                return;
            }

            try
            {
                GitGetRemote();
                GitOutput = "Start sync...";

                StartWorking("Sync");

                GitResult pullResult = await GitProcess.ExcecuteASync(DestinationFolder, "pull origin master");

                if (pullResult.ExitCode != 0)
                {
                    GitOutput = pullResult.Output;
                }

                GitResult pushResult = await GitProcess.ExcecuteASync(DestinationFolder, "push");

                if (pushResult.ExitCode == 0)
                {
                    GitOutput = string.Format("Succesfully pulled and pushed from server\n{0}", pushResult.Output);
                }
                else
                {
                    GitOutput = pushResult.Output;
                }
            }
            catch (Exception ex)
            {
                _dialogService.ShowErrorMessage("Git Status Error", ex.Message);
            }
            finally
            {
                StopWorking();
            }
        }