Skip to content

Commit 805353a

Browse files
committed
Merge pull request git-tfs#727 from pmiossec/unshelve_on_current_commit
[WIP]Trying to apply shelveset on current commit when parent changeset is not...
2 parents e6165b8 + 7b5eeda commit 805353a

File tree

4 files changed

+18
-7
lines changed

4 files changed

+18
-7
lines changed

GitTfs/Commands/Unshelve.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public int Run(string shelvesetName, string destinationBranch)
5050
TfsBranch = _globals.RemoteId;
5151

5252
var remote = _globals.Repository.ReadTfsRemote(TfsBranch);
53-
remote.Unshelve(Owner, shelvesetName, destinationBranch, BuildErrorHandler());
53+
remote.Unshelve(Owner, shelvesetName, destinationBranch, BuildErrorHandler(), Force);
5454
_stdout.WriteLine("Created branch " + destinationBranch + " from shelveset \"" + shelvesetName + "\".");
5555
return GitTfsExitCodes.OK;
5656
}

GitTfs/Core/DerivedGitTfsRemote.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ public void QuickFetch(int changesetId)
225225
throw DerivedRemoteException;
226226
}
227227

228-
public void Unshelve(string a, string b, string c, Action<Exception> h)
228+
public void Unshelve(string a, string b, string c, Action<Exception> h, bool force)
229229
{
230230
throw DerivedRemoteException;
231231
}

GitTfs/Core/GitTfsRemote.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ private string BuildCommitMessage(string tfsCheckinComment, long changesetId)
736736
return builder.ToString();
737737
}
738738

739-
public void Unshelve(string shelvesetOwner, string shelvesetName, string destinationBranch, Action<Exception> ignorableErrorHandler)
739+
public void Unshelve(string shelvesetOwner, string shelvesetName, string destinationBranch, Action<Exception> ignorableErrorHandler, bool force)
740740
{
741741
var destinationRef = GitRepository.ShortToLocalName(destinationBranch);
742742
if(Repository.HasRef(destinationRef))
@@ -746,11 +746,22 @@ public void Unshelve(string shelvesetOwner, string shelvesetName, string destina
746746

747747
var parentId = shelvesetChangeset.BaseChangesetId;
748748
var ch = GetTfsChangesetById(parentId);
749+
string rootCommit;
749750
if (ch == null)
750-
throw new GitTfsException("ERROR: Parent changeset C" + parentId + " not found."
751-
+" Try fetching the latest changes from TFS");
751+
{
752+
if (!force)
753+
throw new GitTfsException("ERROR: Parent changeset C" + parentId + " not found."
754+
+ " Try fetching the latest changes from TFS");
755+
stdout.WriteLine("warning: Parent changeset C" + parentId + " not found."
756+
+ " Trying to apply the shelveset on the current commit...");
757+
rootCommit = Repository.GetCurrentCommit();
758+
}
759+
else
760+
{
761+
rootCommit = ch.GitCommit;
762+
}
752763

753-
var log = Apply(ch.GitCommit, shelvesetChangeset, ignorableErrorHandler);
764+
var log = Apply(rootCommit, shelvesetChangeset, ignorableErrorHandler);
754765
var commit = Commit(log);
755766
Repository.UpdateRef(destinationRef, commit, "Shelveset " + shelvesetName + " from " + shelvesetOwner);
756767
}

GitTfs/Core/IGitTfsRemote.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public interface IGitTfsRemote
5050
IFetchResult FetchWithMerge(long mergeChangesetId, bool stopOnFailMergeCommit = false, params string[] parentCommitsHashes);
5151
void QuickFetch();
5252
void QuickFetch(int changesetId);
53-
void Unshelve(string shelvesetOwner, string shelvesetName, string destinationBranch, Action<Exception> ignorableErrorHandler);
53+
void Unshelve(string shelvesetOwner, string shelvesetName, string destinationBranch, Action<Exception> ignorableErrorHandler, bool force);
5454
void Shelve(string shelvesetName, string treeish, TfsChangesetInfo parentChangeset, bool evaluateCheckinPolicies);
5555
bool HasShelveset(string shelvesetName);
5656
long CheckinTool(string head, TfsChangesetInfo parentChangeset);

0 commit comments

Comments
 (0)