DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
View Events Video Library
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Integrating PostgreSQL Databases with ANF: Join this workshop to learn how to create a PostgreSQL server using Instaclustr’s managed service

Mobile Database Essentials: Assess data needs, storage requirements, and more when leveraging databases for cloud and edge applications.

Monitoring and Observability for LLMs: Datadog and Google Cloud discuss how to achieve optimal AI model performance.

Automated Testing: The latest on architecture, TDD, and the benefits of AI and low-code tools.

Related

  • Understanding Git
  • Unleashing the Power of React Hooks
  • The Art of the Bug Fix: Boosting Software Quality Through Effective Git Commits
  • Five Software Development Trends

Trending

  • Writing Reusable SQL Queries for Your Application With DbVisualizer Scripts
  • Memory Management in Java: An Introduction
  • Selecting the Right Automated Tests
  • Effective Tips for Debugging Complex Code in Java
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. Xcode Project Git Hooks

Xcode Project Git Hooks

Add some discipline in your source control procedure with git hooks.

Paul Zabelin user avatar by
Paul Zabelin
·
Dec. 28, 15 · Tutorial
Like (2)
Save
Tweet
Share
3.41K Views

Join the DZone community and get the full member experience.

Join For Free

what are git hooks?

git has ability to run special script along with standard git commands. there are many uses for git hooks from enforcing code style before commit to deploying on push, etc. see more on http://githooks.com .

git pre-commit hook

git pre-commit hook can help developer accidentally committing temporary changes to the source code made for debugging or testing.

example of git pre-commit hook

xcode projects that use specta or quick can take advantage of focus tests. focus tests allows to focus on a subset of a test suite. see how temporarily run a subset of focused examples in quick . focus tests speed up test driven development as we can focus on one failing spec at a time. the only problem with focus tests, they require source code modification that we might commit and limit our ability to run full suite of tests. here is a blog post on git pre-commit hooks and specta’s focused examples . unfortunately git hooks are not part of the repository. if we want to share git hooks on the project between multiple developers or even between multiple computers we have to install hooks on each clone.

git hook manager

one way to share git hooks across multiple clones is to use tool like overcommit . overcommit is “a fully configurable and extendable git hook manager.” it adds .overcommit.yml to configure hooks and allows adding custom hooks to .git-hooks/ folder in the project root folder.

overcommit and xcode

to make overcommit available for xcode inside ide we have to install overcommit gem at a system level:

rvm system
gem install overcommit

if you are not using rvm - ruby version manager you can skip first line and run this in shell:

gem install overcommit

xcode pre-commit hook for focused examples

here is the gist of a pre-commit hook that checks tests for temporary focused examples:

precommit:
  nofocusedexamples:
    include: ['*tests/*.swift', '*tests/*.m']
    enabled: true
    description: 'checking for temporary focused examples'
# .git-hooks/pre_commit/no_focused_examples.rb
# check bdd specs for temporary focused examples
module overcommit::hook::precommit
  class nofocusedexamples < base
    def run
      errors = []
      focused = ['describe', 'context', 'it']
      applicable_files.each do |file|
        file.open(file, 'r').each_with_index do |line, index|
          focused.each do |block_name|
            if line.index("f#{block_name}(")
              relative = pathname(file).relative_path_from(pathname(overcommit::utils.repo_root))
              errors << "#{relative}:#{index} has focused #{block_name} block `f#{block_name}`"
            end
          end
        end
      end

      return :fail, errors.join("\n") if errors.any?

      :pass
    end
  end
end

to install:

  1. update .overcommit.yml with the above lines
  2. save above script to .git-hooks/pre_commit/no_focused_examples.rb

now when we try to commit a focused test we get an error message similar to:

running pre-commit hooks
checking for temporary focused examples...........[nofocusedexamples] failed
unittests/somespec.swift:108 has focused it block `fit`

✗ one or more pre-commit hooks failed

same message will be shown by xcode when we try to commit from ide: xcode error screenshot

what hooks would you add for your xcode project?

Git Hook XCode

Published at DZone with permission of Paul Zabelin. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Understanding Git
  • Unleashing the Power of React Hooks
  • The Art of the Bug Fix: Boosting Software Quality Through Effective Git Commits
  • Five Software Development Trends

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: