|
6 | 6 | using System.Reflection; |
7 | 7 | using System.Text; |
8 | 8 | using System.Text.Json; |
| 9 | +using System.Text.RegularExpressions; |
9 | 10 | using System.Threading; |
10 | 11 | using System.Threading.Tasks; |
11 | 12 |
|
@@ -431,21 +432,37 @@ private static bool TryLaunchAsRebaseMessageEditor(string[] args, out int exitCo |
431 | 432 | return true; |
432 | 433 |
|
433 | 434 | var gitDir = Path.GetDirectoryName(file)!; |
| 435 | + var origHeadFile = Path.Combine(gitDir, "rebase-merge", "orig-head"); |
| 436 | + var ontoFile = Path.Combine(gitDir, "rebase-merge", "onto"); |
| 437 | + var doneFile = Path.Combine(gitDir, "rebase-merge", "done"); |
434 | 438 | var jobsFile = Path.Combine(gitDir, "sourcegit_rebase_jobs.json"); |
435 | | - if (!File.Exists(jobsFile)) |
| 439 | + if (!File.Exists(ontoFile) || !File.Exists(origHeadFile) || !File.Exists(doneFile) || !File.Exists(jobsFile)) |
436 | 440 | return true; |
437 | 441 |
|
| 442 | + var origHead = File.ReadAllText(origHeadFile).Trim(); |
| 443 | + var onto = File.ReadAllText(ontoFile).Trim(); |
438 | 444 | var collection = JsonSerializer.Deserialize(File.ReadAllText(jobsFile), JsonCodeGen.Default.InteractiveRebaseJobCollection); |
439 | | - var doneFile = Path.Combine(gitDir, "rebase-merge", "done"); |
440 | | - if (!File.Exists(doneFile)) |
| 445 | + if (!collection.Onto.Equals(onto) || !collection.OrigHead.Equals(origHead)) |
441 | 446 | return true; |
442 | 447 |
|
443 | | - var done = File.ReadAllText(doneFile).Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries); |
444 | | - if (done.Length > collection.Jobs.Count) |
| 448 | + var done = File.ReadAllText(doneFile).Trim().Split([ '\r', '\n' ], StringSplitOptions.RemoveEmptyEntries); |
| 449 | + if (done.Length == 0) |
445 | 450 | return true; |
446 | 451 |
|
447 | | - var job = collection.Jobs[done.Length - 1]; |
448 | | - File.WriteAllText(file, job.Message); |
| 452 | + var current = done[^1].Trim(); |
| 453 | + var match = REG_REBASE_TODO().Match(current); |
| 454 | + if (!match.Success) |
| 455 | + return true; |
| 456 | + |
| 457 | + var sha = match.Groups[1].Value; |
| 458 | + foreach (var job in collection.Jobs) |
| 459 | + { |
| 460 | + if (job.SHA.StartsWith(sha)) |
| 461 | + { |
| 462 | + File.WriteAllText(file, job.Message); |
| 463 | + break; |
| 464 | + } |
| 465 | + } |
449 | 466 |
|
450 | 467 | return true; |
451 | 468 | } |
@@ -621,6 +638,9 @@ private string FixFontFamilyName(string input) |
621 | 638 | return trimmed.Count > 0 ? string.Join(',', trimmed) : string.Empty; |
622 | 639 | } |
623 | 640 |
|
| 641 | + [GeneratedRegex(@"^[a-z]+\s+([a-fA-F0-9]{4,40})(\s+.*)?$")] |
| 642 | + private static partial Regex REG_REBASE_TODO(); |
| 643 | + |
624 | 644 | private Models.IpcChannel _ipcChannel = null; |
625 | 645 | private ViewModels.Launcher _launcher = null; |
626 | 646 | private ResourceDictionary _activeLocale = null; |
|
0 commit comments