Exemple #1
0
        protected override bool RunInternal(IRemoteClient client, RemoteCommandVerbOptions options)
        {
            LockCheckVerbOptions localOptions = options as LockCheckVerbOptions;

            if (string.IsNullOrEmpty(localOptions.Path) && !localOptions.Full)
            {
                Printer.PrintMessage("#x#Error:## missing specification of lock path!");
            }
            if (!localOptions.Full)
            {
                string fullPath = System.IO.Path.GetFullPath(localOptions.Path);
                if (System.IO.Directory.Exists(fullPath))
                {
                    fullPath += "/";
                }
                else if (!System.IO.File.Exists(fullPath))
                {
                    Printer.PrintMessage("#w#Warning:## File #b#\"{0}\"## does not exist (yet).", localOptions.Path);
                }
                localOptions.Path = client.Workspace.GetLocalPath(fullPath);
            }
            if (string.IsNullOrEmpty(localOptions.Branch))
            {
                localOptions.Branch = client.Workspace.CurrentBranch.ID.ToString();
            }
            if (localOptions.Break)
            {
                return(client.BreakLocks(localOptions.Path, localOptions.Branch, localOptions.AllBranches, localOptions.Full));
            }
            else
            {
                return(client.ListLocks(localOptions.Path, localOptions.Branch, localOptions.AllBranches, localOptions.Full));
            }
        }
Exemple #2
0
        protected override bool RunInternal(IRemoteClient client, RemoteCommandVerbOptions options)
        {
            PushVerbOptions localOptions = options as PushVerbOptions;

            if (!client.Push(localOptions.Branch))
            {
                return(false);
            }

            if (client.RequestUpdate)
            {
                Printer.PrintMessage("Server has remotely merged the current branch.");
                if (Printer.Prompt("Update?"))
                {
                    client.Close();
                    client = client.Workspace.Connect(URL, false);
                    if (!client.Pull(true, null, false))
                    {
                        return(false);
                    }
                    client.Workspace.Update(new Area.MergeSpecialOptions());
                }
            }
            return(true);
        }
Exemple #3
0
 protected override bool RunInternal(Client client, RemoteCommandVerbOptions options)
 {
     SyncRecordsOptions localOptions = options as SyncRecordsOptions;
     if (localOptions.Current)
         return client.SyncCurrentRecords();
     else
         return client.SyncRecords();
 }
Exemple #4
0
        protected override bool RunInternal(IRemoteClient client, RemoteCommandVerbOptions options)
        {
            SyncRecordsOptions localOptions = options as SyncRecordsOptions;

            if (localOptions.Current)
            {
                return(client.SyncCurrentRecords());
            }
            else
            {
                return(client.SyncAllRecords());
            }
        }
Exemple #5
0
        protected override bool RunInternal(IRemoteClient client, RemoteCommandVerbOptions options)
        {
            PushStashVerbOptions localOptions = options as PushStashVerbOptions;

            foreach (var x in localOptions.Names)
            {
                var stash = StashList.LookupStash(client.Workspace, x);
                if (stash != null)
                {
                    client.PushStash(stash);
                }
            }
            return(true);
        }
Exemple #6
0
        protected override bool RunInternal(IRemoteClient client, RemoteCommandVerbOptions options)
        {
            PullStashVerbOptions localOptions = options as PullStashVerbOptions;

            foreach (var x in localOptions.Names)
            {
                bool ambiguous;
                var  stash = StashList.LookupStash(client.Workspace, x, out ambiguous, true);
                if (stash == null && !ambiguous)
                {
                    client.PullStash(x);
                }
            }
            return(true);
        }
Exemple #7
0
        protected override bool RunInternal(Client client, RemoteCommandVerbOptions options)
        {
            CloneVerbOptions localOptions = options as CloneVerbOptions;
            if (localOptions.QuietFail && new System.IO.DirectoryInfo(System.IO.Path.Combine(TargetDirectory.FullName, ".versionr")).Exists)
                return true;
            bool result = false;
            try
            {
                TargetDirectory.Create();
            }
            catch
            {
                Printer.PrintError("#e#Error - couldn't create subdirectory \"{0}\"##", TargetDirectory);
                return false;
            }
            if (localOptions.Full.HasValue)
                result = client.Clone(localOptions.Full.Value);
            else
            {
                result = client.Clone(true);
                if (!result)
                    result = client.Clone(false);
            }
            if (result)
            {
                Printer.PrintMessage("Successfully cloned from remote vault. Initializing default remote.");
                string remoteName = "default";
                
                if (client.Workspace.SetRemote(client.Host, client.Port, client.Module, remoteName))
                    Printer.PrintMessage("Configured remote \"#b#{0}##\" as: #b#{1}##", remoteName, client.VersionrURL);

                if (localOptions.Partial != null)
                    client.Workspace.SetPartialPath(localOptions.Partial);

                if (localOptions.Update)
                {
                    client.Pull(false, string.IsNullOrEmpty(localOptions.Branch) ? client.Workspace.CurrentBranch.ID.ToString() : localOptions.Branch);
                    Area area = Area.Load(client.Workspace.Root);
                    area.Checkout(localOptions.Branch, false, false);
                }

                if (localOptions.Synchronize)
                    return client.SyncRecords();
            }
            return result;
        }
Exemple #8
0
        protected override bool RunInternal(Client client, RemoteCommandVerbOptions options)
        {
            PullVerbOptions localOptions = options as PullVerbOptions;
            bool objects = true;
            if (localOptions.PullAll)
                objects = false;
            if (localOptions.List)
            {
                var branches = client.ListBranches();
                if (branches == null)
                    return false;
                Printer.PrintMessage("Displaying remote branches:");
                foreach (var x in branches.Item1)
                {
                    if (!localOptions.Deleted && x.Terminus.HasValue)
                        continue;
                    string tipmarker = "";
                    if (x.ID == client.Workspace.CurrentBranch.ID)
                        tipmarker = " #w#*<current>##";
                    Printer.PrintMessage("#b#{1}## - #c#{0}##{2}", x.ID, x.Name, tipmarker);
                    string heading = string.Empty;
                    var localBranch = client.Workspace.GetBranch(x.ID);
                    if (x.Terminus.HasValue)
                    {
                        var terminus = branches.Item3[x.Terminus.Value];
                        bool present = client.Workspace.GetVersion(x.Terminus.Value) != null;
                        string presentMarker = present ? "" : " #w#(behind)##";
                        if (present && localBranch != null)
                        {
                            if (localBranch.Terminus.Value != x.Terminus.Value)
                                presentMarker += " #w#(ahead)##";
                        }
                        if (localBranch != null && !localBranch.Terminus.HasValue)
                            presentMarker += " #w#(not locally deleted)##";
                        if (localBranch == null)
                            presentMarker += " #w#(not synchronized)##";
                        Printer.PrintMessage("  #e#(deleted)## - Last version: #b#{0}##{3}, #q#{2} {1}##", terminus.ShortName, terminus.Timestamp.ToLocalTime(), terminus.Author, presentMarker);
                    }
                    foreach (var z in branches.Item2.Where(y => y.Key == x.ID))
                    {
                        bool present = client.Workspace.GetVersion(z.Value) != null;
                        string presentMarker = present ? "" : " #w#(behind)##";
                        if (present && localBranch != null)
                        {
                            var localHeads = client.Workspace.GetBranchHeads(localBranch);
                            if (localHeads.Count == 1 && localHeads[0].Version != z.Value)
                                presentMarker += " #w#(ahead)##";
                        }
                        if (localBranch != null && localBranch.Terminus.HasValue)
                            presentMarker += " #e#(locally deleted)##";
                        if (localBranch == null)
                            presentMarker += " #w#(not synchronized)##";
                        var head = branches.Item3[z.Value];
                        Printer.PrintMessage("  #s#(head)## - Version: #b#{0}##{3}, #q#{2} {1}##", head.ShortName, head.Timestamp.ToLocalTime(), head.Author, presentMarker);
                    }
                }
                return true;
            }

            if (!client.Pull(localOptions.PullObjects.HasValue ? localOptions.PullObjects.Value : objects, localOptions.RemoteBranch, localOptions.PullAll))
                return false;
            if (localOptions.Update)
            {
                client.Workspace.Update();
            }
            return true;
        }
 protected abstract bool RunInternal(Client client, RemoteCommandVerbOptions options);
Exemple #10
0
        protected override bool RunInternal(IRemoteClient client, RemoteCommandVerbOptions options)
        {
            PushVerbOptions localOptions = options as PushVerbOptions;

            return(client.PushRecords());
        }
Exemple #11
0
        protected override bool RunInternal(IRemoteClient client, RemoteCommandVerbOptions options)
        {
            AheadVerbOptions localOptions = options as AheadVerbOptions;

            Info.DisplayInfo(client.Workspace);
            Objects.Branch desiredBranch = client.Workspace.CurrentBranch;
            if (!string.IsNullOrEmpty(localOptions.Branch))
            {
                bool multiple;
                desiredBranch = client.Workspace.GetBranchByPartialName(localOptions.Branch, out multiple);
                if (desiredBranch == null)
                {
                    Printer.PrintError("#e#Error:## Local branch #b#`{0}`## not found.", localOptions.Branch);
                    return(false);
                }
            }
            var branches = client.ListBranches();

            if (branches == null)
            {
                Printer.PrintError("#e#Error:## Server does not support branch list operation.");
                return(false);
            }

            foreach (var x in branches.Item1)
            {
                if (x.ID != desiredBranch.ID && !localOptions.AllBranches)
                {
                    continue;
                }

                var localBranch = client.Workspace.GetBranch(x.ID);

                if (localOptions.AllBranches && localBranch == null && !localOptions.ShowUninteresting)
                {
                    continue;
                }

                if (x.Terminus.HasValue && (!localOptions.AllBranches || localOptions.IncludeDeleted))
                {
                    bool present = client.Workspace.GetVersion(x.Terminus.Value) != null;

                    Objects.Version terminus = null;
                    branches.Item3.TryGetValue(x.Terminus.Value, out terminus);

                    string presentMarker = present ? "" : " #w#(behind)##";
                    if (present && localBranch != null)
                    {
                        if (localBranch.Terminus.Value != x.Terminus.Value)
                        {
                            presentMarker += " #w#(ahead)##";
                        }
                        else
                        {
                            if (localOptions.AllBranches && !localOptions.ShowUninteresting)
                            {
                                continue;
                            }

                            presentMarker += " #s#(up-to-date)##";
                        }
                    }
                    if (localBranch != null && !localBranch.Terminus.HasValue)
                    {
                        presentMarker += " #w#(not locally deleted)##";
                    }
                    if (localBranch == null)
                    {
                        presentMarker += " #w#(not synchronized)##";
                    }

                    string branchMarker = localOptions.AllBranches ? "#b#" + x.Name + "##" : "";

                    if (terminus == null)
                    {
                        Printer.PrintMessage("Remote - #e#(deleted)## {2} - Last version: #e#(unknown)## #b#{0}##{1}", x.Terminus.Value, presentMarker, branchMarker);
                    }
                    else
                    {
                        Printer.PrintMessage("Remote - #e#(deleted)## {4} - Last version: #b#{0}##{3}, #q#{2} {1}##", terminus.ShortName, terminus.Timestamp.ToLocalTime(), terminus.Author, presentMarker, branchMarker);
                    }
                }
                foreach (var z in branches.Item2.Where(y => y.Key == x.ID))
                {
                    bool present = client.Workspace.GetVersion(z.Value) != null;

                    string presentMarker = present ? "" : " #w#(behind)##";
                    if (present && localBranch != null)
                    {
                        var localHeads = client.Workspace.GetBranchHeads(localBranch);
                        if (localHeads.Count == 1 && localHeads[0].Version != z.Value)
                        {
                            presentMarker += " #w#(ahead)##";
                        }
                        else
                        {
                            if (localOptions.AllBranches && !localOptions.ShowUninteresting)
                            {
                                continue;
                            }
                            presentMarker += " #s#(up-to-date)##";
                        }
                    }
                    if (localBranch != null && localBranch.Terminus.HasValue)
                    {
                        presentMarker += " #e#(locally deleted)##";
                    }
                    if (localBranch == null)
                    {
                        presentMarker += " #w#(not synchronized)##";
                    }

                    string branchMarker = localOptions.AllBranches ? "#b#" + x.Name + "##" : "";

                    var head = branches.Item3[z.Value];
                    Printer.PrintMessage("Remote - #s#(active)## {4} - Version: #b#{0}##{3}, #q#{2} {1}##", head.ShortName, head.Timestamp.ToLocalTime(), head.Author, presentMarker, branchMarker);
                }
            }
            return(true);
        }
Exemple #12
0
        public bool Run(System.IO.DirectoryInfo workingDirectory, object options)
        {
            RemoteCommandVerbOptions localOptions = options as RemoteCommandVerbOptions;

            Printer.EnableDiagnostics = localOptions.Verbose;
            IRemoteClient client = null;
            Area          ws     = null;

            if (NeedsWorkspace)
            {
                ws = Area.Load(workingDirectory, Headless);
                if (ws == null)
                {
                    Printer.Write(Printer.MessageType.Error, string.Format("#x#Error:##\n  The current directory #b#`{0}`## is not part of a vault.\n", workingDirectory.FullName));
                    return(false);
                }
            }
            TargetDirectory = workingDirectory;
            bool requireRemoteName = false;

            LocalState.RemoteConfig config = null;
            if (ws != null)
            {
                config = ws.GetRemote(string.IsNullOrEmpty(localOptions.Remote) ? "default" : localOptions.Remote);
                if (UpdateRemoteTimestamp && config != null)
                {
                    ws.UpdateRemoteTimestamp(config);
                }
            }
            if (config == null && string.IsNullOrEmpty(localOptions.Remote))
            {
                requireRemoteName = true;
            }

            if (config == null && requireRemoteName)
            {
                Printer.PrintError("You must specify either a remote server or name.");
                return(false);
            }
            if (config == null)
            {
                config = new LocalState.RemoteConfig()
                {
                    Module = localOptions.Remote
                }
            }
            ;

            if (ws == null)
            {
                // No workspace; must use Versionr Client
                client = new Client(workingDirectory);
                if (!((Client)client).Connect(config.URL, RequiresWriteAccess))
                {
                    client = null;
                }
            }
            else
            {
                client = ws.Connect(config.URL, RequiresWriteAccess);
                URL    = config.URL;
            }

            if (client == null || !client.Connected)
            {
                Printer.PrintError("Couldn't connect to server:## #b#{0}##", config.URL);
                return(false);
            }
            bool result = RunInternal(client, localOptions);

            client.Close();
            return(result);
        }
Exemple #13
0
 protected abstract bool RunInternal(IRemoteClient client, RemoteCommandVerbOptions options);
Exemple #14
0
 protected override bool RunInternal(Client client, RemoteCommandVerbOptions options)
 {
     PushVerbOptions localOptions = options as PushVerbOptions;
     return client.Push(localOptions.Branch);
 }
Exemple #15
0
        protected override bool RunInternal(IRemoteClient client, RemoteCommandVerbOptions options)
        {
            CloneVerbOptions localOptions = options as CloneVerbOptions;

            if (localOptions.Path.Count > 1)
            {
                Printer.PrintError("#e#Error:## Clone path is invalid. Please specify a subfolder to clone in to or leave empty to clone into the current directory.");
                return(false);
            }

            // Choose target directory from server name or path
            if (localOptions.Path != null && localOptions.Path.Count == 1)
            {
                string subdir = localOptions.Path[0];
                if (!string.IsNullOrEmpty(subdir))
                {
                    System.IO.DirectoryInfo info;
                    try
                    {
                        info = new System.IO.DirectoryInfo(System.IO.Path.Combine(TargetDirectory.FullName, subdir));
                    }
                    catch
                    {
                        Printer.PrintError("#e#Error - invalid subdirectory \"{0}\"##", subdir);
                        return(false);
                    }
                    Printer.PrintMessage("Target directory: #b#{0}##.", info);
                    TargetDirectory = info;
                }
            }

            if (localOptions.QuietFail && new System.IO.DirectoryInfo(System.IO.Path.Combine(TargetDirectory.FullName, ".versionr")).Exists)
            {
                return(true);
            }

            try
            {
                var ws = Area.Load(TargetDirectory, Headless, localOptions.BreachContainment);
                if (ws != null)
                {
                    CloneVerbOptions cloneOptions = options as CloneVerbOptions;
                    if (cloneOptions != null && cloneOptions.QuietFail)
                    {
                        Printer.PrintMessage("Directory already contains a vault. Skipping.");
                        return(false);
                    }
                    Printer.PrintError("This command cannot function with an active Versionr vault.");
                    return(false);
                }
            }
            catch
            {
            }
            bool result = false;

            try
            {
                TargetDirectory.Create();
            }
            catch
            {
                Printer.PrintError("#e#Error - couldn't create subdirectory \"{0}\"##", TargetDirectory);
                return(false);
            }
            client.BaseDirectory = TargetDirectory;
            if (localOptions.Full.HasValue)
            {
                result = client.Clone(localOptions.Full.Value);
            }
            else
            {
                result = client.Clone(true);
                if (!result)
                {
                    result = client.Clone(false);
                }
            }
            if (result)
            {
                Printer.PrintMessage("Successfully cloned from remote vault. Initializing default remote.");
                string remoteName = "default";

                if (client.Workspace.SetRemote(client.URL, remoteName))
                {
                    Printer.PrintMessage("Configured remote \"#b#{0}##\" as: #b#{1}##", remoteName, client.URL);
                }

                if (localOptions.Partial != null)
                {
                    client.Workspace.SetPartialPath(localOptions.Partial);
                }

                if (localOptions.Update)
                {
                    client.Pull(false, string.IsNullOrEmpty(localOptions.Branch) ? client.Workspace.CurrentBranch.ID.ToString() : localOptions.Branch);
                    Area area = Area.Load(client.Workspace.Root);
                    area.Checkout(localOptions.Branch, false, false);
                }

                if (localOptions.Synchronize)
                {
                    return(client.SyncAllRecords());
                }
            }
            return(result);
        }
Exemple #16
0
        protected override bool RunInternal(IRemoteClient client, RemoteCommandVerbOptions options)
        {
            PullVerbOptions localOptions = options as PullVerbOptions;
            bool            objects      = true;

            if (localOptions.PullAll)
            {
                objects = false;
            }
            if (localOptions.List)
            {
                var branches = client.ListBranches();
                if (branches == null)
                {
                    return(false);
                }
                Printer.PrintMessage("Displaying remote branches:");
                foreach (var x in branches.Item1)
                {
                    if (!localOptions.Deleted && x.Terminus.HasValue)
                    {
                        continue;
                    }
                    string tipmarker = "";
                    if (x.ID == client.Workspace.CurrentBranch.ID)
                    {
                        tipmarker = " #w#*<current>##";
                    }
                    Printer.PrintMessage("#b#{1}## - #c#{0}##{2}", x.ID, x.Name, tipmarker);
                    string heading     = string.Empty;
                    var    localBranch = client.Workspace.GetBranch(x.ID);
                    if (x.Terminus.HasValue)
                    {
                        Objects.Version terminus      = null;
                        bool            present       = client.Workspace.GetVersion(x.Terminus.Value) != null;
                        string          presentMarker = present ? "" : " #w#(behind)##";
                        if (!branches.Item3.TryGetValue(x.Terminus.Value, out terminus))
                        {
                            Printer.PrintMessage("  #e#(deleted)## - #w#(no data)##");
                            continue;
                        }
                        if (present && localBranch != null)
                        {
                            if (localBranch.Terminus.Value != x.Terminus.Value)
                            {
                                presentMarker += " #w#(ahead)##";
                            }
                        }
                        if (localBranch != null && !localBranch.Terminus.HasValue)
                        {
                            presentMarker += " #w#(not locally deleted)##";
                        }
                        if (localBranch == null)
                        {
                            presentMarker += " #w#(not synchronized)##";
                        }
                        Printer.PrintMessage("  #e#(deleted)## - Last version: #b#{0}##{3}, #q#{2} {1}##", terminus.ShortName, terminus.Timestamp.ToLocalTime(), terminus.Author, presentMarker);
                    }
                    foreach (var z in branches.Item2.Where(y => y.Key == x.ID))
                    {
                        bool   present       = client.Workspace.GetVersion(z.Value) != null;
                        string presentMarker = present ? "" : " #w#(behind)##";
                        if (present && localBranch != null)
                        {
                            var localHeads = client.Workspace.GetBranchHeads(localBranch);
                            if (localHeads.Count == 1 && localHeads[0].Version != z.Value)
                            {
                                presentMarker += " #w#(ahead)##";
                            }
                        }
                        if (localBranch != null && localBranch.Terminus.HasValue)
                        {
                            presentMarker += " #e#(locally deleted)##";
                        }
                        if (localBranch == null)
                        {
                            presentMarker += " #w#(not synchronized)##";
                        }
                        var head = branches.Item3[z.Value];
                        Printer.PrintMessage("  #s#(head)## - Version: #b#{0}##{3}, #q#{2} {1}##", head.ShortName, head.Timestamp.ToLocalTime(), head.Author, presentMarker);
                    }
                }
                return(true);
            }

            if (!client.Pull(localOptions.PullObjects.HasValue ? localOptions.PullObjects.Value : objects, localOptions.RemoteBranch, localOptions.PullAll, localOptions.AcceptDeletes))
            {
                return(false);
            }
            if (localOptions.Update)
            {
                client.Workspace.Update(new Area.MergeSpecialOptions());
            }
            return(true);
        }