'/bin/bash not found when using pre-commit

I have been asked to run the following command within my git repo in order to install pre-commit:

pre-commit install --hook-type commit-msg

However when attempting to commit code using GitKraken i'm getting the following error, this is on Windows 10.

### version information

pre-commit version: 2.19.0
git --version: git version 2.35.1.windows.2
sys.version:
    3.9.1 (tags/v3.9.1:1e5d33e, Dec  7 2020, 17:08:21) [MSC v.1927 64 bit (AMD64)]
sys.executable: C:\python39\python.exe
os.name: nt
sys.platform: win32

### error information

An unexpected error has occurred: ExecutableNotFoundError: Executable `/bin/bash` not found

Traceback (most recent call last):
  File "C:\python39\lib\site-packages\pre_commit\error_handler.py", line 73, in error_handler
    yield
  File "C:\python39\lib\site-packages\pre_commit\main.py", line 361, in main
    return hook_impl(
  File "C:\python39\lib\site-packages\pre_commit\commands\hook_impl.py", line 232, in hook_impl
    retv, stdin = _run_legacy(hook_type, hook_dir, args)
  File "C:\python39\lib\site-packages\pre_commit\commands\hook_impl.py", line 42, in _run_legacy
    cmd = normalize_cmd((legacy_hook, *args))
  File "C:\python39\lib\site-packages\pre_commit\parse_shebang.py", line 82, in normalize_cmd
    exe = normexe(cmd[0])
  File "C:\python39\lib\site-packages\pre_commit\parse_shebang.py", line 61, in normexe
    _error('not found')
  File "C:\python39\lib\site-packages\pre_commit\parse_shebang.py", line 51, in _error
    raise ExecutableNotFoundError(f'Executable `{orig}` {msg}')
pre_commit.parse_shebang.ExecutableNotFoundError: Executable `/bin/bash` not found
// .pre-commit-config.yaml

ci:
  skip:
    - actionlint

repos:
  - repo: https://github.com/alessandrojcm/commitlint-pre-commit-hook
    rev: v8.0.0
    hooks:
      - id: commitlint
        stages: [commit-msg]
        additional_dependencies: ['commitlint-plugin-jira-rules', 'commitlint-config-jira']
  # - repo: https://github.com/editorconfig-checker/editorconfig-checker.python
  #   rev: 2.4.0
  #   hooks:
  #     - id: editorconfig-checker
  - repo: https://github.com/rhysd/actionlint
    rev: v1.6.12
    hooks:
      - id: actionlint
  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v4.2.0
    hooks:
      - id: check-merge-conflict

How can I solve this, attempted to do a Google Search but to not success.



Solution 1:[1]

Found the solution, just had to delete .git/hooks/pre-commit.legacy and then reinstall, I also deleted .git/hooks/pre-commit just to be sure before installing again.

Solution 2:[2]

You are doing nothing or not calling the function explicitly for foto to be defined. Also, return foto would only make sense if we assign this function call to a variable.

I would make the following changes.

I would use HttpClient instead of fetch, Angular provides this HttpClient for us to make unit testing easier.

import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { environment } from '../../../environments/environment';

@Component({
 selector: 'app-root',
 templateUrl: './entrega.component.html',
 styleUrls: ['./entrega.component.css']
})
export class EntregaComponent implements OnInit {
 idEntrega:any='';
 foto:any='';
 urlCasillero='';
 constructor(private route: ActivatedRoute, private http: HttpClient) { }

 ngOnInit() {
   this.urlCasillero=environment.URLCASILLERO;
   this.idEntrega = this.route.snapshot.params.id;
 }


 peticionFoto(data:string): void {
   this.httpClient.get(this.urlCasillero+this.idEntrega).pipe(
     // might not be needed, this map
     map(res => res.text()),
   ).subscribe(result => {
     console.log(result); // make sure the result is what you would like
     this.foto = result;
   });
 }
}

And for the test:

import { EntregaComponent } from './entrega.component';

describe('EntregaComponent', () => {
  let component: EntregaComponent;
  let fixture: ComponentFixture<EntregaComponent>;
  let httpTestingController: HttpTestingController;


  beforeEach(async () => {
    await TestBed.configureTestingModule({
      declarations: [ EntregaComponent ],
      // !! Add HttpClientTestingModule !!
      imports: [ RouterTestingModule, HttpClientTestingModule  ],
    })
    .compileComponents();
  });

  beforeEach(() => {
    // get an instance of http testing controller
    httpTestingController = TestBed.inject(HttpTestingController);
    fixture = TestBed.createComponent(EntregaComponent);
    component = fixture.componentInstance;
    fixture.detectChanges();
  });

  it('should create', () => {
    expect(component).toBeTruthy();
  });


  it('debe obtener una foto', fakeAsync(() => {
   // call the function
   component.peticionFoto('abc');
   // expect a get request   
   const request = httpTestingController.expectOne(request => request.method === 'GET');
   // flush this response
   request.flush({ text: () => 'abc' });
   // wait for subscriptions to complete   
   tick();
   expect(component.foto).toBe('abc');
  }));
 
});

I did everything without an IDE so there might be mistakes. That being said, I have found this resource https://testing-angular.com/ very good for learning unit testing.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Martyn Ball
Solution 2 AliF50