1

If often find myself writing out helpful messages in my code when developing locally. See this code snippet as a simple example:

# Public API
namespace :api do
  namespace :v1 do
    # REMOVE THE FIRST LINE WHEN DONE TESTING
    get :delivery_report, to: 'delivery_report#index'
    post :delivery_report, to: 'delivery_report#index'
  end
end

The point here is that when I am done and I feel like I can finally commit my work I need to remember that I have to remove the line get :delivery_report, to: 'delivery_report#index'

Is it somehow possible to tell git that before accepting a commit or maybe before staging it, it should warn me about a line in my code that has some content? In this case that would be my comment or any other pre-defined line.

karlingen
  • 13,800
  • 5
  • 43
  • 74

1 Answers1

0

Git supports a "pre-commit hook", in which you can test what the user has proposed committing, and force the commit to fail if some condition(s) apply.

See git pre-commit hook code formatting with partial commit? and How do I properly git stash/pop in pre-commit hooks to get a clean working tree for tests?

Community
  • 1
  • 1
torek
  • 448,244
  • 59
  • 642
  • 775