Commits

Jason Harris  committed ee2c2e6

- Allow amending from the non-tip version just as long as the version being amended is the
tip of it's branch.

  • Participants
  • Parent commits c6d82c1

Comments (0)

Files changed (2)

File Classes/Sheets/CommitSheet/CommitSheetController.h

 	NSArray*		logCommentsTableSourceData;		// This array is computed whenever we put up the
 													// sheet, but the tableview in the sheet uses this class as a data
 													// source so we have to have this as a class member.
+	BOOL			amendIsPossible_;				// Is the amend operation even possible. This is determined at sheet opening time.
 	
 	// Advanaced commit options
 	NSString*		committer_;						// The value of the committer option

File Classes/Sheets/CommitSheet/CommitSheetController.m

 // MARK:  Sheet opening
 // -----------------------------------------------------------------------------------------------------------------------------------------
 
+- (void) computeAmendIsPossible
+{
+	// Determine if we can do amends at all
+	amendIsPossible_ = NO;
+	if ([myDocument inMergeState])
+		return;
+
+	NSString* rootPath = [myDocument absolutePathOfRepositoryRoot];
+	NSString* parentRevision = numberAsString([myDocument getHGParent1Revision]);
+	NSString* revPattern = fstr(@"descendants(rev(%@))", parentRevision);
+	NSMutableArray* argsLog = [NSMutableArray arrayWithObjects:@"log", @"--limit", @"10", @"--template", @"{rev},", @"--rev", revPattern, nil];
+	ExecutionResult* hgLogResults = [TaskExecutions executeMercurialWithArgs:argsLog  fromRoot:rootPath  logging:eLoggingNone];
+	if ([hgLogResults hasErrors])
+		return;
+	
+	NSArray* descdentRevs = [hgLogResults.outStr componentsSeparatedByString:@","];
+	NSInteger count = [descdentRevs count];
+	if (IsEmpty([descdentRevs lastObject]))
+		count--;
+	if (count <= 1)
+		amendIsPossible_ = YES;
+}
 
 
 - (void) openCommitSheetWithPaths:(NSArray*)paths
 	[previousCommitMessagesTableView reloadData];
 	cachedCommitMessageForAmend_ = [[logCommentsTableSourceData objectAtIndex:0] copy];
 
+	[self computeAmendIsPossible];
+	
 	[self validateButtons:self];
 }
 
 - (IBAction) validateButtons:(id)sender
 {
 	BOOL pathsAreSelected = [commitFilesViewer nodesAreSelected];
-	BOOL canAllowAmend = AllowHistoryEditingOfRepositoryFromDefaults() && [myDocument isCurrentRevisionTip] && ![myDocument inMergeState];
+	BOOL canAllowAmend = AllowHistoryEditingOfRepositoryFromDefaults() && amendIsPossible_ && ![myDocument inMergeState];
 	BOOL okToCommit = IsNotEmpty([commitMessageTextView string]) && [self anyHunksToCommit];
 	NSString* diffButtonMessage = pathsAreSelected ? @"Diff Selected" : @"Diff All";