1

I have a project where generating reproducible code CRCs is important, and if possible want make to throw an error if any files [in a git repository] have uncommitted modifications.

My first naive approach was: @git status -s 1>&2 Didn't work, no make errors generated.

Anyone know how to force a make error if an arbitrary command produces stdout text as a general case, or if a git repository has modified files as a specific case?

Mr Blue
  • 131
  • 5
  • 3
    Possible duplicate of [Checking for a dirty index or untracked files with Git](https://stackoverflow.com/questions/2657935/checking-for-a-dirty-index-or-untracked-files-with-git) – phd Nov 15 '19 at 16:56
  • https://stackoverflow.com/search?q=%5Bgit%5D+check+uncommitted+changes – phd Nov 15 '19 at 16:56
  • Very helpful! Not strictly a duplicate since I was looking for a general solution, but it did contain the answer I was looking for burred within the 2nd/3rd solution: use 'test -z' – Mr Blue Nov 15 '19 at 18:24

2 Answers2

2

Assuming that you don't want to run the command twice, you can use:

! command | grep .

Example:

full:
    ! echo hello | grep .

empty:
    ! true | grep .

Output:

$ make empty; echo "make returned $?"
! true | grep .
make returned 0
$ make full; echo "make returned $?"
! echo hello | grep .
hello
makefile:2: recipe for target 'full' failed
make: *** [full] Error 1
make returned 2
root
  • 5,528
  • 1
  • 7
  • 15
1

Solution was a lot simpler than expected:

@test -z "$$(commandX)"

Or in my case:

 @git status -s
 @test -z "$$(git status -s)"

(First git-status generates user friendly text to tell user what happened, second test to flag error for make)

Mr Blue
  • 131
  • 5