Skip to content

Commit 75b4a4b

Browse files
committed
enhance: record more git command logs
Signed-off-by: leo <[email protected]>
1 parent d254b55 commit 75b4a4b

File tree

9 files changed

+107
-50
lines changed

9 files changed

+107
-50
lines changed

src/Commands/LFS.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ public bool IsEnabled()
3636
return content.Contains("git lfs pre-push");
3737
}
3838

39-
public bool Install()
39+
public bool Install(Models.ICommandLog log)
4040
{
41-
return new SubCmd(_repo, "lfs install --local", null).Exec();
41+
return new SubCmd(_repo, "lfs install --local", log).Exec();
4242
}
4343

4444
public bool Track(string pattern, bool isFilenameMode, Models.ICommandLog log)
@@ -93,21 +93,21 @@ public void Prune(Models.ICommandLog log)
9393
return locks;
9494
}
9595

96-
public bool Lock(string remote, string file)
96+
public bool Lock(string remote, string file, Models.ICommandLog log)
9797
{
98-
return new SubCmd(_repo, $"lfs lock --remote={remote} \"{file}\"", null).Exec();
98+
return new SubCmd(_repo, $"lfs lock --remote={remote} \"{file}\"", log).Exec();
9999
}
100100

101-
public bool Unlock(string remote, string file, bool force)
101+
public bool Unlock(string remote, string file, bool force, Models.ICommandLog log)
102102
{
103103
var opt = force ? "-f" : "";
104-
return new SubCmd(_repo, $"lfs unlock --remote={remote} {opt} \"{file}\"", null).Exec();
104+
return new SubCmd(_repo, $"lfs unlock --remote={remote} {opt} \"{file}\"", log).Exec();
105105
}
106106

107-
public bool Unlock(string remote, long id, bool force)
107+
public bool Unlock(string remote, long id, bool force, Models.ICommandLog log)
108108
{
109109
var opt = force ? "-f" : "";
110-
return new SubCmd(_repo, $"lfs unlock --remote={remote} {opt} --id={id}", null).Exec();
110+
return new SubCmd(_repo, $"lfs unlock --remote={remote} {opt} --id={id}", log).Exec();
111111
}
112112

113113
private readonly string _repo;

src/ViewModels/AssumeUnchangedManager.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ public class AssumeUnchangedManager
99
{
1010
public AvaloniaList<string> Files { get; private set; }
1111

12-
public AssumeUnchangedManager(string repo)
12+
public AssumeUnchangedManager(Repository repo)
1313
{
1414
_repo = repo;
1515
Files = new AvaloniaList<string>();
1616

1717
Task.Run(() =>
1818
{
19-
var collect = new Commands.QueryAssumeUnchangedFiles(_repo).Result();
19+
var collect = new Commands.QueryAssumeUnchangedFiles(_repo.FullPath).Result();
2020
Dispatcher.UIThread.Invoke(() => Files.AddRange(collect));
2121
});
2222
}
@@ -25,11 +25,13 @@ public void Remove(string file)
2525
{
2626
if (!string.IsNullOrEmpty(file))
2727
{
28-
new Commands.AssumeUnchanged(_repo, file, false).Exec();
28+
var log = _repo.CreateLog("Remove Assue Unchanged File");
29+
new Commands.AssumeUnchanged(_repo.FullPath, file, false).Use(log).Exec();
30+
log.Complete();
2931
Files.Remove(file);
3032
}
3133
}
3234

33-
private readonly string _repo;
35+
private readonly Repository _repo;
3436
}
3537
}

src/ViewModels/CommitDetail.cs

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,9 @@ public ContextMenu CreateChangeContextMenu(Models.Change change)
391391
resetToThisRevision.Icon = App.CreateMenuIcon("Icons.File.Checkout");
392392
resetToThisRevision.Click += (_, ev) =>
393393
{
394-
new Commands.Checkout(_repo.FullPath).FileWithRevision(change.Path, $"{_commit.SHA}");
394+
var log = _repo.CreateLog($"Reset File to '{_commit.SHA}'");
395+
new Commands.Checkout(_repo.FullPath).Use(log).FileWithRevision(change.Path, $"{_commit.SHA}");
396+
log.Complete();
395397
ev.Handled = true;
396398
};
397399

@@ -401,10 +403,12 @@ public ContextMenu CreateChangeContextMenu(Models.Change change)
401403
resetToFirstParent.IsEnabled = _commit.Parents.Count > 0;
402404
resetToFirstParent.Click += (_, ev) =>
403405
{
406+
var log = _repo.CreateLog($"Reset File to '{_commit.SHA}~1'");
404407
if (change.Index == Models.ChangeState.Renamed)
405-
new Commands.Checkout(_repo.FullPath).FileWithRevision(change.OriginalPath, $"{_commit.SHA}~1");
408+
new Commands.Checkout(_repo.FullPath).Use(log).FileWithRevision(change.OriginalPath, $"{_commit.SHA}~1");
406409

407-
new Commands.Checkout(_repo.FullPath).FileWithRevision(change.Path, $"{_commit.SHA}~1");
410+
new Commands.Checkout(_repo.FullPath).Use(log).FileWithRevision(change.Path, $"{_commit.SHA}~1");
411+
log.Complete();
408412
ev.Handled = true;
409413
};
410414

@@ -530,7 +534,9 @@ public ContextMenu CreateRevisionFileContextMenu(Models.Object file)
530534
resetToThisRevision.IsEnabled = File.Exists(fullPath);
531535
resetToThisRevision.Click += (_, ev) =>
532536
{
533-
new Commands.Checkout(_repo.FullPath).FileWithRevision(file.Path, $"{_commit.SHA}");
537+
var log = _repo.CreateLog($"Reset File to '{_commit.SHA}'");
538+
new Commands.Checkout(_repo.FullPath).Use(log).FileWithRevision(file.Path, $"{_commit.SHA}");
539+
log.Complete();
534540
ev.Handled = true;
535541
};
536542

@@ -542,7 +548,9 @@ public ContextMenu CreateRevisionFileContextMenu(Models.Object file)
542548
resetToFirstParent.IsEnabled = _commit.Parents.Count > 0 && fileIndex != Models.ChangeState.Renamed;
543549
resetToFirstParent.Click += (_, ev) =>
544550
{
545-
new Commands.Checkout(_repo.FullPath).FileWithRevision(file.Path, $"{_commit.SHA}~1");
551+
var log = _repo.CreateLog($"Reset File to '{_commit.SHA}~1'");
552+
new Commands.Checkout(_repo.FullPath).Use(log).FileWithRevision(file.Path, $"{_commit.SHA}~1");
553+
log.Complete();
546554
ev.Handled = true;
547555
};
548556

@@ -737,10 +745,12 @@ private void TryToAddContextMenuItemsForGitLFS(ContextMenu menu, string path)
737745
{
738746
lfsLock.Click += async (_, e) =>
739747
{
740-
var succ = await Task.Run(() => new Commands.LFS(_repo.FullPath).Lock(_repo.Remotes[0].Name, path));
748+
var log = _repo.CreateLog("Lock LFS file");
749+
var succ = await Task.Run(() => new Commands.LFS(_repo.FullPath).Lock(_repo.Remotes[0].Name, path, log));
741750
if (succ)
742751
App.SendNotification(_repo.FullPath, $"Lock file \"{path}\" successfully!");
743752

753+
log.Complete();
744754
e.Handled = true;
745755
};
746756
}
@@ -753,10 +763,12 @@ private void TryToAddContextMenuItemsForGitLFS(ContextMenu menu, string path)
753763
lockRemote.Header = remoteName;
754764
lockRemote.Click += async (_, e) =>
755765
{
756-
var succ = await Task.Run(() => new Commands.LFS(_repo.FullPath).Lock(remoteName, path));
766+
var log = _repo.CreateLog("Lock LFS file");
767+
var succ = await Task.Run(() => new Commands.LFS(_repo.FullPath).Lock(remoteName, path, log));
757768
if (succ)
758769
App.SendNotification(_repo.FullPath, $"Lock file \"{path}\" successfully!");
759770

771+
log.Complete();
760772
e.Handled = true;
761773
};
762774
lfsLock.Items.Add(lockRemote);
@@ -772,10 +784,12 @@ private void TryToAddContextMenuItemsForGitLFS(ContextMenu menu, string path)
772784
{
773785
lfsUnlock.Click += async (_, e) =>
774786
{
775-
var succ = await Task.Run(() => new Commands.LFS(_repo.FullPath).Unlock(_repo.Remotes[0].Name, path, false));
787+
var log = _repo.CreateLog("Unlock LFS file");
788+
var succ = await Task.Run(() => new Commands.LFS(_repo.FullPath).Unlock(_repo.Remotes[0].Name, path, false, log));
776789
if (succ)
777790
App.SendNotification(_repo.FullPath, $"Unlock file \"{path}\" successfully!");
778791

792+
log.Complete();
779793
e.Handled = true;
780794
};
781795
}
@@ -788,10 +802,12 @@ private void TryToAddContextMenuItemsForGitLFS(ContextMenu menu, string path)
788802
unlockRemote.Header = remoteName;
789803
unlockRemote.Click += async (_, e) =>
790804
{
791-
var succ = await Task.Run(() => new Commands.LFS(_repo.FullPath).Unlock(remoteName, path, false));
805+
var log = _repo.CreateLog("Unlock LFS file");
806+
var succ = await Task.Run(() => new Commands.LFS(_repo.FullPath).Unlock(remoteName, path, false, log));
792807
if (succ)
793808
App.SendNotification(_repo.FullPath, $"Unlock file \"{path}\" successfully!");
794809

810+
log.Complete();
795811
e.Handled = true;
796812
};
797813
lfsUnlock.Items.Add(unlockRemote);

src/ViewModels/Histories.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -297,12 +297,14 @@ public ContextMenu MakeContextMenu(ListBox list)
297297
return;
298298

299299
var options = new FolderPickerOpenOptions() { AllowMultiple = false };
300+
var log = null as CommandLog;
300301
try
301302
{
302303
var picker = await storageProvider.OpenFolderPickerAsync(options);
303304
if (picker.Count == 1)
304305
{
305-
var log = _repo.CreateLog("Save as Patch");
306+
log = _repo.CreateLog("Save as Patch");
307+
306308
var succ = false;
307309
for (var i = 0; i < selected.Count; i++)
308310
{
@@ -314,15 +316,14 @@ public ContextMenu MakeContextMenu(ListBox list)
314316

315317
if (succ)
316318
App.SendNotification(_repo.FullPath, App.Text("SaveAsPatchSuccess"));
317-
318-
log.Complete();
319319
}
320320
}
321321
catch (Exception exception)
322322
{
323323
App.RaiseException(_repo.FullPath, $"Failed to save as patch: {exception.Message}");
324324
}
325325

326+
log?.Complete();
326327
e.Handled = true;
327328
};
328329
multipleMenu.Items.Add(saveToPatchMultiple);
@@ -658,13 +659,16 @@ public ContextMenu MakeContextMenu(ListBox list)
658659
return;
659660

660661
var options = new FolderPickerOpenOptions() { AllowMultiple = false };
662+
var log = null as CommandLog;
661663
try
662664
{
663665
var selected = await storageProvider.OpenFolderPickerAsync(options);
664666
if (selected.Count == 1)
665667
{
668+
log = _repo.CreateLog("Save as Patch");
669+
666670
var saveTo = GetPatchFileName(selected[0].Path.LocalPath, commit);
667-
var succ = new Commands.FormatPatch(_repo.FullPath, commit.SHA, saveTo).Exec();
671+
var succ = new Commands.FormatPatch(_repo.FullPath, commit.SHA, saveTo).Use(log).Exec();
668672
if (succ)
669673
App.SendNotification(_repo.FullPath, App.Text("SaveAsPatchSuccess"));
670674
}
@@ -674,6 +678,7 @@ public ContextMenu MakeContextMenu(ListBox list)
674678
App.RaiseException(_repo.FullPath, $"Failed to save as patch: {exception.Message}");
675679
}
676680

681+
log?.Complete();
677682
e.Handled = true;
678683
};
679684
menu.Items.Add(saveToPatch);

src/ViewModels/InteractiveRebase.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,14 @@ public Task<bool> Start()
174174
}
175175
File.WriteAllText(saveFile, JsonSerializer.Serialize(collection, JsonCodeGen.Default.InteractiveRebaseJobCollection));
176176

177+
var log = _repo.CreateLog("Interactive Rebase");
177178
return Task.Run(() =>
178179
{
179-
var succ = new Commands.InteractiveRebase(_repo.FullPath, On.SHA).Exec();
180+
var succ = new Commands.InteractiveRebase(_repo.FullPath, On.SHA).Use(log).Exec();
180181
if (succ)
181182
File.Delete(saveFile);
182183

184+
log.Complete();
183185
Dispatcher.UIThread.Invoke(() => _repo.SetWatcherEnabled(true));
184186
return succ;
185187
});

src/ViewModels/LFSLocks.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,17 @@ public List<Models.LFSLock> VisibleLocks
3737
private set => SetProperty(ref _visibleLocks, value);
3838
}
3939

40-
public LFSLocks(string repo, string remote)
40+
public LFSLocks(Repository repo, string remote)
4141
{
4242
_repo = repo;
4343
_remote = remote;
44-
_userName = new Commands.Config(repo).Get("user.name");
44+
_userName = new Commands.Config(repo.FullPath).Get("user.name");
4545

4646
HasValidUserName = !string.IsNullOrEmpty(_userName);
4747

4848
Task.Run(() =>
4949
{
50-
_cachedLocks = new Commands.LFS(_repo).Locks(_remote);
50+
_cachedLocks = new Commands.LFS(_repo.FullPath).Locks(_remote);
5151
Dispatcher.UIThread.Invoke(() =>
5252
{
5353
UpdateVisibleLocks();
@@ -62,9 +62,13 @@ public void Unlock(Models.LFSLock lfsLock, bool force)
6262
return;
6363

6464
IsLoading = true;
65+
66+
var log = _repo.CreateLog("Unlock LFS File");
6567
Task.Run(() =>
6668
{
67-
var succ = new Commands.LFS(_repo).Unlock(_remote, lfsLock.ID, force);
69+
var succ = new Commands.LFS(_repo.FullPath).Unlock(_remote, lfsLock.ID, force, log);
70+
log.Complete();
71+
6872
Dispatcher.UIThread.Invoke(() =>
6973
{
7074
if (succ)
@@ -99,7 +103,7 @@ private void UpdateVisibleLocks()
99103
VisibleLocks = visible;
100104
}
101105

102-
private string _repo;
106+
private Repository _repo;
103107
private string _remote;
104108
private bool _isLoading = true;
105109
private List<Models.LFSLock> _cachedLocks = [];

src/ViewModels/Repository.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1405,7 +1405,7 @@ public ContextMenu CreateContextMenuForGitLFS()
14051405
{
14061406
locks.Click += (_, e) =>
14071407
{
1408-
var dialog = new Views.LFSLocks() { DataContext = new LFSLocks(_fullpath, _remotes[0].Name) };
1408+
var dialog = new Views.LFSLocks() { DataContext = new LFSLocks(this, _remotes[0].Name) };
14091409
App.OpenDialog(dialog);
14101410
e.Handled = true;
14111411
};
@@ -1419,7 +1419,7 @@ public ContextMenu CreateContextMenuForGitLFS()
14191419
lockRemote.Header = remoteName;
14201420
lockRemote.Click += (_, e) =>
14211421
{
1422-
var dialog = new Views.LFSLocks() { DataContext = new LFSLocks(_fullpath, remoteName) };
1422+
var dialog = new Views.LFSLocks() { DataContext = new LFSLocks(this, remoteName) };
14231423
App.OpenDialog(dialog);
14241424
e.Handled = true;
14251425
};
@@ -1437,10 +1437,12 @@ public ContextMenu CreateContextMenuForGitLFS()
14371437
install.Icon = App.CreateMenuIcon("Icons.Init");
14381438
install.Click += (_, e) =>
14391439
{
1440-
var succ = new Commands.LFS(_fullpath).Install();
1440+
var log = CreateLog("Install LFS");
1441+
var succ = new Commands.LFS(_fullpath).Install(log);
14411442
if (succ)
14421443
App.SendNotification(_fullpath, $"LFS enabled successfully!");
14431444

1445+
log.Complete();
14441446
e.Handled = true;
14451447
};
14461448
menu.Items.Add(install);
@@ -2249,9 +2251,11 @@ public ContextMenu CreateContextMenuForWorktree(Models.Worktree worktree)
22492251
unlock.Click += (_, ev) =>
22502252
{
22512253
SetWatcherEnabled(false);
2252-
var succ = new Commands.Worktree(_fullpath).Unlock(worktree.FullPath);
2254+
var log = CreateLog("Unlock Worktree");
2255+
var succ = new Commands.Worktree(_fullpath).Use(log).Unlock(worktree.FullPath);
22532256
if (succ)
22542257
worktree.IsLocked = false;
2258+
log.Complete();
22552259
SetWatcherEnabled(true);
22562260
ev.Handled = true;
22572261
};
@@ -2265,9 +2269,11 @@ public ContextMenu CreateContextMenuForWorktree(Models.Worktree worktree)
22652269
loc.Click += (_, ev) =>
22662270
{
22672271
SetWatcherEnabled(false);
2268-
var succ = new Commands.Worktree(_fullpath).Lock(worktree.FullPath);
2272+
var log = CreateLog("Lock Worktree");
2273+
var succ = new Commands.Worktree(_fullpath).Use(log).Lock(worktree.FullPath);
22692274
if (succ)
22702275
worktree.IsLocked = true;
2276+
log.Complete();
22712277
SetWatcherEnabled(true);
22722278
ev.Handled = true;
22732279
};

src/ViewModels/StashesPage.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,9 @@ public ContextMenu MakeContextMenuForChange(Models.Change change)
238238
resetToThisRevision.Icon = App.CreateMenuIcon("Icons.File.Checkout");
239239
resetToThisRevision.Click += (_, ev) =>
240240
{
241-
new Commands.Checkout(_repo.FullPath).FileWithRevision(change.Path, $"{_selectedStash.SHA}");
241+
var log = _repo.CreateLog($"Reset File to '{_selectedStash.SHA}'");
242+
new Commands.Checkout(_repo.FullPath).Use(log).FileWithRevision(change.Path, $"{_selectedStash.SHA}");
243+
log.Complete();
242244
ev.Handled = true;
243245
};
244246

0 commit comments

Comments
 (0)