Error: Couldn't find Git Commit or Branch with name
CHarnel opened this issue ยท 6 comments
Hi, I'm running a Github workflow and getting the following error:
Unhandled exception: System.InvalidOperationException: Couldn't find Git Commit or Branch with name develop in repository /home/runner/work/[...]/[...]/.git/
The command that runs is:
dotnet affected -f text traversal --from feature/nuget-publish-workflow --to develop
When I run this on my local working dir I'm not getting the error, but if I fetch the repo with the same command the GH action does, then I can reproduce the error locally (I'm fetching with fetch-depth: 0
).
Full stack trace:
/usr/share/dotnet/dotnet affected -f text traversal --from feature/nuget-publish-workflow --to develop
Unhandled exception: System.InvalidOperationException: Couldn't find Git Commit or Branch with name develop in repository /home/runner/work/[...]/[...]/.git/
at Affected.Cli.GitChangesProvider.GetCommitOrThrow(Repository repo, String name) in /home/runner/work/dotnet-affected/dotnet-affected/src/dotnet-affected/Infrastructure/GitChangesProvider.cs:line 137
at Affected.Cli.GitChangesProvider.GetCommitOrHead(Repository repository, String name) in /home/runner/work/dotnet-affected/dotnet-affected/src/dotnet-affected/Infrastructure/GitChangesProvider.cs:line [12](https://github.com/[...]/[...]/actions/runs/3215661710/jobs/5256915063#step:5:13)0
at Affected.Cli.GitChangesProvider.ParseRevisionRanges(Repository repository, String from, String to) in /home/runner/work/dotnet-affected/dotnet-affected/src/dotnet-affected/Infrastructure/GitChangesProvider.cs:line 67
at Affected.Cli.GitChangesProvider.GetChangesForRange[T](Repository repository, String from, String to) in /home/runner/work/dotnet-affected/dotnet-affected/src/dotnet-affected/Infrastructure/GitChangesProvider.cs:line 86
at Affected.Cli.GitChangesProvider.GetChangedFiles(String directory, String from, String to) in /home/runner/work/dotnet-affected/dotnet-affected/src/dotnet-affected/Infrastructure/GitChangesProvider.cs:line 15
at Affected.Cli.Commands.CommandExecutionContext.DetermineChangedFiles() in /home/runner/work/dotnet-affected/dotnet-affected/src/dotnet-affected/Commands/Context/CommandExecutionContext.cs:line 56
at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
at System.Lazy`1.CreateValue()
at System.Lazy`1.get_Value()
at Affected.Cli.Commands.CommandExecutionContext.DetermineChangedProjects() in /home/runner/work/dotnet-affected/dotnet-affected/src/dotnet-affected/Commands/Context/CommandExecutionContext.cs:line 66
at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
at System.Lazy`1.CreateValue()
at System.Lazy`1.get_Value()
at Affected.Cli.Commands.CommandExecutionContext.get_ChangedProjects() in /home/runner/work/dotnet-affected/dotnet-affected/src/dotnet-affected/Commands/Context/CommandExecutionContext.cs:line 47
at Affected.Cli.Commands.AffectedRootCommand.AffectedCommandHandler.InvokeAsync(InvocationContext ic) in /home/runner/work/dotnet-affected/dotnet-affected/src/dotnet-affected/Commands/AffectedRootCommand.cs:line 69
at System.CommandLine.NamingConventionBinder.CommandHandler.GetExitCodeAsync(Object returnValue, InvocationContext context)
at System.CommandLine.NamingConventionBinder.ModelBindingCommandHandler.InvokeAsync(InvocationContext context)
at System.CommandLine.Invocation.InvocationPipeline.<>c__DisplayClass4_0.<<BuildInvocationChain>b__0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass18_0.<<UseParseErrorReporting>b__0>d.MoveNext()
--- End of stack trace from previous location ---
at Affected.Cli.ErrorHandlingMiddleware.<>c__DisplayClass0_0.<<UseRenderingErrorHandler>b__0>d.MoveNext() in /home/runner/work/dotnet-affected/dotnet-affected/src/dotnet-affected/CommandLine/ErrorHandlingMiddleware.cs:line 26
--- End of stack trace from previous location ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass16_0.<<AddMiddleware>b__0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass16_0.<<AddMiddleware>b__0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass16_0.<<AddMiddleware>b__0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass13_0.<<UseHelp>b__0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass22_0.<<UseVersionOption>b__0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass20_0.<<UseTypoCorrections>b__0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseSuggestDirective>b__19_0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass17_0.<<UseParseDirective>b__0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<RegisterWithDotnetSuggest>b__6_0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass9_0.<<UseExceptionHandler>b__0>d.MoveNext()
Error: dotnet affected failed!
Error: Unhandled exception: System.InvalidOperationException: Couldn't find Git Commit or Branch with name develop in repository /home/runner/work/[...]/[...]/.git/
at Affected.Cli.GitChangesProvider.GetCommitOrThrow(Repository repo, String name) in /home/runner/work/dotnet-affected/dotnet-affected/src/dotnet-affected/Infrastructure/GitChangesProvider.cs:line [13](https://github.com/[...]/[...]/actions/runs/3215661710/jobs/5256915063#step:5:14)7
at Affected.Cli.GitChangesProvider.GetCommitOrHead(Repository repository, String name) in /home/runner/work/dotnet-affected/dotnet-affected/src/dotnet-affected/Infrastructure/GitChangesProvider.cs:line 120
at Affected.Cli.GitChangesProvider.ParseRevisionRanges(Repository repository, String from, String to) in /home/runner/work/dotnet-affected/dotnet-affected/src/dotnet-affected/Infrastructure/GitChangesProvider.cs:line 67
at Affected.Cli.GitChangesProvider.GetChangesForRange[T](Repository repository, String from, String to) in /home/runner/work/dotnet-affected/dotnet-affected/src/dotnet-affected/Infrastructure/GitChangesProvider.cs:line 86
at Affected.Cli.GitChangesProvider.GetChangedFiles(String directory, String from, String to) in /home/runner/work/dotnet-affected/dotnet-affected/src/dotnet-affected/Infrastructure/GitChangesProvider.cs:line [15](https://github.com/[...]/[...]/actions/runs/3215661710/jobs/5256915063#step:5:16)
at Affected.Cli.Commands.CommandExecutionContext.DetermineChangedFiles() in /home/runner/work/dotnet-affected/dotnet-affected/src/dotnet-affected/Commands/Context/CommandExecutionContext.cs:line 56
at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
at System.Lazy`1.CreateValue()
at System.Lazy`1.get_Value()
at Affected.Cli.Commands.CommandExecutionContext.DetermineChangedProjects() in /home/runner/work/dotnet-affected/dotnet-affected/src/dotnet-affected/Commands/Context/CommandExecutionContext.cs:line 66
at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
at System.Lazy`1.CreateValue()
at System.Lazy`1.get_Value()
at Affected.Cli.Commands.CommandExecutionContext.get_ChangedProjects() in /home/runner/work/dotnet-affected/dotnet-affected/src/dotnet-affected/Commands/Context/CommandExecutionContext.cs:line 47
at Affected.Cli.Commands.AffectedRootCommand.AffectedCommandHandler.InvokeAsync(InvocationContext ic) in /home/runner/work/dotnet-affected/dotnet-affected/src/dotnet-affected/Commands/AffectedRootCommand.cs:line 69
at System.CommandLine.NamingConventionBinder.CommandHandler.GetExitCodeAsync(Object returnValue, InvocationContext context)
at System.CommandLine.NamingConventionBinder.ModelBindingCommandHandler.InvokeAsync(InvocationContext context)
at System.CommandLine.Invocation.InvocationPipeline.<>c__DisplayClass4_0.<<BuildInvocationChain>b__0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass18_0.<<UseParseErrorReporting>b__0>d.MoveNext()
--- End of stack trace from previous location ---
at Affected.Cli.ErrorHandlingMiddleware.<>c__DisplayClass0_0.<<UseRenderingErrorHandler>b__0>d.MoveNext() in /home/runner/work/dotnet-affected/dotnet-affected/src/dotnet-affected/CommandLine/ErrorHandlingMiddleware.cs:line 26
--- End of stack trace from previous location ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass[16](https://github.com/[...]/[...]/actions/runs/3215661710/jobs/5256915063#step:5:17)_0.<<AddMiddleware>b__0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass16_0.<<AddMiddleware>b__0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass16_0.<<AddMiddleware>b__0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass13_0.<<UseHelp>b__0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass22_0.<<UseVersionOption>b__0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass20_0.<<UseTypoCorrections>b__0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseSuggestDirective>b__19_0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass[17](https://github.com/[...]/[...]/actions/runs/3215661710/jobs/5256915063#step:5:18)_0.<<UseParseDirective>b__0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<RegisterWithDotnetSuggest>b__6_0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass9_0.<<UseExceptionHandler>b__0>d.MoveNext()
Hi @CHarnel.
For Github Actions we have our own action to simplify stuff: https://github.com/leonardochaia/dotnet-affected-action#for-building-branches
However, I am not sure why develop
is not being found, perhaps its origin/develop
or similar?
We usually use commit sha's in CI instead of branch names. There's an example in our our workflow for release here:
dotnet-affected/.github/workflows/release.yml
Lines 49 to 58 in 002cc49
PD: Are you running 2.2.0?
Yes, I forgot to mention that I used your action for it (well I forked it ๐ )
Here's a piece of the workflow:
on: pull_request
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x
- name: Nuget disable source
run: |
dotnet nuget list source
dotnet nuget disable source github
- uses: Octoplay/dotnet-affected-action@v1.0.0
id: dotnet_affected
with:
from: ${{ github.head_ref }}
to: ${{ github.base_ref }}
...
It had an issue installing dotnet affected (Nuget didn't work) so I'm disabling and re-enabling the Nuget source.
Here's the tree of .git
dir in the GH runner:
.git
โโโ FETCH_HEAD
โโโ HEAD
โโโ branches
โโโ config
โโโ description
โโโ hooks
...
โโโ index
โโโ info
โ โโโ exclude
โโโ logs
โ โโโ HEAD
โ โโโ refs
โ โโโ remotes
โ โโโ origin
โ โ โโโ develop
โ โ โโโ feature
โ โ โ โโโ nuget-publish-workflow
โ โ โโโ master
โ โโโ pull
โ โโโ 2
โ โโโ merge
โโโ objects
โ โโโ info
โ โโโ pack
...
โโโ refs
โโโ heads
โโโ remotes
โ โโโ origin
โ โ โโโ develop
โ โ โโโ feature
โ โ โ โโโ nuget-publish-workflow
โ โ โโโ master
โ โโโ pull
โ โโโ 2
โ โโโ merge
โโโ tags
I used an example for PRs, that's why it's different... should I try the one on push
you mentioned?
Regarding version - yes, it's 2.2.0
/usr/share/dotnet/dotnet tool install -g dotnet-affected
You can invoke the tool using the following command: dotnet-affected
Tool 'dotnet-affected' (version '2.2.0') was successfully installed.
Hi @CHarnel
Still not sure why it wouldn't work.
I've had these issues before when using develop
instead of origin/develop
, but I'm not sure it is the case here.
Repository path has been an issue before, but in the case of the action it is set to the github path by code so it should work.
And fetch-depth as well, but again, looks good here. I'm a bit baffled.
should I try the one on push you mentioned?
Yeah, perhaps give it a go with a workflow copied from our samples? Just for a sanity check.
Thanks and keep me posted.
I will try to make a PR workflow run during the weekend.
PD: BTW, what kind of changes did you need to do on the github action? Feel free to throw a PR to that repo for review ๐
Regards,
Leo.
Hi @CHarnel , have you managed to fix this issue?
Regards,
Leo.
Hi @leonardochaia , no actually I went with another approach, less comprehensive but good enough for our case. I'm using tj-actions/changed-files to detect changes from git, and am triggering builds when a project or Common changed. Since we have a simple solution hierarchy right now, only independent projects and just one Common project, this works fine.
Also in the end I didn't need to make any changes to the actions repo ๐
Understood. I'll close this one in the meantime ๐