Example #1
0
        // uses rebase and works only with HEAD
        public int Run()
        {
            if (_globals.Repository.IsBare)
            {
                throw new GitTfsException("error: you should specify the local branch to checkin for a bare repository.");
            }

            return(_writer.Write("HEAD", PerformRCheckin));
        }
Example #2
0
 public int Run(string shelvesetName, string refToShelve)
 {
     return(_writer.Write(refToShelve, (changeset, referenceToShelve) =>
     {
         if (!_checkinOptions.Force && changeset.Remote.HasShelveset(shelvesetName))
         {
             _stdout.WriteLine("Shelveset \"" + shelvesetName + "\" already exists. Use -f to replace it.");
             return GitTfsExitCodes.ForceRequired;
         }
         changeset.Remote.Shelve(shelvesetName, referenceToShelve, changeset, EvaluateCheckinPolicies);
         return GitTfsExitCodes.OK;
     }));
 }
Example #3
0
 public int Run(string refToCheckin)
 {
     return(_writer.Write(refToCheckin, changeset =>
     {
         var newChangesetId = DoCheckin(changeset, refToCheckin);
         _stdout.WriteLine("TFS Changeset #" + newChangesetId + " was created. Marking it as a merge commit...");
         changeset.Remote.Fetch(new Dictionary <long, string> {
             { newChangesetId, refToCheckin }
         });
         if (refToCheckin == "HEAD")
         {
             changeset.Remote.Repository.CommandNoisy("merge", changeset.Remote.MaxCommitHash);
         }
         return GitTfsExitCodes.OK;
     }));
 }
Example #4
0
        public int Run(string shelvesetName, string refToShelve)
        {
            return(_writer.Write(refToShelve, (changeset, referenceToShelve) =>
            {
                if (!_checkinOptions.Force && changeset.Remote.HasShelveset(shelvesetName))
                {
                    _stdout.WriteLine("Shelveset \"" + shelvesetName + "\" already exists. Use -f to replace it.");
                    return GitTfsExitCodes.ForceRequired;
                }

                var commit = _globals.Repository.GetCommit(refToShelve);
                var message = commit != null // this is only null in the unit tests
                    ? BuildCommitMessage(commit, !_checkinOptions.NoGenerateCheckinComment,
                                         changeset.Remote.MaxCommitHash)
                    : string.Empty;

                var shelveSpecificCheckinOptions = _checkinOptionsFactory.BuildShelveSetSpecificCheckinOptions(_checkinOptions, message);

                changeset.Remote.Shelve(shelvesetName, referenceToShelve, changeset, shelveSpecificCheckinOptions, EvaluateCheckinPolicies);
                return GitTfsExitCodes.OK;
            }));
        }
Example #5
0
 // uses rebase and works only with HEAD
 public int Run()
 {
     return(_writer.Write("HEAD", PerformRCheckin));
 }
Example #6
0
 public int Run(string refToCheckin)
 {
     return(_writer.Write(refToCheckin, PerformCheckin));
 }
Example #7
0
 public int Run(string refToCheckin)
 {
     return(_writer.Write(refToCheckin, changeset => PerformCheckin(changeset, refToCheckin)));
 }
Example #8
0
        // uses rebase and works only with HEAD
        public int Run()
        {
            _cachePath     = _globals.Repository.GitPath + ".git\\cache";
            _tfsBranchPath = _globals.Repository.GitPath + ".git\\refs\\remotes\\tfs";
            _currentBranch = _globals.Repository.GetCurrentBranchFriendlyName();

            // only allow tfs branches
            if (!"master".Equals(_currentBranch) && !Regex.Match(_currentBranch, @"^R\d{2}_\d$").Success)
            {
                throw new GitTfsException("error: current branch " + _currentBranch + " is not a target branch.");
            }

            // run a git pull rebase
            Trace.TraceInformation("Phase 1: Pull from git remote...");
            try
            {
                _globals.Repository.CommandOneline("pull", "--rebase");
                _globals.Repository.CommandOneline("tfs", "bootstrap");
            } catch (Exception)
            {
                _globals.Repository.CommandOneline("rebase", "--abort");
                throw new GitTfsException("'git pull' failed because of conflicts.")
                      .WithRecommendation("Run 'git pull' manually and resolve conflicts, then run 'git tfs push' again.");
            }
            Trace.TraceInformation("Done");
            Trace.TraceInformation("Phase 2: Push to tfsvc remote...");
            // Sync git remote with tfs local remote
            string gitRemote = "master", tfsRemote = "default";

            if (!"master".Equals(_currentBranch))
            {
                gitRemote = tfsRemote = _currentBranch;
            }

            string sourceOfCopy = _globals.Repository.GitPath + ".git\\refs\\remotes\\origin\\" + gitRemote;
            string targetOfCopy = _globals.Repository.GitPath + ".git\\refs\\remotes\\tfs\\" + tfsRemote;

            if (File.Exists(sourceOfCopy))
            {
                File.Copy(sourceOfCopy, targetOfCopy, true);
            }

            // After a 'git gc', refs/remote/tfs/branch will be deleted, restore it from cache if it exist
            if (!File.Exists(targetOfCopy))
            {
                bool copySuccess = CopyFromCache(_currentBranch);
                // Cache does not exist, which is the first time 'git tfs push' is run
                if (!copySuccess)
                {
                    throw new GitTfsException("Please run 'git tfs bootstrap' before git tfs push.");
                }
            }

            // Must have new commits to checkin
            if (_globals.Repository.GetCurrentTfsCommit(_currentBranch) != null)
            {
                throw new GitTfsException("error: nothing new to rcheckin.");
            }

            _globals.WarnOnGitVersion();

            if (_globals.Repository.IsBare)
            {
                throw new GitTfsException("error: you should specify the local branch to checkin for a bare repository.");
            }

            return(_writer.Write("HEAD", PerformRCheckin));
        }