Exemple #1
0
        // Starts a timer when something changes
        private void OnFileActivity(object o, FileSystemEventArgs fse_args)
        {
            if (fse_args.Name.StartsWith(".git/"))
            {
                return;
            }

            WatcherChangeTypes wct = fse_args.ChangeType;

            if (AnyDifferences)
            {
                _IsBuffering = true;

                // Only fire the event if the timer has been stopped.
                // This prevents multiple events from being raised whilst "buffering".
                if (!HasChanged)
                {
                    SparkleEventArgs args = new SparkleEventArgs("ChangesDetected");

                    if (ChangesDetected != null)
                    {
                        ChangesDetected(this, args);
                    }
                }

                SparkleHelpers.DebugInfo("Event", "[" + Name + "] " + wct.ToString() + " '" + fse_args.Name + "'");
                SparkleHelpers.DebugInfo("Local", "[" + Name + "] Changes found, checking if settled.");

                RemoteTimer.Stop();

                lock (ChangeLock) {
                    HasChanged = true;
                }
            }
        }
Exemple #2
0
        // When there are changes we generally want to Add, Commit and Push,
        // so this method does them all with appropriate timers, etc. switched off
        public void AddCommitAndPush()
        {
            try {
                LocalTimer.Stop();
                RemoteTimer.Stop();

                if (AnyDifferences)
                {
                    Add();

                    string message = FormatCommitMessage();
                    Commit(message);

                    Push();
                }
                else
                {
                    SparkleEventArgs args = new SparkleEventArgs("CommitEndedUpEmpty");

                    if (CommitEndedUpEmpty != null)
                    {
                        CommitEndedUpEmpty(this, args);
                    }
                }
            } finally {
                RemoteTimer.Start();
                LocalTimer.Start();
            }
        }
Exemple #3
0
        // Commits the made changes
        public void Commit(string message)
        {
            if (!AnyDifferences)
            {
                return;
            }

            SparkleGit git = new SparkleGit(LocalPath, "commit -m '" + message + "'");

            git.Start();
            git.WaitForExit();

            _CurrentHash = GetCurrentHash();
            SparkleHelpers.DebugInfo("Commit", "[" + Name + "] " + message + " (" + _CurrentHash + ")");

            SparkleEventArgs args = new SparkleEventArgs("Commited")
            {
                Message = message
            };

            if (Commited != null)
            {
                Commited(this, args);
            }

            // Collect garbage pseudo-randomly
            if (DateTime.Now.Second % 10 == 0)
            {
                CollectGarbage();
            }
        }
Exemple #4
0
        // Commits the made changes
        new public void Commit(string message)
        {
            if (!AnyDifferences)
            {
                return;
            }

            base.Commit(message);
            _CurrentHash = Head.CurrentCommit.Hash;

            SparkleHelpers.DebugInfo("Commit", "[" + Name + "] " + message + " (" + _CurrentHash);

            SparkleEventArgs args = new SparkleEventArgs("Commited")
            {
                Message = message
            };

            if (Commited != null)
            {
                Commited(this, args);
            }

            // Collect garbage pseudo-randomly
            if (DateTime.Now.Second % 10 == 0)
            {
                CollectGarbage();
            }
        }
Exemple #5
0
        // Fetches changes from the remote repository
        public void Fetch()
        {
            _IsSyncing  = true;
            _IsFetching = true;

            RemoteTimer.Stop();

            SparkleHelpers.DebugInfo("Git", "[" + Name + "] Fetching changes...");

            SparkleGit git = new SparkleGit(LocalPath, "fetch -v origin master");

            SparkleEventArgs args;

            args = new SparkleEventArgs("FetchingStarted");

            if (FetchingStarted != null)
            {
                FetchingStarted(this, args);
            }


            git.Exited += delegate {
                SparkleHelpers.DebugInfo("Git", "[" + Name + "] Changes fetched.");

                _IsSyncing  = false;
                _IsFetching = false;

                _CurrentHash = Head.CurrentCommit.Hash;

                if (git.ExitCode != 0)
                {
                    _ServerOnline = false;

                    args = new SparkleEventArgs("FetchingFailed");

                    if (FetchingFailed != null)
                    {
                        FetchingFailed(this, args);
                    }
                }
                else
                {
                    _ServerOnline = true;

                    args = new SparkleEventArgs("FetchingFinished");

                    if (FetchingFinished != null)
                    {
                        FetchingFinished(this, args);
                    }
                }

                RemoteTimer.Start();
            };


            git.Start();
            git.WaitForExit();
        }
Exemple #6
0
        // Merges the fetched changes
        public void Rebase()
        {
            if (AnyDifferences)
            {
                Add();

                string commit_message = FormatCommitMessage();
                Commit(commit_message);
            }

            SparkleHelpers.DebugInfo("Git", "[" + Name + "] Rebasing changes...");
            SparkleGit git = new SparkleGit(LocalPath, "rebase -v FETCH_HEAD");

            git.Exited += delegate {
                if (git.ExitCode != 0)
                {
                    SparkleHelpers.DebugInfo("Git", "[" + Name + "] Conflict detected. Trying to get out...");
                    Watcher.EnableRaisingEvents = false;

                    while (AnyDifferences)
                    {
                        ResolveConflict();
                    }

                    SparkleHelpers.DebugInfo("Git", "[" + Name + "] Conflict resolved.");
                    Watcher.EnableRaisingEvents = true;

                    SparkleEventArgs args = new SparkleEventArgs("ConflictDetected");
                    if (ConflictDetected != null)
                    {
                        ConflictDetected(this, args);
                    }
                }

                _CurrentHash = GetCurrentHash();
            };

            git.Start();
            git.WaitForExit();

            _CurrentHash = GetCurrentHash();

            if (NewCommit != null)
            {
                NewCommit(GetCommits(1) [0], LocalPath);
            }

            SparkleHelpers.DebugInfo("Git", "[" + Name + "] Changes rebased.");
        }
        // Clones the remote repository
        public void Clone()
        {
            if (Directory.Exists (TargetFolder))
                Directory.Delete (TargetFolder, true);

            SparkleEventArgs args = new SparkleEventArgs ("CloningStarted");

            if (CloningStarted != null)
                CloningStarted (this, args);

            Process process = new Process () {
                EnableRaisingEvents = true
            };

            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.UseShellExecute = false;
            process.StartInfo.FileName = "git";
            process.StartInfo.Arguments = "clone --depth=1 " + RemoteOriginUrl + " " + TargetFolder;

            process.Exited += delegate {

                SparkleHelpers.DebugInfo ("Git", "Exit code " + process.ExitCode.ToString ());

                if (process.ExitCode != 0) {

                    args = new SparkleEventArgs ("CloningFailed");

                    if (CloningFailed != null)
                        CloningFailed (this, args);

                } else {

                    InstallUserInfo ();
                    InstallExcludeRules ();

                    args = new SparkleEventArgs ("CloningFinished");

                    if (CloningFinished != null)
                        CloningFinished (this, args);

                }

            };

            process.Start ();
        }
Exemple #8
0
        // Stages the made changes
        private void Add()
        {
            SparkleHelpers.DebugInfo("Git", "[" + Name + "] Staging changes...");

            SparkleGit git = new SparkleGit(LocalPath, "add --all");

            git.Start();
            git.WaitForExit();

            SparkleHelpers.DebugInfo("Git", "[" + Name + "] Changes staged.");
            SparkleEventArgs args = new SparkleEventArgs("Added");

            if (Added != null)
            {
                Added(this, args);
            }
        }
Exemple #9
0
        // Stages the made changes
        private void Add()
        {
            SparkleHelpers.DebugInfo("Git", "[" + Name + "] Staging changes...");

            // FIXME: this GitSharp method seems to block...
            // Index.AddAll ();

            SparkleGit git = new SparkleGit(LocalPath, "add --all");

            git.Start();
            git.WaitForExit();

            SparkleHelpers.DebugInfo("Git", "[" + Name + "] Changes staged.");

            SparkleEventArgs args = new SparkleEventArgs("Added");

            if (Added != null)
            {
                Added(this, args);
            }
        }
Exemple #10
0
        // Stages the made changes
        private void Add()
        {
            SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Staging changes...");

            SparkleGit git = new SparkleGit (LocalPath, "add --all");
            git.Start ();
            git.WaitForExit ();

            SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Changes staged.");
            SparkleEventArgs args = new SparkleEventArgs ("Added");

            if (Added != null)
                Added (this, args);
        }
Exemple #11
0
        // Stages the made changes
        private void Add()
        {
            SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Staging changes...");

            Process.StartInfo.Arguments = "add --all";
            Process.Start ();
            Process.WaitForExit ();

            SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Changes staged.");

            SparkleEventArgs args = new SparkleEventArgs ("Added");

            if (Added != null)
                Added (this, args);
        }
Exemple #12
0
        // Merges the fetched changes
        public void Rebase()
        {
            Add ();

            Watcher.EnableRaisingEvents = false;

            SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Rebasing changes...");

            Process.StartInfo.Arguments = "rebase -v FETCH_HEAD";
            Process.WaitForExit ();
            Process.Start ();

            SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Changes rebased.");

            string output = Process.StandardOutput.ReadToEnd ().Trim ();

            if (!output.Contains ("up to date")) {

                if (output.Contains ("Failed to merge")) {

                    SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Resolving conflict...");

                    Process.StartInfo.Arguments = "status";
                    Process.WaitForExit ();
                    Process.Start ();
                    output = Process.StandardOutput.ReadToEnd ().Trim ();
                    string [] lines = Regex.Split (output, "\n");

                    foreach (string line in lines) {

                        if (line.Contains ("needs merge")) {

                            string problem_file_name = line.Substring (line.IndexOf (": needs merge"));

                            Process.StartInfo.Arguments = "checkout --ours " + problem_file_name;
                            Process.WaitForExit ();
                            Process.Start ();

                            string timestamp = DateTime.Now.ToString ("H:mm d MMM yyyy");

                            File.Move (problem_file_name, problem_file_name + " (" + UserName  + ", " + timestamp + ")");

                            Process.StartInfo.Arguments = "checkout --theirs " + problem_file_name;
                            Process.WaitForExit ();
                            Process.Start ();

                            SparkleEventArgs args = new SparkleEventArgs ("ConflictDetected");

                            if (ConflictDetected != null)
                                ConflictDetected (this, args);

                        }

                    }

                    Add ();

                    Process.StartInfo.Arguments = "rebase --continue";
                    Process.WaitForExit ();
                    Process.Start ();

                    SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Conflict resolved.");

                    Push ();

                }

                // Get the last commiter
                Process.StartInfo.Arguments = "log --format=\"%an\" -1";
                Process.Start ();
                string author = Process.StandardOutput.ReadToEnd ().Trim ();

                // Get the last committer e-mail
                Process.StartInfo.Arguments = "log --format=\"%ae\" -1";
                Process.Start ();
                string email = Process.StandardOutput.ReadToEnd ().Trim ();

                // Get the last commit message
                Process.StartInfo.Arguments = "log --format=\"%s\" -1";
                Process.Start ();
                string message = Process.StandardOutput.ReadToEnd ().Trim ();

                NewCommitArgs new_commit_args = new NewCommitArgs (author, email, message, Name);

                if (NewCommit != null)
                    NewCommit (this, new_commit_args);

            }

            Watcher.EnableRaisingEvents = true;
            SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Idling...");
        }
Exemple #13
0
        // Stages the made changes
        private void Add()
        {
            SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Staging changes...");

            // FIXME: this GitSharp method seems to block...
            // Index.AddAll ();

            SparkleGit git = new SparkleGit (LocalPath, "add --all");
            git.Start ();
            git.WaitForExit ();

            SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Changes staged.");

            SparkleEventArgs args = new SparkleEventArgs ("Added");

            if (Added != null)
                Added (this, args);
        }
Exemple #14
0
        // Merges the fetched changes
        public void Rebase()
        {
            if (AnyDifferences) {
                Add ();

                string commit_message = FormatCommitMessage ();
                Commit (commit_message);
            }

            SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Rebasing changes...");
            SparkleGit git = new SparkleGit (LocalPath, "rebase -v FETCH_HEAD");

            git.Exited += delegate {
                if (git.ExitCode != 0) {
                    SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Conflict detected. Trying to get out...");
                    Watcher.EnableRaisingEvents = false;

                    while (AnyDifferences)
                        ResolveConflict ();

                    SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Conflict resolved.");
                    Watcher.EnableRaisingEvents = true;

                    SparkleEventArgs args = new SparkleEventArgs ("ConflictDetected");
                    if (ConflictDetected != null)
                        ConflictDetected (this, args);
                }

                _CurrentHash = GetCurrentHash ();
            };

            git.Start ();
            git.WaitForExit ();

            _CurrentHash = GetCurrentHash ();

            if (NewCommit != null)
                NewCommit (GetCommits (1) [0], LocalPath);

            SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Changes rebased.");
        }
Exemple #15
0
        // Pushes the changes to the remote repo
        public void Push()
        {
            _IsSyncing = true;
            _IsPushing = true;

            SparkleGit git = new SparkleGit (LocalPath, "push origin master");

            SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Pushing changes...");

            SparkleEventArgs args = new SparkleEventArgs ("PushingStarted");

            if (PushingStarted != null)
                PushingStarted (this, args);

            git.Exited += delegate {

                _IsSyncing = false;
                _IsPushing = false;

                if (git.ExitCode != 0) {

                    SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Pushing failed.");

                    string unsynced_file_path = SparkleHelpers.CombineMore (LocalPath ,
                        ".git", "has_unsynced_changes");

                    if (!File.Exists (unsynced_file_path))
                        File.Create (unsynced_file_path);

                    _HasUnsyncedChanges = true;

                    args = new SparkleEventArgs ("PushingFailed");

                    if (PushingFailed != null)
                        PushingFailed (this, args);

                    CheckForRemoteChanges ();
                    Push ();

                } else {

                    SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Changes pushed.");

                    args = new SparkleEventArgs ("PushingFinished");

                    string unsynced_file_path = SparkleHelpers.CombineMore (LocalPath ,
                        ".git", "has_unsynced_changes");

                    if (File.Exists (unsynced_file_path))
                        File.Delete (unsynced_file_path);

                    _HasUnsyncedChanges = false;

                    if (PushingFinished != null)
                        PushingFinished (this, args);

                    if (!_IsPolling)
                        Listener.Announce (_CurrentHash);

                }

            };

            git.Start ();
            git.WaitForExit ();
        }
Exemple #16
0
        // Merges the fetched changes
        public void Rebase()
        {
            if (AnyDifferences) {

                Add ();

                string commit_message = FormatCommitMessage ();
                Commit (commit_message);

            }

            SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Rebasing changes...");
            SparkleGit git = new SparkleGit (LocalPath, "rebase -v FETCH_HEAD");

            git.Exited += delegate {

                if (Status.MergeConflict.Count > 0) {

                    SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Conflict detected...");

                    foreach (string problem_file_name in Status.MergeConflict) {

                        SparkleGit git_ours = new SparkleGit (LocalPath,
                            "checkout --ours " + problem_file_name);
                        git_ours.Start ();
                        git_ours.WaitForExit ();

                        string timestamp = DateTime.Now.ToString ("H:mm d MMM");

                        string new_file_name = problem_file_name + " (" + UserName  + ", " + timestamp + ")";
                        File.Move (problem_file_name, new_file_name);

                        SparkleGit git_theirs = new SparkleGit (LocalPath,
                            "checkout --theirs " + problem_file_name);
                        git_theirs.Start ();
                        git_theirs.WaitForExit ();

                        SparkleEventArgs args = new SparkleEventArgs ("ConflictDetected");

                        if (ConflictDetected != null)
                            ConflictDetected (this, args);

                    }

                    Add ();

                    SparkleGit git_continue = new SparkleGit (LocalPath, "rebase --continue");
                    git_continue.Start ();
                    git_continue.WaitForExit ();

                    SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Conflict resolved.");

                    Push ();

                }

            };

            git.Start ();
            git.WaitForExit ();

            _CurrentHash = Head.CurrentCommit.Hash;

            if (NewCommit != null)
                NewCommit (GetCommits (1) [0], LocalPath);

            SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Changes rebased.");
        }
Exemple #17
0
        // Pushes the changes to the remote repo
        public void Push()
        {
            SparkleEventArgs args = new SparkleEventArgs ("PushingStarted");

            if (PushingStarted != null)
                PushingStarted (this, args);

            SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Pushing changes...");

            Process.StartInfo.Arguments = "push origin master";
            Process.Start ();
            Process.WaitForExit ();

            Process.Exited += delegate {

                if (Process.ExitCode != 0) {

                    SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Pushing failed.");

                    HasUnsyncedChanges = true;

                    args = new SparkleEventArgs ("PushingFailed");

                    if (PushingFailed != null)
                        PushingFailed (this, args);

                } else {

                    SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Changes pushed.");

                    args = new SparkleEventArgs ("PushingFinished");

                    HasUnsyncedChanges = false;

                    if (PushingFinished != null)
                        PushingFinished (this, args);

                }

            };
        }
Exemple #18
0
        // Starts a timer when something changes
        private void OnFileActivity(object o, FileSystemEventArgs fse_args)
        {
            WatcherChangeTypes wct = fse_args.ChangeType;

            int number_of_changes = Status.Untracked.Count +
                                    Status.Missing.Count +
                                    Status.Modified.Count;

            if (number_of_changes > 0) {

                _IsBuffering = true;

                // Only fire the event if the timer has been stopped.
                // This prevents multiple events from being raised whilst "buffering".
                if (!HasChanged) {

                    SparkleEventArgs args = new SparkleEventArgs ("ChangesDetected");

                    if (ChangesDetected != null)
                        ChangesDetected (this, args);

                }

                SparkleHelpers.DebugInfo ("Event", "[" + Name + "] " + wct.ToString () + " '" + fse_args.Name + "'");
                SparkleHelpers.DebugInfo ("Local", "[" + Name + "] Changes found, checking if settled.");

                RemoteTimer.Stop ();

                lock (ChangeLock) {

                    HasChanged = true;

                }

            }
        }
Exemple #19
0
        // When there are changes we generally want to Add, Commit and Push,
        // so this method does them all with appropriate timers, etc. switched off
        public void AddCommitAndPush()
        {
            try {
                LocalTimer.Stop ();
                RemoteTimer.Stop ();

                if (AnyDifferences) {
                    Add ();

                    string message = FormatCommitMessage ();
                    Commit (message);

                    Push ();
                } else {
                    SparkleEventArgs args = new SparkleEventArgs ("CommitEndedUpEmpty");

                    if (CommitEndedUpEmpty != null)
                        CommitEndedUpEmpty (this, args);
                }
            } finally {

                RemoteTimer.Start ();
                LocalTimer.Start ();

            }
        }
Exemple #20
0
        // Fetches changes from the remote repository
        public void Fetch()
        {
            _IsSyncing  = true;
            _IsFetching = true;

            RemoteTimer.Stop ();

            SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Fetching changes...");
            SparkleGit git = new SparkleGit (LocalPath, "fetch -v origin master");

            SparkleEventArgs args = new SparkleEventArgs ("FetchingStarted");

            if (FetchingStarted != null)
                FetchingStarted (this, args);

            git.Exited += delegate {
                SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Changes fetched.");

                _IsSyncing   = false;
                _IsFetching  = false;
                _CurrentHash = GetCurrentHash ();

                if (git.ExitCode != 0) {
                    _ServerOnline = false;

                    args = new SparkleEventArgs ("FetchingFailed");

                    if (FetchingFailed != null)
                        FetchingFailed (this, args);
                } else {
                    _ServerOnline = true;

                    args = new SparkleEventArgs ("FetchingFinished");

                    if (FetchingFinished != null)
                        FetchingFinished (this, args);
                }

                RemoteTimer.Start ();
            };

            git.Start ();
            git.WaitForExit ();
        }
Exemple #21
0
        // Pushes the changes to the remote repo
        public void Push()
        {
            _IsSyncing = true;
            _IsPushing = true;

            SparkleHelpers.DebugInfo("Git", "[" + Name + "] Pushing changes...");
            SparkleGit git = new SparkleGit(LocalPath, "push origin master");

            SparkleEventArgs args = new SparkleEventArgs("PushingStarted");

            if (PushingStarted != null)
            {
                PushingStarted(this, args);
            }

            git.Exited += delegate {
                _IsSyncing = false;
                _IsPushing = false;

                if (git.ExitCode != 0)
                {
                    SparkleHelpers.DebugInfo("Git", "[" + Name + "] Pushing failed.");

                    string unsynced_file_path = SparkleHelpers.CombineMore(LocalPath,
                                                                           ".git", "has_unsynced_changes");

                    if (!File.Exists(unsynced_file_path))
                    {
                        File.Create(unsynced_file_path);
                    }

                    _HasUnsyncedChanges = true;

                    args = new SparkleEventArgs("PushingFailed");

                    if (PushingFailed != null)
                    {
                        PushingFailed(this, args);
                    }

                    FetchRebaseAndPush();
                }
                else
                {
                    SparkleHelpers.DebugInfo("Git", "[" + Name + "] Changes pushed.");
                    args = new SparkleEventArgs("PushingFinished");

                    string unsynced_file_path = SparkleHelpers.CombineMore(LocalPath,
                                                                           ".git", "has_unsynced_changes");

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

                    _HasUnsyncedChanges = false;

                    if (PushingFinished != null)
                    {
                        PushingFinished(this, args);
                    }

                    if (Listener.Client.IsConnected)
                    {
                        Listener.Announce(_CurrentHash);
                    }
                    else
                    {
                        AnnounceQueue++;
                        SparkleHelpers.DebugInfo("Irc", "[" + Name + "] Could not deliver notification, added it to the queue");
                    }
                }
            };

            git.Start();
            git.WaitForExit();
        }
Exemple #22
0
        // When there are changes we generally want to Add, Commit and Push,
        // so this method does them all with appropriate timers, etc. switched off
        public void AddCommitAndPush()
        {
            try {

                LocalTimer.Stop ();
                RemoteTimer.Stop ();

                Add ();

                string message = FormatCommitMessage ();

                if (message != null) {

                    Commit (message);
                    CheckForRemoteChanges ();
                    Push ();

                } else {

                    SparkleEventArgs args = new SparkleEventArgs ("CommitEndedUpEmpty");

                    if (CommitEndedUpEmpty != null)
                        CommitEndedUpEmpty (this, args);

                }

            } finally {

                if (_IsPolling)
                    RemoteTimer.Start ();

                LocalTimer.Start ();

            }
        }
Exemple #23
0
        // Starts a timer when something changes
        private void OnFileActivity(object o, FileSystemEventArgs fse_args)
        {
            WatcherChangeTypes wct = fse_args.ChangeType;

            if (!ShouldIgnore (fse_args.FullPath)) {

                _IsBuffering = true;

                // Only fire the event if the timer has been stopped.
                // This prevents multiple events from being raised whilst "buffering".
                if (!HasChanged) {

                    SparkleEventArgs args = new SparkleEventArgs ("ChangesDetected");

                    if (ChangesDetected != null)
                        ChangesDetected (this, args);

                }

                SparkleHelpers.DebugInfo ("Event", "[" + Name + "] " + wct.ToString () + " '" + fse_args.Name + "'");

                RemoteTimer.Stop ();

                lock (ChangeLock) {

                    LastChange = DateTime.UtcNow;
                    HasChanged = true;

                }

            }
        }
Exemple #24
0
        // Pushes the changes to the remote repo
        public void Push()
        {
            _IsSyncing = true;
            _IsPushing = true;

            SparkleGit git = new SparkleGit(LocalPath, "push origin master");

            SparkleHelpers.DebugInfo("Git", "[" + Name + "] Pushing changes...");

            SparkleEventArgs args = new SparkleEventArgs("PushingStarted");

            if (PushingStarted != null)
            {
                PushingStarted(this, args);
            }


            git.Exited += delegate {
                _IsSyncing = false;
                _IsPushing = false;

                if (git.ExitCode != 0)
                {
                    SparkleHelpers.DebugInfo("Git", "[" + Name + "] Pushing failed.");

                    string unsynced_file_path = SparkleHelpers.CombineMore(LocalPath,
                                                                           ".git", "has_unsynced_changes");

                    if (!File.Exists(unsynced_file_path))
                    {
                        File.Create(unsynced_file_path);
                    }

                    _HasUnsyncedChanges = true;

                    args = new SparkleEventArgs("PushingFailed");

                    if (PushingFailed != null)
                    {
                        PushingFailed(this, args);
                    }

                    CheckForRemoteChanges();
                    Push();
                }
                else
                {
                    SparkleHelpers.DebugInfo("Git", "[" + Name + "] Changes pushed.");

                    args = new SparkleEventArgs("PushingFinished");

                    string unsynced_file_path = SparkleHelpers.CombineMore(LocalPath,
                                                                           ".git", "has_unsynced_changes");

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

                    _HasUnsyncedChanges = false;

                    if (PushingFinished != null)
                    {
                        PushingFinished(this, args);
                    }

                    if (!_IsPolling)
                    {
                        Listener.Announce(_CurrentHash);
                    }
                }
            };


            git.Start();
            git.WaitForExit();
        }
Exemple #25
0
        // Merges the fetched changes
        public void Rebase()
        {
            if (AnyDifferences)
            {
                Add();

                string commit_message = FormatCommitMessage();
                Commit(commit_message);
            }

            SparkleHelpers.DebugInfo("Git", "[" + Name + "] Rebasing changes...");
            SparkleGit git = new SparkleGit(LocalPath, "rebase -v FETCH_HEAD");

            git.Exited += delegate {
                if (Status.MergeConflict.Count > 0)
                {
                    SparkleHelpers.DebugInfo("Git", "[" + Name + "] Conflict detected...");

                    foreach (string problem_file_name in Status.MergeConflict)
                    {
                        SparkleGit git_ours = new SparkleGit(LocalPath,
                                                             "checkout --ours " + problem_file_name);
                        git_ours.Start();
                        git_ours.WaitForExit();

                        string timestamp = DateTime.Now.ToString("H:mm d MMM");

                        string new_file_name = problem_file_name + " (" + UserName + ", " + timestamp + ")";
                        File.Move(problem_file_name, new_file_name);

                        SparkleGit git_theirs = new SparkleGit(LocalPath,
                                                               "checkout --theirs " + problem_file_name);
                        git_theirs.Start();
                        git_theirs.WaitForExit();

                        SparkleEventArgs args = new SparkleEventArgs("ConflictDetected");

                        if (ConflictDetected != null)
                        {
                            ConflictDetected(this, args);
                        }
                    }

                    Add();

                    SparkleGit git_continue = new SparkleGit(LocalPath, "rebase --continue");
                    git_continue.Start();
                    git_continue.WaitForExit();

                    SparkleHelpers.DebugInfo("Git", "[" + Name + "] Conflict resolved.");

                    Push();
                }
            };


            git.Start();
            git.WaitForExit();

            _CurrentHash = Head.CurrentCommit.Hash;

            if (NewCommit != null)
            {
                NewCommit(GetCommits(1) [0], LocalPath);
            }

            SparkleHelpers.DebugInfo("Git", "[" + Name + "] Changes rebased.");
        }
Exemple #26
0
        // Commits the made changes
        public new void Commit(string message)
        {
            if (!Status.AnyDifferences)
                return;

            base.Commit (message);

            SparkleHelpers.DebugInfo ("Commit", "[" + Name + "] " + message);

            SparkleEventArgs args = new SparkleEventArgs ("Commited");
            args.Message = message;

            if (Commited != null)
                Commited (this, args);
        }
Exemple #27
0
        // Fetches changes from the remote repository
        public void Fetch()
        {
            RemoteTimer.Stop ();

            Process process = new Process () {
                EnableRaisingEvents = true
            };

            process.StartInfo.FileName               = "git";
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.UseShellExecute        = false;
            process.StartInfo.WorkingDirectory       = LocalPath;

            SparkleEventArgs args;
            args = new SparkleEventArgs ("FetchingStarted");

            if (FetchingStarted != null)
                FetchingStarted (this, args);

            SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Fetching changes...");

            process.StartInfo.Arguments = "fetch -v origin master";

            process.Start ();

            process.Exited += delegate {

                SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Changes fetched.");

                args = new SparkleEventArgs ("FetchingFinished");

                if (FetchingFinished != null)
                    FetchingFinished (this, args);

                Rebase ();

                RemoteTimer.Start ();

                CurrentHash = GetCurrentHash ();

            };
        }
Exemple #28
0
        // Starts a timer when something changes
        private void OnFileActivity(object o, FileSystemEventArgs fse_args)
        {
            if (fse_args.Name.StartsWith (".git/"))
                return;

            WatcherChangeTypes wct = fse_args.ChangeType;

            if (AnyDifferences) {
                _IsBuffering = true;

                // Only fire the event if the timer has been stopped.
                // This prevents multiple events from being raised whilst "buffering".
                if (!HasChanged) {
                    SparkleEventArgs args = new SparkleEventArgs ("ChangesDetected");

                    if (ChangesDetected != null)
                        ChangesDetected (this, args);
                }

                SparkleHelpers.DebugInfo ("Event", "[" + Name + "] " + wct.ToString () + " '" + fse_args.Name + "'");
                SparkleHelpers.DebugInfo ("Local", "[" + Name + "] Changes found, checking if settled.");

                RemoteTimer.Stop ();

                lock (ChangeLock) {
                    HasChanged = true;
                }
            }
        }
Exemple #29
0
        // Fetches changes from the remote repository
        public void Fetch()
        {
            _IsSyncing  = true;
            _IsFetching = true;

            RemoteTimer.Stop ();

            /* FIXME: SSH transport doesn't work with GitSharp
            try {

                FetchCommand fetch_command = new FetchCommand () {
                    Remote = "origin",
                    Repository = this
                };

                fetch_command.Execute ();

            } catch (GitSharp.Core.Exceptions.TransportException e) {

                Console.WriteLine ("Nothing to fetch: " + e.Message);

            }
            */

            Process process = new Process () {
                EnableRaisingEvents = true
            };

            process.StartInfo.FileName               = SparklePaths.GitPath;
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.UseShellExecute        = false;
            process.StartInfo.WorkingDirectory       = LocalPath;

            SparkleEventArgs args;
            args = new SparkleEventArgs ("FetchingStarted");

            if (FetchingStarted != null)
                FetchingStarted (this, args);

            SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Fetching changes...");

            process.StartInfo.Arguments = "fetch -v origin master";

            process.Start ();
            process.WaitForExit ();

            process.Exited += delegate {

                SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Changes fetched.");

                args = new SparkleEventArgs ("FetchingFinished");

                _IsSyncing  = false;
                _IsFetching = false;

                if (_IsPolling)
                    RemoteTimer.Start ();

                _CurrentHash = Head.CurrentCommit.Hash;

                if (process.ExitCode != 0) {

                    _ServerOnline = false;

                    if (FetchingFailed != null)
                        FetchingFailed (this, args);

                } else {

                    _ServerOnline = true;

                    if (FetchingFinished != null)
                        FetchingFinished (this, args);

                }

            };
        }
Exemple #30
0
        // Commits the made changes
        public void Commit(string message)
        {
            if (!AnyDifferences)
                return;

            SparkleGit git = new SparkleGit (LocalPath, "commit -m '" + message + "'");
            git.Start ();
            git.WaitForExit ();

            _CurrentHash = GetCurrentHash ();
            SparkleHelpers.DebugInfo ("Commit", "[" + Name + "] " + message + " (" + _CurrentHash + ")");

            SparkleEventArgs args = new SparkleEventArgs ("Commited") {
                Message = message
            };

            if (Commited != null)
                Commited (this, args);

            // Collect garbage pseudo-randomly
            if (DateTime.Now.Second % 10 == 0)
                CollectGarbage ();
        }
Exemple #31
0
        // Pushes the changes to the remote repo
        public void Push()
        {
            _IsSyncing = true;
            _IsPushing = true;

            SparkleEventArgs args = new SparkleEventArgs ("PushingStarted");

            if (PushingStarted != null)
                PushingStarted (this, args);

            SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Pushing changes...");

            /* FIXME: SSH transport doesn't work with GitSharp
            try {

                PushCommand push_command = new PushCommand () {
                    Remote = "origin",
                    Repository = this
                };

                push_command.Execute ();

            } catch (GitSharp.Core.Exceptions.TransportException e) {

                Console.WriteLine (e.Message);

            }
            */

            Process.StartInfo.Arguments = "push origin master";

            Process.WaitForExit ();
            Process.Start ();

            Process.Exited += delegate {

                _IsSyncing = false;
                _IsPushing = false;

                if (Process.ExitCode != 0) {

                    SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Pushing failed.");

                    string unsynced_file_path = SparkleHelpers.CombineMore (LocalPath ,
                        ".git", "has_unsynced_changes");

                    if (!File.Exists (unsynced_file_path))
                        File.Create (unsynced_file_path);

                    _HasUnsyncedChanges = true;

                    args = new SparkleEventArgs ("PushingFailed");

                    if (PushingFailed != null)
                        PushingFailed (this, args);

                } else {

                    SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Changes pushed.");

                    args = new SparkleEventArgs ("PushingFinished");

                    string unsynced_file_path = SparkleHelpers.CombineMore (LocalPath ,
                        ".git", "has_unsynced_changes");

                    if (File.Exists (unsynced_file_path))
                        File.Delete (unsynced_file_path);

                    _HasUnsyncedChanges = false;

                    if (PushingFinished != null)
                        PushingFinished (this, args);

                }

            };
        }
Exemple #32
0
        // Pushes the changes to the remote repo
        public void Push()
        {
            _IsSyncing = true;
            _IsPushing = true;

            SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Pushing changes...");
            SparkleGit git = new SparkleGit (LocalPath, "push origin master");

            SparkleEventArgs args = new SparkleEventArgs ("PushingStarted");

            if (PushingStarted != null)
                PushingStarted (this, args);

            git.Exited += delegate {
                _IsSyncing = false;
                _IsPushing = false;

                if (git.ExitCode != 0) {
                    SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Pushing failed.");

                    string unsynced_file_path = SparkleHelpers.CombineMore (LocalPath ,
                        ".git", "has_unsynced_changes");

                    if (!File.Exists (unsynced_file_path))
                        File.Create (unsynced_file_path);

                    _HasUnsyncedChanges = true;

                    args = new SparkleEventArgs ("PushingFailed");

                    if (PushingFailed != null)
                        PushingFailed (this, args);

                    FetchRebaseAndPush ();
                } else {
                    SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Changes pushed.");
                    args = new SparkleEventArgs ("PushingFinished");

                    string unsynced_file_path = SparkleHelpers.CombineMore (LocalPath ,
                        ".git", "has_unsynced_changes");

                    if (File.Exists (unsynced_file_path))
                        File.Delete (unsynced_file_path);

                    _HasUnsyncedChanges = false;

                    if (PushingFinished != null)
                        PushingFinished (this, args);

                    if (Listener.Client.IsConnected) {
                        Listener.Announce (_CurrentHash);
                    } else {
                        AnnounceQueue++;
                        SparkleHelpers.DebugInfo ("Irc", "[" + Name + "] Could not deliver notification, added it to the queue");
                     }
                }

            };

            git.Start ();
            git.WaitForExit ();
        }
Exemple #33
0
        // Merges the fetched changes
        public void Rebase()
        {
            Add ();

            Watcher.EnableRaisingEvents = false;

            SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Rebasing changes...");

            Process.StartInfo.Arguments = "rebase -v FETCH_HEAD";
            Process.WaitForExit ();
            Process.Start ();

            SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Changes rebased.");

            string output = Process.StandardOutput.ReadToEnd ().Trim ();

            if (!output.Contains ("up to date")) {

                if (output.Contains ("Failed to merge")) {

                    SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Resolving conflict...");

                    Process.StartInfo.Arguments = "status";
                    Process.WaitForExit ();
                    Process.Start ();
                    output = Process.StandardOutput.ReadToEnd ().Trim ();
                    string [] lines = Regex.Split (output, "\n");

                    foreach (string line in lines) {

                        if (line.Contains ("needs merge")) {

                            string problem_file_name = line.Substring (line.IndexOf (": needs merge"));

                            Process.StartInfo.Arguments = "checkout --ours " + problem_file_name;
                            Process.WaitForExit ();
                            Process.Start ();

                            string timestamp = DateTime.Now.ToString ("H:mm d MMM yyyy");

                            File.Move (problem_file_name, problem_file_name + " (" + UserName  + ", " + timestamp + ")");

                            Process.StartInfo.Arguments = "checkout --theirs " + problem_file_name;
                            Process.WaitForExit ();
                            Process.Start ();

                            SparkleEventArgs args = new SparkleEventArgs ("ConflictDetected");

                            if (ConflictDetected != null)
                                ConflictDetected (this, args);

                        }

                    }

                    Add ();

                    Process.StartInfo.Arguments = "rebase --continue";
                    Process.WaitForExit ();
                    Process.Start ();

                    SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Conflict resolved.");

                    Push ();

                }

                List <SparkleCommit> commits = GetCommits (1);

                if (NewCommit != null)
                    NewCommit (commits [0], LocalPath);

            }

            Watcher.EnableRaisingEvents = true;
        }
Exemple #34
0
        // Commits the made changes
        public new void Commit(string message)
        {
            if (!AnyDifferences)
                return;

            base.Commit (message);
            _CurrentHash = Head.CurrentCommit.Hash;

            SparkleHelpers.DebugInfo ("Commit", "[" + Name + "] " + message + " (" + _CurrentHash);

            SparkleEventArgs args = new SparkleEventArgs ("Commited") {
                Message = message
            };

            if (Commited != null)
                Commited (this, args);

            // Collect garbage pseudo-randomly
            if (DateTime.Now.Second % 10 == 0)
                CollectGarbage ();
        }
Exemple #35
0
        // Commits the made changes
        public void Commit(string message)
        {
            Process.StartInfo.Arguments = "status --porcelain";
            Process.Start ();
            Process.WaitForExit ();

            if (Process.StandardOutput.ReadToEnd ().TrimEnd ("\n".ToCharArray ()).Equals (""))
                return;

            SparkleHelpers.DebugInfo ("Commit", "[" + Name + "] " + message);

            Process.StartInfo.Arguments = "commit -m \"" + message + "\"";
            Process.Start ();
            Process.WaitForExit ();

            SparkleEventArgs args = new SparkleEventArgs ("Commited");
            args.Message = message;

            if (Commited != null)
                Commited (this, args);
        }