Skip to content
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

Improved error message in prepare-release when uncommited changes are present #885

Merged
merged 2 commits into from
Jan 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions doc/nbgv-cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ It will also add/modify your `Directory.Build.props` file in the root of your re
If scripting for running in a CI build where global impact from installing a tool is undesirable, you can localize the tool installation:

```ps1
dotnet tool install --tool-path . nbgv
dotnet tool install --tool-path my/path nbgv
```
> Ensure your custom path is outside of your git repository, as the `nbgv` tool doesn't support uncommited changes

At this point you can launch the tool using `./nbgv` in your build script.

Expand All @@ -41,7 +42,7 @@ The `prepare-release` command automates the task of branching off the main devel
The `prepare-release` command supports this working model by taking care of
creating the release branch and updating `version.json` on both branches.

To prepare a release, run:
To prepare a release, first ensure there is no uncommited changes in your repository then run:

```ps1
nbgv prepare-release
Expand Down
7 changes: 5 additions & 2 deletions src/NerdBank.GitVersioning/ReleaseManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,12 @@ private LibGit2Context GetRepository(string projectDirectory)
RepositoryStatus status = libgit2context.Repository.RetrieveStatus();
if (status.IsDirty)
{
var changedFiles = status.OfType<StatusEntry>().ToList();
// This filter copies the internal logic used by LibGit2 behind RepositoryStatus.IsDirty to tell if
// a repo is dirty or not
// Could be simplified if https://github.com/libgit2/libgit2sharp/pull/2004 is ever merged
var changedFiles = status.Where(file => file.State != FileStatus.Ignored && file.State != FileStatus.Unaltered).ToList();
string changesFilesFormatted = string.Join(Environment.NewLine, changedFiles.Select(t => $"- {t.FilePath} changed with {nameof(FileStatus)} {t.State}"));
this.stderr.WriteLine($"Uncommitted changes ({changedFiles.Count}) in directory '{projectDirectory}':");
this.stderr.WriteLine($"No uncommitted changes are allowed, but {changedFiles.Count} are present in directory '{projectDirectory}':");
this.stderr.WriteLine(changesFilesFormatted);
throw new ReleasePreparationException(ReleasePreparationError.UncommittedChanges);
}
Expand Down