public WorkspaceHook(Area area, string username, Objects.Branch branch, Objects.Version v, Objects.Version old = null)
     : base()
 {
     m_Area       = area;
     m_Username   = username;
     m_Branch     = branch;
     m_Version    = v;
     m_OldVersion = old;
 }
Exemple #2
0
 public PushHeadHook(Area ws, string username, Objects.Branch branch, Objects.Version newHead, Objects.Version oldHead, List <Objects.Version> consumedVersions)
     : base(ws, username)
 {
     m_Branch             = branch;
     m_NewHead            = newHead;
     m_OldHead            = oldHead;
     m_AdditionalVersions = new Lazy <List <Objects.Version> >(() => { return(consumedVersions.Distinct().ToList()); });
     m_Modifications      = new Lazy <List <KeyValuePair <Objects.AlterationType, string> > >(() =>
     {
         Dictionary <string, string> oldRecords = new Dictionary <string, string>();
         HashSet <string> newRecords            = new HashSet <string>();
         if (oldHead != null)
         {
             foreach (var rec in ws.GetRecords(ws.GetVersion(oldHead.ID)))
             {
                 oldRecords.Add(rec.CanonicalName, rec.Fingerprint);
             }
         }
         List <KeyValuePair <Objects.AlterationType, string> > results = new List <KeyValuePair <Objects.AlterationType, string> >();
         if (newHead != null)
         {
             foreach (var rec in ws.GetRecords(ws.GetVersion(newHead.ID)))
             {
                 string oldfp;
                 if (oldRecords.TryGetValue(rec.CanonicalName, out oldfp))
                 {
                     if (oldfp != rec.Fingerprint)
                     {
                         results.Add(new KeyValuePair <Objects.AlterationType, string>(Objects.AlterationType.Update, rec.CanonicalName));
                     }
                 }
                 else
                 {
                     results.Add(new KeyValuePair <Objects.AlterationType, string>(Objects.AlterationType.Add, rec.CanonicalName));
                 }
                 newRecords.Add(rec.CanonicalName);
             }
         }
         foreach (var x in oldRecords)
         {
             if (!newRecords.Contains(x.Key))
             {
                 results.Add(new KeyValuePair <Objects.AlterationType, string>(Objects.AlterationType.Delete, x.Key));
             }
         }
         return(results);
     });
 }
Exemple #3
0
        private void FormatLog(Tuple <Objects.Version, int> vt, IEnumerable <KeyValuePair <bool, ResolvedAlteration> > filteralt, LogVerbOptions localOptions)
        {
            Objects.Version v = vt.Item1;
            if (m_LoggedVersions == null)
            {
                m_LoggedVersions = new HashSet <Guid>();
            }
            m_LoggedVersions.Add(v.ID);

            Objects.Branch branch = null;
            if (!m_Branches.TryGetValue(v.Branch, out branch))
            {
                branch = Workspace.GetBranch(v.Branch);
                m_Branches[v.Branch] = branch;
            }

            if (localOptions.Xml)
            {
                Printer.PrintMessage($"  <version id='{v.ID}' parent='{v.Parent}' branch='{v.Branch}' timestamp='{v.Timestamp.ToString("o")}' author='{XmlAttr(v.Author)}' published='{v.Published}'>");
                Printer.PrintMessage($"    <message>{XmlText(v.Message)}</message>");

                foreach (var y in Workspace.GetMergeInfo(v.ID))
                {
                    var mergeParent = Workspace.GetVersion(y.SourceVersion);
                    Printer.PrintMessage($"    <merge type='{y.Type.ToString().ToLower()}' version='{mergeParent.ID}' branch='{mergeParent.Branch}' />");
                }

                if (localOptions.Detail == LogVerbOptions.DetailMode.Full)
                {
                    foreach (var y in GetAlterations(v))
                    {
                        string operationName = y.Alteration.Type.ToString().ToLower();
                        if (y.Alteration.Type == Objects.AlterationType.Copy || y.Alteration.Type == Objects.AlterationType.Move)
                        {
                            Objects.Record prior  = Workspace.GetRecord(y.Alteration.PriorRecord.Value);
                            Objects.Record next   = Workspace.GetRecord(y.Alteration.NewRecord.Value);
                            bool           edited = (!next.IsDirectory && prior.DataIdentifier != next.DataIdentifier);
                            Printer.PrintMessage($"    <alteration type='{operationName}' path='{XmlAttr(next.CanonicalName)}' frompath='{XmlAttr(prior.CanonicalName)}' edited='{edited}' />");
                        }
                        else
                        {
                            Printer.PrintMessage($"    <alteration type='{operationName}' path='{y.Record.CanonicalName}' />");
                        }
                    }
                }
                Printer.PrintMessage("  </version>");
            }
            else if (localOptions.Jrunting)
            {
                // list of heads
                var    heads      = Workspace.GetHeads(v.ID);
                bool   isHead     = false;
                string headString = "";
                foreach (var y in heads)
                {
                    isHead = true;
                    if (headString.Length != 0)
                    {
                        headString = headString + ", ";
                    }
                    headString += Workspace.GetBranch(y.Branch).Name;
                }

                // message up to first newline
                string message = v.Message;
                if (message == null)
                {
                    message = string.Empty;
                }

                message = message.Replace("\r\n", "\n");

                var idx = message.IndexOf('\n');
                if (idx == -1)
                {
                    idx = message.Length;
                }
                message = message.Substring(0, idx);


                string mergemarker = "";
                if (Workspace.GetMergeInfo(v.ID).Count() > 0)
                {
                    var m      = Workspace.GetMergeInfo(v.ID).First();
                    var heads2 = Workspace.GetHeads(m.SourceVersion);
                    if (heads2.Count > 0)
                    {
                        if (isHead)
                        {
                            mergemarker = " <- " + Workspace.GetBranch(heads2.First().Branch).Name;
                        }
                        else
                        {
                            mergemarker = "M: " + Workspace.GetBranch(heads2.First().Branch).Name;
                        }
                    }
                }

                var date = new DateTime(v.Timestamp.Ticks, DateTimeKind.Utc).ToShortDateString();

                string pattern = "* #U#{0}## - ";

                if (isHead)
                {
                    pattern += "#Y#({4}{5})## ";
                }
                else if (mergemarker.Length > 0)
                {
                    pattern += "#Y#({5})## ";
                }


                pattern += "{1} ";
                var tagList = Workspace.GetTagsForVersion(v.ID);
                if (tagList.Count > 0)
                {
                    pattern += "#I#[" + string.Join(" ", tagList.Select(x => "\\#" + x).ToArray()) + "]## ";
                }
                pattern += "#g#({2}, {3})##";

                Printer.PrintMessage(pattern, v.ShortName, message, v.Author, date, headString, mergemarker);
            }
            else if (localOptions.Concise)
            {
                if (vt.Item2 != 0 && localOptions.Indent)
                {
                    Printer.Prefix = " ";
                }
                var  heads  = Workspace.GetHeads(v.ID);
                bool isHead = false;
                foreach (var y in heads)
                {
                    if (y.Branch == branch.ID)
                    {
                        isHead = true;
                        break;
                    }
                }
                string message = v.Message;
                if (message == null)
                {
                    message = string.Empty;
                }
                string tipmarker = " ";
                if (v.ID == m_Tip.ID)
                {
                    tipmarker = "#w#*##";
                }
                string mergemarker = " ";
                if (Workspace.GetMergeInfo(v.ID).FirstOrDefault() != null)
                {
                    mergemarker = "#s#M##";
                }
                var    tagList = Workspace.GetTagsForVersion(v.ID);
                string tags    = "";
                if (tagList.Count > 0)
                {
                    tags = "#s#" + string.Join(" ", tagList.Select(x => "\\#" + x).ToArray()) + "## ";
                }
                Printer.PrintMessage($"{tipmarker}#c#{v.ShortName}:##{mergemarker}({v.Revision}/{(isHead ? "#i#" : "#b#")}{branch.Name}##)"
                                     + $"{message.Replace("\r\n", " ").Replace('\n', ' ')} {tags}"
                                     + $"#q#({v.Author} {new DateTime(v.Timestamp.Ticks, DateTimeKind.Utc).ToShortDateString()})##");
                Printer.Prefix = "";
            }
            else
            {
                Printer.PrintMessage("");
                if (vt.Item2 != 0 && localOptions.Indent)
                {
                    Printer.Prefix = "| ";
                }
                string tipmarker = "";
                if (v.ID == m_Tip.ID)
                {
                    tipmarker = " #w#*<current>##";
                }
                Printer.PrintMessage("({0}) #c#{1}## on branch #b#{2}##{3}", v.Revision, v.ID, branch.Name, tipmarker);

                var mergeInfo = Workspace.GetMergeInfo(v.ID);
                foreach (var y in mergeInfo)
                {
                    var            mergeParent = Workspace.GetVersion(y.SourceVersion);
                    Objects.Branch mergeBranch = null;
                    if (!m_Branches.TryGetValue(mergeParent.Branch, out mergeBranch))
                    {
                        mergeBranch = Workspace.GetBranch(mergeParent.Branch);
                        m_Branches[mergeParent.Branch] = mergeBranch;
                    }
                    Printer.PrintMessage(" <- Merged from #s#{0}## on branch #b#{1}##", mergeParent.ID, mergeBranch.Name);
                }

                var heads = Workspace.GetHeads(v.ID);
                foreach (var y in heads)
                {
                    Objects.Branch headBranch = null;
                    if (!m_Branches.TryGetValue(y.Branch, out headBranch))
                    {
                        headBranch           = Workspace.GetBranch(y.Branch);
                        m_Branches[y.Branch] = headBranch;
                    }
                    string branchFlags = string.Empty;
                    if (branch.Terminus.HasValue)
                    {
                        branchFlags = " #e#(deleted)##";
                    }
                    Printer.PrintMessage(" ++ #i#Head## of branch #b#{0}## (#b#\"{1}\"##){2}", headBranch.ID, headBranch.Name, branchFlags);
                }
                if (branch.Terminus == v.ID)
                {
                    Printer.PrintMessage(" ++ #i#Terminus## of #e#deleted branch## #b#{0}## (#b#\"{1}\"##)", branch.ID, branch.Name);
                }

                Printer.PrintMessage("#b#Author:## {0} #q# {1} ##", v.Author, v.Timestamp.ToLocalTime());
                var tagList = Workspace.GetTagsForVersion(v.ID);
                if (tagList.Count > 0)
                {
                    Printer.PrintMessage(" #s#" + string.Join(" ", tagList.Select(x => "\\#" + x).ToArray()) + "##");
                }
                Printer.PrintMessage("");
                Printer.PushIndent();
                Printer.PrintMessage("{0}", string.IsNullOrWhiteSpace(v.Message) ? "<none>" : Printer.Escape(v.Message));
                Printer.PopIndent();

                if (localOptions.Detail == LogVerbOptions.DetailMode.Detailed || localOptions.Detail == LogVerbOptions.DetailMode.Full)
                {
                    var alterations = localOptions.Detail == LogVerbOptions.DetailMode.Detailed ? filteralt.Select(z => z.Value) : GetAlterations(v);
                    if (localOptions.Detail == LogVerbOptions.DetailMode.Full)
                    {
                        Printer.PrintMessage("");
                        Printer.PrintMessage("#b#Alterations:##");
                        foreach (var y in alterations.OrderBy(z => z.Alteration.Type))
                        {
                            if (y.Alteration.Type == Objects.AlterationType.Move || y.Alteration.Type == Objects.AlterationType.Copy)
                            {
                                string         operationName = y.Alteration.Type.ToString().ToLower();
                                Objects.Record prior         = Workspace.GetRecord(y.Alteration.PriorRecord.Value);
                                Objects.Record next          = Workspace.GetRecord(y.Alteration.NewRecord.Value);
                                bool           isUpdate      = false;
                                if (y.Alteration.Type == Objects.AlterationType.Move && !next.IsDirectory && prior.DataIdentifier != next.DataIdentifier)
                                {
                                    isUpdate      = true;
                                    operationName = "refactor";
                                }
                                Printer.PrintMessage("#{2}#({0})## {1}\n  <- #q#{3}##", operationName, y.Record.CanonicalName, GetAlterationFormat(y.Alteration.Type), prior.CanonicalName);
                                if (localOptions.Diff && isUpdate)
                                {
                                    InlineDiff(prior, next);
                                }
                            }
                            else
                            {
                                Printer.PrintMessage("#{2}#({0})## {1}", y.Alteration.Type.ToString().ToLower(), y.Record.CanonicalName, GetAlterationFormat(y.Alteration.Type));
                                if (localOptions.Diff && y.Alteration.Type == Objects.AlterationType.Update)
                                {
                                    InlineDiff(Workspace.GetRecord(y.Alteration.PriorRecord.Value), Workspace.GetRecord(y.Alteration.NewRecord.Value));
                                }
                            }
                        }
                    }
                    else
                    {
                        int[] alterationCounts = new int[5];
                        foreach (var y in alterations)
                        {
                            alterationCounts[(int)y.Alteration.Type]++;
                        }
                        bool   first      = true;
                        string formatData = "";
                        for (int i = 0; i < alterationCounts.Length; i++)
                        {
                            if (alterationCounts[i] != 0)
                            {
                                if (!first)
                                {
                                    formatData += ", ";
                                }
                                else
                                {
                                    formatData += "  ";
                                }
                                first       = false;
                                formatData += string.Format("#{2}#{0}s: {1}##", ((Objects.AlterationType)i).ToString(), alterationCounts[i], GetAlterationFormat((Objects.AlterationType)i));
                            }
                        }
                        if (formatData.Length > 0)
                        {
                            Printer.PrintMessage("");
                            Printer.PrintMessage("#b#Alterations:##");
                            Printer.PrintMessage(formatData);
                        }
                    }
                }
                else if (FilterOptions.Objects.Count != 0)
                {
                    Printer.PrintMessage("");
                    Printer.PrintMessage("#b#Alterations:##");
                    List <KeyValuePair <string, ResolvedAlteration> > altList = new List <KeyValuePair <string, ResolvedAlteration> >();
                    foreach (var y in GetAlterations(v))
                    {
                        string recName = y.Record.CanonicalName;
                        altList.Add(new KeyValuePair <string, ResolvedAlteration>(recName, y));
                    }

                    if (localOptions.Diff)
                    {
                        var records = FilterObjects(altList)
                                      .SelectMany(x => new[] { x.Value.Alteration.PriorRecord, x.Value.Alteration.NewRecord })
                                      .Where(x => x.HasValue)
                                      .Select(x => Workspace.GetRecord(x.Value));

                        Workspace.GetMissingObjects(records, null);
                    }

                    foreach (var y in FilterObjects(altList).Select(x => x.Value))
                    {
                        if (y.Alteration.Type == Objects.AlterationType.Move || y.Alteration.Type == Objects.AlterationType.Copy)
                        {
                            string         operationName = y.Alteration.Type.ToString().ToLower();
                            Objects.Record prior         = Workspace.GetRecord(y.Alteration.PriorRecord.Value);
                            Objects.Record next          = Workspace.GetRecord(y.Alteration.NewRecord.Value);
                            bool           isUpdate      = false;
                            if (y.Alteration.Type == Objects.AlterationType.Move && !next.IsDirectory && prior.DataIdentifier != next.DataIdentifier)
                            {
                                isUpdate      = true;
                                operationName = "refactor";
                            }

                            Printer.PrintMessage("#{2}#({0})## {1}\n  <- #q#{3}##", operationName, y.Record.CanonicalName, GetAlterationFormat(y.Alteration.Type), prior.CanonicalName);

                            if (localOptions.Diff && isUpdate)
                            {
                                InlineDiff(prior, next);
                            }
                        }
                        else
                        {
                            Printer.PrintMessage("#{2}#({0})## {1}", y.Alteration.Type.ToString().ToLower(), y.Record.CanonicalName, GetAlterationFormat(y.Alteration.Type));
                            if (localOptions.Diff && y.Alteration.Type == Objects.AlterationType.Update)
                            {
                                InlineDiff(Workspace.GetRecord(y.Alteration.PriorRecord.Value), Workspace.GetRecord(y.Alteration.NewRecord.Value));
                            }
                        }
                    }
                }

                Printer.Prefix = "";
                // Same-branch merge revisions. This only sort-of respects the limit :(
                //foreach (var y in mergeInfo)
                //{
                //	var mergeParent = Workspace.GetVersion(y.SourceVersion);
                //	if (mergeParent.Branch == v.Branch)
                //	{
                //		Printer.PushIndent();
                //		Printer.PrintMessage("---- Merged versions ----");

                //		List<Objects.Version> mergedVersions = new List<Objects.Version>();

                //		var p = mergeParent;
                //		do
                //		{
                //			mergedVersions.Add(p);
                //			if (p.Parent.HasValue && !m_LoggedVersions.Contains(p.Parent.Value))
                //				p = Workspace.GetVersion(p.Parent.Value);
                //			else
                //				p = null;
                //		} while (p != null);

                //		foreach (var a in ApplyHistoryFilter(mergedVersions, localOptions))
                //			FormatLog(a.Item1, a.Item2, localOptions);

                //		Printer.PrintMessage("-------------------------");
                //		Printer.PopIndent();
                //	}
                //}
            }
        }
Exemple #4
0
        protected override bool RunInternal(object options)
        {
            BranchControlVerbOptions localOptions = options as BranchControlVerbOptions;

            Objects.Branch branch;
            bool           multiple;

            if (string.IsNullOrEmpty(localOptions.Branch))
            {
                branch = Workspace.CurrentBranch;
            }
            else
            {
                branch = Workspace.GetBranchByPartialName(localOptions.Branch, out multiple);
            }

            if (branch == null)
            {
                Printer.PrintError("#x#Error:##\n Can't modify branch - unable to identify object for rename.");
                return(false);
            }

            bool didsomething = false;

            if (!string.IsNullOrEmpty(localOptions.DisallowMerge))
            {
                Objects.Branch otherBranch = Workspace.GetBranchByPartialName(localOptions.DisallowMerge, out multiple);
                if (otherBranch == null)
                {
                    Printer.PrintError("#x#Error:##\n Can't modify branch information - unknown branch for disallowing merges \"{0}\".", localOptions.DisallowMerge);
                    return(false);
                }
                didsomething = true;
                if (Workspace.DisallowMerge(branch, otherBranch))
                {
                    Printer.PrintMessage("#s#Success:## now disallowing merges from branch #b#\"{0}\"## ({1}) into #b#\"{2}\"## ({3})", otherBranch.Name, otherBranch.ShortID, branch.Name, branch.ShortID);
                }
                else
                {
                    Printer.PrintMessage("#w#Failure:## merges already disallowed.");
                }
            }
            if (!string.IsNullOrEmpty(localOptions.AllowMerge))
            {
                Objects.Branch otherBranch = Workspace.GetBranchByPartialName(localOptions.AllowMerge, out multiple);
                if (otherBranch == null)
                {
                    Printer.PrintError("#x#Error:##\n Can't modify branch information - unknown branch for allowing merges \"{0}\".", localOptions.DisallowMerge);
                    return(false);
                }
                didsomething = true;
                if (Workspace.AllowMerge(branch, otherBranch))
                {
                    Printer.PrintMessage("#s#Success:## now allowing merges from branch #b#\"{0}\"## ({1}) into #b#\"{2}\"## ({3})", otherBranch.Name, otherBranch.ShortID, branch.Name, branch.ShortID);
                }
                else
                {
                    Printer.PrintMessage("#w#Failure:## merges already allowed.");
                }
            }
            if (!didsomething)
            {
                var metainfo = Workspace.GetBranchMetadata(branch);
                Printer.PrintMessage("Displaying branch metadata info for #b#\"{0}\"## ({1})", branch.Name, branch.ID);
                foreach (var x in metainfo)
                {
                    string inherited = string.Empty;
                    if (x.Branch != branch.ID)
                    {
                        inherited = " #q#(inherited from \"" + Workspace.GetBranch(x.Branch).Name + "\")##";
                    }
                    Printer.PrintMessage("[{0}] - {1}{2}", x.Type, x.Operand1, inherited);
                }
            }
            return(true);
        }
 public PostCommitHook(Area ws, string username, Objects.Branch branch, Objects.Version version, Objects.Version old, List <KeyValuePair <AlterationType, string> > modifications)
     : base(ws, username, branch, version, old)
 {
     m_Modifications = modifications;
 }
 public PreCommitHook(Area ws, string username, Objects.Branch branch, Objects.Version version, string message, List <KeyValuePair <AlterationType, string> > modifications)
     : base(ws, username, branch, version)
 {
     m_Modifications = modifications;
     m_Message       = message;
 }
Exemple #7
0
        public bool Run(System.IO.DirectoryInfo workingDirectory, object options)
        {
            MergeInfoVerbOptions localOptions = options as MergeInfoVerbOptions;

            Printer.EnableDiagnostics = localOptions.Verbose;
            Area ws = Area.Load(workingDirectory);

            if (ws == null)
            {
                return(false);
            }
            foreach (var x in localOptions.Target)
            {
                Objects.Version v = ws.GetPartialVersion(x);
                if (v != null)
                {
                    Printer.PrintMessage("Merge information for version #c#{0}##.", v.ID);
                    var            mergeInfos   = ws.GetMergeList(v.ID);
                    HashSet <Guid> directMerges = new HashSet <Guid>();
                    foreach (var m in mergeInfos)
                    {
                        if (m == null)
                        {
                            Printer.PrintMessage(" - Merged into #w#unknown version##");
                        }
                        else
                        {
                            Objects.Branch b = ws.GetBranch(m.Branch);
                            directMerges.Add(b.ID);
                            Printer.PrintMessage(" - Merged into #b#{0}## on branch #b#\"{1}\"## ({2})", m.ShortName, b.Name, b.ShortID);
                        }
                    }
                    string deleteMarker = " #e#[deleted]##";
                    Printer.PrintMessage("Branch relationships:");
                    foreach (var b in ws.GetBranches(localOptions.Deleted))
                    {
                        HashSet <Guid> inputMerges      = new HashSet <Guid>();
                        HashSet <Guid> visitedMerges    = new HashSet <Guid>();
                        string         result           = "#w#unrelated";
                        int            relationshipCode = 0;
                        foreach (var h in ws.GetBranchHeads(b))
                        {
                            var headVersion = ws.GetVersion(h.Version);
                            if (relationshipCode < 4 && headVersion.ID == v.ID)
                            {
                                relationshipCode = 4;
                                result           = "#s#a branch head";
                            }
                            else if (relationshipCode < 3 && ws.GetHistory(headVersion).Any(z => z.ID == v.ID))
                            {
                                relationshipCode = 3;
                                result           = "#s#a direct parent";
                            }
                            else if (relationshipCode < 2 && directMerges.Contains(b.ID))
                            {
                                relationshipCode = 2;
                                result           = "#s#a merge parent";
                            }
                            else if (relationshipCode < 1 && ws.GetParentGraph(headVersion, false).ContainsKey(v.ID))
                            {
                                relationshipCode = 1;
                                result           = "#c#an indirect ancestor";
                            }
                        }
                        Printer.PrintMessage(" - #b#{0}## ({1}){3}: version is {2}##.", b.Name, b.ShortID, result, b.Terminus.HasValue ? deleteMarker : string.Empty);
                    }
                }
                else
                {
                    Printer.PrintError("#e#Can't locate version with ID #b#\"{0}\"#e#.", x);
                }
            }
            return(true);
        }
Exemple #8
0
        public bool Run(System.IO.DirectoryInfo workingDirectory, object options)
        {
            BeheadVerbOptions localOptions = options as BeheadVerbOptions;

            Printer.EnableDiagnostics = localOptions.Verbose;
            Area ws = Area.Load(workingDirectory);

            if (ws == null)
            {
                return(false);
            }
            Objects.Version version;
            if (!ws.FindVersion(localOptions.Target, out version))
            {
                if (localOptions.Force)
                {
                    if (!ws.ForceBehead(localOptions.Target))
                    {
                        Printer.PrintError("No head pointing to partial name \"{0}.\"", localOptions.Target);
                        return(false);
                    }
                    return(true);
                }
                else
                {
                    Printer.PrintError("Can't find version with partial name \"{0}.\"", localOptions.Target);
                    return(false);
                }
            }
            List <Objects.Head> heads = ws.GetHeads(version.ID);

            if (heads.Count == 0)
            {
                Printer.PrintError("Can't behead version {0}, version is not a head.", version.ID);
                return(false);
            }
            if (string.IsNullOrEmpty(localOptions.Branch))
            {
                if (heads.Count != 1)
                {
                    Printer.PrintError("Can't behead version {0}, version is present on {1} branches.", version.ID, heads.Count);
                    foreach (var x in heads)
                    {
                        Printer.PrintError("Could be head for branch \"{0}\"", ws.GetBranch(x.Branch).Name);
                    }
                    Printer.PrintError("Use the --branch option to specify the head more precisely.");
                    return(false);
                }
                var branchHeads = ws.GetBranchHeads(ws.GetBranch(heads[0].Branch));
                if (branchHeads.Count == 1 && !localOptions.Force)
                {
                    Printer.PrintError("Can't behead version - this would leave branch \"{0}\" with no head!", ws.GetBranch(heads[0].Branch).Name);
                    Printer.PrintError("Use --force if this is what you want.");
                }
                return(ws.RemoveHead(heads[0]));
            }
            else
            {
                foreach (var x in heads)
                {
                    Objects.Branch b = ws.GetBranch(x.Branch);
                    if (b.Name == localOptions.Branch)
                    {
                        var branchHeads = ws.GetBranchHeads(b);
                        if (branchHeads.Count == 1 && !localOptions.Force)
                        {
                            Printer.PrintError("Can't behead version - this would leave branch \"{0}\" with no head!", b.Name);
                            Printer.PrintError("Use --force if this is what you want.");
                            return(false);
                        }
                        return(ws.RemoveHead(x));
                    }
                }
                Printer.PrintError("Couldn't find branch head with branch: \"{0}\" and version {1}.", localOptions.Branch, version.ID);
            }
            return(false);
        }
Exemple #9
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);
        }