-
Notifications
You must be signed in to change notification settings - Fork 0
[patch] Wire up Pull and stop advertising unimplemented Commit and Push #393
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+264
−4
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,177 @@ | ||
| // Copyright (c) 2023-2026 ktsu-dev contributors | ||
|
|
||
| namespace ktsu.ProjectDirector.Test; | ||
|
|
||
| using System; | ||
| using System.IO; | ||
|
|
||
| using ktsu.Semantics.Strings; | ||
| using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
|
||
| /// <summary> | ||
| /// Tests the rule that decides whether pulling a repository interrupts the user first. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// The Pull button used to do nothing at all. Now it either pulls or asks, and which one it does | ||
| /// is the only part of that path with a rule in it -- everything around it draws ImGui and needs a | ||
| /// live context and a display. <see cref="ProjectDirector.DecidePull"/> exists separately so this | ||
| /// rule can be driven against real throwaway repositories, the way <see cref="GitCliTests"/> does. | ||
| /// | ||
| /// Getting it wrong in either direction is user-visible: nagging on a clean tree makes the button | ||
| /// annoying, and staying silent on a dirty one is the case the confirmation exists for. | ||
| /// </remarks> | ||
| [TestClass] | ||
| public sealed class PullDecisionTests | ||
| { | ||
| private static FullyQualifiedLocalRepoPath CreateCommittedRepository() | ||
| { | ||
| string root = Path.Combine(Path.GetTempPath(), $"ktsu_pd_pull_{Guid.NewGuid():N}"); | ||
| _ = Directory.CreateDirectory(root); | ||
|
|
||
| Assert.IsTrue(GitCli.Run("init", root).Succeeded, "git init failed."); | ||
|
|
||
| // Scope identity to this throwaway repository so the test neither depends on nor disturbs | ||
| // whatever global configuration the machine happens to carry. | ||
| Assert.IsTrue(GitCli.RunIn(root, "config", "user.name", "ProjectDirector").Succeeded); | ||
| Assert.IsTrue(GitCli.RunIn(root, "config", "user.email", "ProjectDirector@ktsu.dev").Succeeded); | ||
|
|
||
| File.WriteAllText(Path.Combine(root, "tracked.txt"), "original\n"); | ||
|
github-code-quality[bot] marked this conversation as resolved.
Fixed
|
||
| Assert.IsTrue(GitCli.RunIn(root, "add", "--all").Succeeded, "git add failed."); | ||
|
|
||
| GitResult committed = GitCli.RunIn(root, "commit", "-m", "initial"); | ||
| Assert.IsTrue(committed.Succeeded, $"git commit failed: {committed.FailureText}"); | ||
|
|
||
| return root.As<FullyQualifiedLocalRepoPath>(); | ||
| } | ||
|
|
||
| private static void Cleanup(FullyQualifiedLocalRepoPath root) | ||
| { | ||
| try | ||
| { | ||
| Directory.Delete(root.WeakString, recursive: true); | ||
| } | ||
| catch (IOException) | ||
| { | ||
| // A leaked temp directory is not worth failing an otherwise passing test over. | ||
| } | ||
| catch (UnauthorizedAccessException) | ||
| { | ||
| // Same. | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// A clean tree must pull without interrupting the user. | ||
| /// </summary> | ||
| [TestMethod] | ||
| public void ACleanWorkingTreePullsWithoutAsking() | ||
| { | ||
| // Arrange | ||
| FullyQualifiedLocalRepoPath root = CreateCommittedRepository(); | ||
|
|
||
| try | ||
| { | ||
| // Act & Assert | ||
| Assert.AreEqual(PullDecision.PullNow, ProjectDirector.DecidePull(root)); | ||
| } | ||
| finally | ||
| { | ||
| Cleanup(root); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// A modification to a tracked file must trigger the confirmation. | ||
| /// </summary> | ||
| [TestMethod] | ||
| public void AModifiedTrackedFileAsksFirst() | ||
| { | ||
| // Arrange | ||
| FullyQualifiedLocalRepoPath root = CreateCommittedRepository(); | ||
|
|
||
| try | ||
| { | ||
| File.WriteAllText(Path.Combine(root.WeakString, "tracked.txt"), "modified\n"); | ||
|
github-code-quality[bot] marked this conversation as resolved.
Fixed
|
||
|
|
||
| // Act & Assert | ||
| Assert.AreEqual(PullDecision.Confirm, ProjectDirector.DecidePull(root)); | ||
| } | ||
| finally | ||
| { | ||
| Cleanup(root); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// An untracked file counts too: a pull can still clobber it, so the user should be asked. | ||
| /// </summary> | ||
| [TestMethod] | ||
| public void AnUntrackedFileAsksFirst() | ||
| { | ||
| // Arrange | ||
| FullyQualifiedLocalRepoPath root = CreateCommittedRepository(); | ||
|
|
||
| try | ||
| { | ||
| File.WriteAllText(Path.Combine(root.WeakString, "untracked.txt"), "new\n"); | ||
|
github-code-quality[bot] marked this conversation as resolved.
Fixed
|
||
|
|
||
| // Act & Assert | ||
| Assert.AreEqual(PullDecision.Confirm, ProjectDirector.DecidePull(root)); | ||
| } | ||
| finally | ||
| { | ||
| Cleanup(root); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Staging a change does not make it committed, so it must still ask. | ||
| /// </summary> | ||
| [TestMethod] | ||
| public void AStagedButUncommittedChangeAsksFirst() | ||
| { | ||
| // Arrange | ||
| FullyQualifiedLocalRepoPath root = CreateCommittedRepository(); | ||
|
|
||
| try | ||
| { | ||
| File.WriteAllText(Path.Combine(root.WeakString, "staged.txt"), "staged\n"); | ||
|
github-code-quality[bot] marked this conversation as resolved.
Fixed
|
||
| Assert.IsTrue(GitCli.RunIn(root, "add", "--all").Succeeded, "git add failed."); | ||
|
|
||
| // Act & Assert | ||
| Assert.AreEqual(PullDecision.Confirm, ProjectDirector.DecidePull(root)); | ||
| } | ||
| finally | ||
| { | ||
| Cleanup(root); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Committing the change makes the tree clean again, so the confirmation must stop firing -- | ||
| /// the decision has to track the tree's current state, not merely that it was ever dirty. | ||
| /// </summary> | ||
| [TestMethod] | ||
| public void CommittingTheChangeStopsTheConfirmation() | ||
| { | ||
| // Arrange | ||
| FullyQualifiedLocalRepoPath root = CreateCommittedRepository(); | ||
|
|
||
| try | ||
| { | ||
| File.WriteAllText(Path.Combine(root.WeakString, "tracked.txt"), "modified\n"); | ||
|
github-code-quality[bot] marked this conversation as resolved.
Fixed
|
||
| Assert.AreEqual(PullDecision.Confirm, ProjectDirector.DecidePull(root)); | ||
|
|
||
| // Act | ||
| Assert.IsTrue(GitCli.RunIn(root, "add", "--all").Succeeded); | ||
| Assert.IsTrue(GitCli.RunIn(root, "commit", "-m", "second").Succeeded); | ||
|
|
||
| // Assert | ||
| Assert.AreEqual(PullDecision.PullNow, ProjectDirector.DecidePull(root)); | ||
| } | ||
| finally | ||
| { | ||
| Cleanup(root); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| // Copyright (c) 2023-2026 ktsu-dev contributors | ||
|
|
||
| namespace ktsu.ProjectDirector; | ||
|
|
||
| /// <summary> | ||
| /// Whether a pull can proceed immediately or should ask the user first. | ||
| /// </summary> | ||
| internal enum PullDecision | ||
| { | ||
| /// <summary> | ||
| /// The working tree is clean, so the pull can run without interrupting the user. | ||
| /// </summary> | ||
| PullNow, | ||
|
|
||
| /// <summary> | ||
| /// The working tree has uncommitted changes, so the user should be asked before pulling. | ||
| /// </summary> | ||
| Confirm, | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.