List <Change> ParseStatus()
        {
            List <Change> changes = new List <Change> ();

            var git_status = new GitCommand(LocalPath, "status --porcelain");

            git_status.Start();

            while (!git_status.StandardOutput.EndOfStream)
            {
                string line = git_status.StandardOutput.ReadLine();
                line = line.Trim();

                if (line.EndsWith(".empty") || line.EndsWith(".empty\""))
                {
                    line = line.Replace(".empty", "");
                }

                Change change;

                if (line.StartsWith("R"))
                {
                    string path          = line.Substring(3, line.IndexOf(" -> ") - 3).Trim("\" ".ToCharArray());
                    string moved_to_path = line.Substring(line.IndexOf(" -> ") + 4).Trim("\" ".ToCharArray());

                    change = new Change()
                    {
                        Type        = ChangeType.Moved,
                        Path        = EnsureSpecialCharacters(path),
                        MovedToPath = EnsureSpecialCharacters(moved_to_path)
                    };
                }
                else
                {
                    string path = line.Substring(2).Trim("\" ".ToCharArray());
                    change = new Change()
                    {
                        Path = EnsureSpecialCharacters(path)
                    };
                    change.Type = ChangeType.Added;

                    if (line.StartsWith("M"))
                    {
                        change.Type = ChangeType.Edited;
                    }
                    else if (line.StartsWith("D"))
                    {
                        change.Type = ChangeType.Deleted;
                    }
                }

                changes.Add(change);
            }

            git_status.StandardOutput.ReadToEnd();
            git_status.WaitForExit();

            return(changes);
        }
        public override bool SyncDown()
        {
            string lfs_is_behind_file_path = Path.Combine(LocalPath, ".git", "lfs", "is_behind");

            if (StorageType == StorageType.LargeFiles)
            {
                File.Create(lfs_is_behind_file_path);
            }

            var git_fetch = new GitCommand(LocalPath, "fetch --progress origin " + branch, auth_info);

            git_fetch.StartInfo.RedirectStandardError = true;
            git_fetch.Start();

            if (!ReadStream(git_fetch))
            {
                return(false);
            }

            git_fetch.WaitForExit();

            if (git_fetch.ExitCode != 0)
            {
                Error = ErrorStatus.HostUnreachable;
                return(false);
            }

            if (Merge())
            {
                if (StorageType == StorageType.LargeFiles)
                {
                    // Pull LFS files manually to benefit from concurrency
                    var git_lfs_pull = new GitCommand(LocalPath, "lfs pull origin", auth_info);
                    git_lfs_pull.StartAndWaitForExit();

                    if (git_lfs_pull.ExitCode != 0)
                    {
                        Error = ErrorStatus.HostUnreachable;
                        return(false);
                    }

                    if (File.Exists(lfs_is_behind_file_path))
                    {
                        File.Delete(lfs_is_behind_file_path);
                    }
                }

                UpdateSizes();
                return(true);
            }

            return(false);
        }
Beispiel #3
0
        public override bool SyncUp()
        {
            if (!Add())
            {
                Error = ErrorStatus.UnreadableFiles;
                return(false);
            }

            string message = base.status_message;

            if (string.IsNullOrEmpty(message))
            {
                message = FormatCommitMessage();
            }

            if (message != null)
            {
                Commit(message);
            }

            PrepareGitLFS();

            var git_push = new GitCommand(LocalPath, string.Format("push --all --progress origin", RemoteUrl), auth_info);

            git_push.StartInfo.RedirectStandardError = true;
            git_push.Start();

            if (!ReadStream(git_push))
            {
                return(false);
            }

            git_push.WaitForExit();

            UpdateSizes();

            if (git_push.ExitCode == 0)
            {
                return(true);
            }

            Error = ErrorStatus.HostUnreachable;
            return(false);
        }
Beispiel #4
0
        public override bool Fetch()
        {
            if (!base.Fetch())
            {
                return(false);
            }

            StorageType?storage_type = DetermineStorageType();

            if (storage_type == null)
            {
                return(false);
            }

            FetchedRepoStorageType = (StorageType)storage_type;

            string git_clone_command = "clone --progress --no-checkout";

            if (!FetchPriorHistory)
            {
                git_clone_command += " --depth=1";
            }

            if (storage_type == StorageType.LargeFiles)
            {
                git_clone_command = "lfs clone --progress --no-checkout";
            }

            git_clone = new GitCommand(Configuration.DefaultConfiguration.TmpPath,
                                       string.Format("{0} \"{1}\" \"{2}\"", git_clone_command, RemoteUrl, TargetFolder),
                                       auth_info);

            git_clone.StartInfo.RedirectStandardError = true;
            git_clone.Start();

            StreamReader output_stream = git_clone.StandardError;

            if (FetchedRepoStorageType == StorageType.LargeFiles)
            {
                output_stream = git_clone.StandardOutput;
            }

            double percentage  = 0;
            double speed       = 0;
            string information = "";

            while (!output_stream.EndOfStream)
            {
                string line = output_stream.ReadLine();

                ErrorStatus error = GitCommand.ParseProgress(line, out percentage, out speed, out information);

                if (error != ErrorStatus.None)
                {
                    IsActive = false;
                    git_clone.Kill();
                    git_clone.Dispose();

                    return(false);
                }

                OnProgressChanged(percentage, speed, information);
            }

            git_clone.WaitForExit();

            if (git_clone.ExitCode != 0)
            {
                return(false);
            }

            Thread.Sleep(500);
            OnProgressChanged(100, 0, "");
            Thread.Sleep(500);

            return(true);
        }
        public override bool SyncUp()
        {
            if (!Add())
            {
                Error = ErrorStatus.UnreadableFiles;
                return(false);
            }

            string message = base.status_message.Replace("\"", "\\\"");

            if (string.IsNullOrEmpty(message))
            {
                message = FormatCommitMessage();
            }

            if (message != null)
            {
                Commit(message);
            }

            string pre_push_hook_path = Path.Combine(LocalPath, ".git", "hooks", "pre-push");
            string pre_push_hook_content;

            // The pre-push hook may have been changed by Git LFS, overwrite it to use our own configuration
            if (InstallationInfo.OperatingSystem == OS.Mac)
            {
                pre_push_hook_content =
                    "#!/bin/sh" + Environment.NewLine +
                    "env GIT_SSH_COMMAND='" + GitCommand.FormatGitSSHCommand(auth_info) + "' " +
                    Path.Combine(Configuration.DefaultConfiguration.BinPath, "git-lfs") + " pre-push \"$@\"";
            }
            else
            {
                pre_push_hook_content =
                    "#!/bin/sh" + Environment.NewLine +
                    "env GIT_SSH_COMMAND='" + GitCommand.FormatGitSSHCommand(auth_info) + "' " +
                    "git-lfs pre-push \"$@\"";
            }

            Directory.CreateDirectory(Path.GetDirectoryName(pre_push_hook_path));
            File.WriteAllText(pre_push_hook_path, pre_push_hook_content);

            var git_push = new GitCommand(LocalPath, string.Format("push --all --progress origin", RemoteUrl), auth_info);

            git_push.StartInfo.RedirectStandardError = true;
            git_push.Start();

            if (!ReadStream(git_push))
            {
                return(false);
            }

            git_push.WaitForExit();

            UpdateSizes();

            if (git_push.ExitCode == 0)
            {
                return(true);
            }

            Error = ErrorStatus.HostUnreachable;
            return(false);
        }
        public override bool Fetch()
        {
            if (!base.Fetch ())
                return false;

            StorageType? storage_type = DetermineStorageType ();

            if (storage_type == null)
                return false;

            FetchedRepoStorageType = (StorageType) storage_type;

            string git_clone_command = "clone --progress --no-checkout";

            if (!FetchPriorHistory)
                git_clone_command += " --depth=1";

            if (storage_type == StorageType.LargeFiles)
                git_clone_command = "lfs clone --progress --no-checkout";

            git_clone = new GitCommand (Configuration.DefaultConfiguration.TmpPath,
                string.Format ("{0} \"{1}\" \"{2}\"", git_clone_command, RemoteUrl, TargetFolder),
                auth_info);

            git_clone.StartInfo.RedirectStandardError = true;
            git_clone.Start ();

            StreamReader output_stream = git_clone.StandardError;

            if (FetchedRepoStorageType == StorageType.LargeFiles)
                output_stream = git_clone.StandardOutput;

            double percentage = 0;
            double speed = 0;
            string information = "";

            while (!output_stream.EndOfStream) {
                string line = output_stream.ReadLine ();

                ErrorStatus error = GitCommand.ParseProgress (line, out percentage, out speed, out information);

                if (error != ErrorStatus.None) {
                    IsActive = false;
                    git_clone.Kill ();
                    git_clone.Dispose ();

                    return false;
                }

                OnProgressChanged (percentage, speed, information);
            }

            git_clone.WaitForExit ();

            if (git_clone.ExitCode != 0)
                return false;

            Thread.Sleep (500);
            OnProgressChanged (100, 0, "");
            Thread.Sleep (500);

            return true;
        }
Beispiel #7
0
        List<Change> ParseStatus()
        {
            List<Change> changes = new List<Change> ();

            var git_status = new GitCommand (LocalPath, "status --porcelain");
            git_status.Start ();

            while (!git_status.StandardOutput.EndOfStream) {
                string line = git_status.StandardOutput.ReadLine ();
                line        = line.Trim ();

                if (line.EndsWith (".empty") || line.EndsWith (".empty\""))
                    line = line.Replace (".empty", "");

                Change change;

                if (line.StartsWith ("R")) {
                    string path = line.Substring (3, line.IndexOf (" -> ") - 3).Trim ("\" ".ToCharArray ());
                    string moved_to_path = line.Substring (line.IndexOf (" -> ") + 4).Trim ("\" ".ToCharArray ());

                    change = new Change () {
                        Type = ChangeType.Moved,
                        Path = EnsureSpecialCharacters (path),
                        MovedToPath = EnsureSpecialCharacters (moved_to_path)
                    };

                } else {
                    string path = line.Substring (2).Trim ("\" ".ToCharArray ());
                    change = new Change () { Path = EnsureSpecialCharacters (path) };
                    change.Type = ChangeType.Added;

                    if (line.StartsWith ("M")) {
                        change.Type = ChangeType.Edited;

                    } else if (line.StartsWith ("D")) {
                        change.Type = ChangeType.Deleted;
                    }
                }

                changes.Add (change);
            }

            git_status.StandardOutput.ReadToEnd ();
            git_status.WaitForExit ();

            return changes;
        }
Beispiel #8
0
        public override bool SyncUp()
        {
            if (!Add ()) {
                Error = ErrorStatus.UnreadableFiles;
                return false;
            }

            string message = base.status_message.Replace ("\"", "\\\"");

            if (string.IsNullOrEmpty (message))
                message = FormatCommitMessage ();

            if (message != null)
                Commit (message);

            string pre_push_hook_path = Path.Combine (LocalPath, ".git", "hooks", "pre-push");
            string pre_push_hook_content;

            // The pre-push hook may have been changed by Git LFS, overwrite it to use our own configuration
            if (InstallationInfo.OperatingSystem == OS.Mac) {
                pre_push_hook_content =
                    "#!/bin/sh" + Environment.NewLine +
                    "env GIT_SSH_COMMAND='" + GitCommand.FormatGitSSHCommand (auth_info) + "' " +
                    Path.Combine (Configuration.DefaultConfiguration.BinPath, "git-lfs") + " pre-push \"$@\"";

            } else {
                pre_push_hook_content =
                    "#!/bin/sh" + Environment.NewLine +
                    "env GIT_SSH_COMMAND='" + GitCommand.FormatGitSSHCommand (auth_info) + "' " +
                    "git-lfs pre-push \"$@\"";
            }

            Directory.CreateDirectory (Path.GetDirectoryName (pre_push_hook_path));
            File.WriteAllText (pre_push_hook_path, pre_push_hook_content);

            var git_push = new GitCommand (LocalPath, string.Format ("push --all --progress origin", RemoteUrl), auth_info);
            git_push.StartInfo.RedirectStandardError = true;
            git_push.Start ();

            if (!ReadStream (git_push))
                return false;

            git_push.WaitForExit ();

            UpdateSizes ();

            if (git_push.ExitCode == 0)
                return true;

            Error = ErrorStatus.HostUnreachable;
            return false;
        }
Beispiel #9
0
        public override bool SyncDown()
        {
            string lfs_is_behind_file_path = Path.Combine (LocalPath, ".git", "lfs", "is_behind");

            if (StorageType == StorageType.LargeFiles)
                File.Create (lfs_is_behind_file_path);

            var git_fetch = new GitCommand (LocalPath, "fetch --progress origin " + branch, auth_info);

            git_fetch.StartInfo.RedirectStandardError = true;
            git_fetch.Start ();

            if (!ReadStream (git_fetch))
                return false;

            git_fetch.WaitForExit ();

            if (git_fetch.ExitCode != 0) {
                Error = ErrorStatus.HostUnreachable;
                return false;
            }

            if (Merge ()) {
                if (StorageType == StorageType.LargeFiles) {
                    // Pull LFS files manually to benefit from concurrency
                    var git_lfs_pull = new GitCommand (LocalPath, "lfs pull origin", auth_info);
                    git_lfs_pull.StartAndWaitForExit ();

                    if (git_lfs_pull.ExitCode != 0) {
                        Error = ErrorStatus.HostUnreachable;
                        return false;
                    }

                    if (File.Exists (lfs_is_behind_file_path))
                        File.Delete (lfs_is_behind_file_path);
                }

                UpdateSizes ();
                return true;
            }

            return false;
        }