Skip to content

Commit

Permalink
Merge pull request #885 from clyvari/feat/883-improve-error-messages
Browse files Browse the repository at this point in the history
Improved error message in prepare-release when uncommited changes are present
  • Loading branch information
AArnott committed Jan 11, 2023
2 parents 274a42e + 9786b3c commit f1605ff
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
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

0 comments on commit f1605ff

Please sign in to comment.