예제 #1
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);
        }
예제 #2
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);
        }
예제 #3
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);
        }