Esempio n. 1
0
        public int Checkin(CheckinOptions options, Func <string> generateCheckinComment = null)
        {
            if (options == null)
            {
                options = _checkinOptions;
            }

            var checkinComment = options.CheckinComment;

            if (string.IsNullOrWhiteSpace(checkinComment) && !options.NoGenerateCheckinComment && generateCheckinComment != null)
            {
                checkinComment = generateCheckinComment();
            }

            var pendingChanges = _workspace.GetPendingChanges();

            if (pendingChanges.IsEmpty())
            {
                throw new GitTfsException("Nothing to checkin!");
            }

            var workItemInfos = GetWorkItemInfos(options);
            var checkinNote   = _tfsHelper.CreateCheckinNote(options.CheckinNotes);

            var checkinProblems = _policyEvaluator.EvaluateCheckin(_workspace, pendingChanges, checkinComment, checkinNote, workItemInfos);

            if (checkinProblems.HasErrors)
            {
                bool overridePolicyErrors = options.Force && !string.IsNullOrWhiteSpace(options.OverrideReason);
                TraceCheckinPolicyErrors(checkinProblems, overridePolicyErrors);

                if (!options.Force)
                {
                    throw new GitTfsException("No changes checked in.");
                }
                if (string.IsNullOrWhiteSpace(options.OverrideReason))
                {
                    throw new GitTfsException("A reason must be supplied (-f REASON) to override the policy violations.");
                }
            }

            var policyOverride = GetPolicyOverrides(options, checkinProblems.Result);

            try
            {
                var newChangeset = _workspace.Checkin(pendingChanges, checkinComment, options.AuthorTfsUserId, checkinNote, workItemInfos, policyOverride, options.OverrideGatedCheckIn);
                if (newChangeset == 0)
                {
                    throw new GitTfsException("Checkin failed!");
                }
                else
                {
                    return(newChangeset);
                }
            }
            catch (GitTfsGatedCheckinException e)
            {
                return(LaunchGatedCheckinBuild(e.AffectedBuildDefinitions, e.ShelvesetName, e.CheckInTicket));
            }
        }
Esempio n. 2
0
        public long Checkin(CheckinOptions options)
        {
            if (options == null)
            {
                options = _checkinOptions;
            }

            var pendingChanges = _workspace.GetPendingChanges();

            if (pendingChanges.IsEmpty())
            {
                throw new GitTfsException("Nothing to checkin!");
            }

            var workItemInfos = GetWorkItemInfos(options);
            var checkinNote   = _tfsHelper.CreateCheckinNote(options.CheckinNotes);

            var checkinProblems = _policyEvaluator.EvaluateCheckin(_workspace, pendingChanges, options.CheckinComment, checkinNote, workItemInfos);

            if (checkinProblems.HasErrors)
            {
                foreach (var message in checkinProblems.Messages)
                {
                    if (options.Force && string.IsNullOrWhiteSpace(options.OverrideReason) == false)
                    {
                        _stdout.WriteLine("[OVERRIDDEN] " + message);
                    }
                    else
                    {
                        _stdout.WriteLine("[ERROR] " + message);
                    }
                }
                if (!options.Force)
                {
                    throw new GitTfsException("No changes checked in.");
                }
                if (String.IsNullOrWhiteSpace(options.OverrideReason))
                {
                    throw new GitTfsException("A reason must be supplied (-f REASON) to override the policy violations.");
                }
            }

            var policyOverride = GetPolicyOverrides(options, checkinProblems.Result);
            var newChangeset   = _workspace.Checkin(pendingChanges, options.CheckinComment, options.AuthorTfsUserId, checkinNote, workItemInfos, policyOverride, options.OverrideGatedCheckIn);

            if (newChangeset == 0)
            {
                throw new GitTfsException("Checkin failed!");
            }
            else
            {
                return(newChangeset);
            }
        }
Esempio n. 3
0
        public long Checkin()
        {
            var pendingChanges = _workspace.GetPendingChanges();

            if (pendingChanges.IsEmpty())
            {
                throw new GitTfsException("Nothing to checkin!");
            }

            var workItemInfos   = GetWorkItemInfos();
            var checkinProblems = _policyEvaluator.EvaluateCheckin(_workspace, pendingChanges, _checkinOptions.CheckinComment, workItemInfos);

            if (checkinProblems.HasErrors)
            {
                foreach (var message in checkinProblems.Messages)
                {
                    _stdout.WriteLine("[ERROR] " + message);
                }
                if (!_checkinOptions.Force)
                {
                    throw new GitTfsException("No changes checked in.");
                }
                if (String.IsNullOrWhiteSpace(_checkinOptions.OverrideReason))
                {
                    throw new GitTfsException("A reason must be supplied (-f REASON) to override the policy violations.");
                }
            }

            var policyOverride = GetPolicyOverrides(checkinProblems.Result);
            var newChangeset   = _workspace.Checkin(pendingChanges, _checkinOptions.CheckinComment, null, workItemInfos, policyOverride);

            if (newChangeset == 0)
            {
                throw new GitTfsException("Checkin failed!");
            }
            else
            {
                return(newChangeset);
            }
        }
Esempio n. 4
0
        public int Checkin(CheckinOptions options, Func <string> generateCheckinComment = null)
        {
            if (options == null)
            {
                options = _checkinOptions;
            }

            var checkinComment = options.CheckinComment;

            if (string.IsNullOrWhiteSpace(checkinComment) && !options.NoGenerateCheckinComment && generateCheckinComment != null)
            {
                checkinComment = generateCheckinComment();
            }

            var pendingChanges = _workspace.GetPendingChanges();

            if (pendingChanges.IsEmpty())
            {
                throw new GitTfsException("Nothing to checkin!");
            }

            var workItemInfos = GetWorkItemInfos(options);
            var checkinNote   = _tfsHelper.CreateCheckinNote(options.CheckinNotes);

            var checkinProblems = _policyEvaluator.EvaluateCheckin(_workspace, pendingChanges, checkinComment, checkinNote, workItemInfos);

            if (checkinProblems.HasErrors)
            {
                foreach (var message in checkinProblems.Messages)
                {
                    if (options.Force && string.IsNullOrWhiteSpace(options.OverrideReason) == false)
                    {
                        Trace.TraceWarning("[OVERRIDDEN] " + message);
                    }
                    else
                    {
                        Trace.TraceError("[ERROR] " + message);

                        Trace.TraceInformation("Note: If the checkin policy fails because the assemblies failed to load, please run the file `enable_checkin_policies_support.bat` in the git-tfs directory and try again.");
                    }
                }
                if (!options.Force)
                {
                    throw new GitTfsException("No changes checked in.");
                }
                if (string.IsNullOrWhiteSpace(options.OverrideReason))
                {
                    throw new GitTfsException("A reason must be supplied (-f REASON) to override the policy violations.");
                }
            }

            var policyOverride = GetPolicyOverrides(options, checkinProblems.Result);

            try
            {
                var newChangeset = _workspace.Checkin(pendingChanges, checkinComment, options.AuthorTfsUserId, checkinNote, workItemInfos, policyOverride, options.OverrideGatedCheckIn);
                if (newChangeset == 0)
                {
                    throw new GitTfsException("Checkin failed!");
                }
                else
                {
                    return(newChangeset);
                }
            }
            catch (GitTfsGatedCheckinException e)
            {
                return(LaunchGatedCheckinBuild(e.AffectedBuildDefinitions, e.ShelvesetName, e.CheckInTicket));
            }
        }