From 0e1e21fc063821bc2cb940638f97f18885d4dde7 Mon Sep 17 00:00:00 2001 From: Maciej Bielecki Date: Fri, 6 May 2022 09:46:09 +0000 Subject: [PATCH 1/3] Make it work in a subdirectory --- bin/git_rails | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/bin/git_rails b/bin/git_rails index e1744ae..e08907c 100755 --- a/bin/git_rails +++ b/bin/git_rails @@ -78,13 +78,11 @@ if [ -z "$new_ref" ]; then new_ref=`git rev-parse HEAD` fi -files_changed=`git diff $old_ref $new_ref --name-status` - # CHECK IF WE NEED TO DO A BUNDLE -bundle_changed=`echo "$files_changed" | grep $'M\tGemfile.lock'` +bundle_changed=`git diff $old_ref $new_ref -- Gemfile.lock` # CHECK IF WE NEED TO SPIN SOME YARN -yarn_changed=`echo "$files_changed" | grep $'M\tyarn.lock'` +yarn_changed=`git diff $old_ref $new_ref -- yarn.lock` migrations=`git diff --name-status $old_ref $new_ref -- db/migrate | grep '^[AD]'` From e6a8012aca9f3b06695092f23e93f83c97fb4abc Mon Sep 17 00:00:00 2001 From: Maciej Bielecki Date: Fri, 6 May 2022 09:49:44 +0000 Subject: [PATCH 2/3] Add documentation --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index b322b58..f01c9a2 100644 --- a/README.md +++ b/README.md @@ -61,3 +61,15 @@ The following command line options are supported: You shouldn't have to think about the hooks once they are installed. Just pull, checkout, and rebase as normal and they should work fine. If you find that `git_rails` hasn't fired when it should follow the command instructions to run it manually. Also, the hooks are optional, you can use `git_rails` without them! + +#### Monorepo usage + +If the Rails project is not in the root of the Git repository, execute `git_rails` and hooks in the Rails directory. + +For example, to make the post-checkout hook run in a particular subdirectory, create the following `.git/hooks/post-checkout` file: + +```sh +#!/bin/sh +cd path/to/rails/project +exec /path/to/git_rails/hooks/post-checkout "$@" +``` From 98f9a9950e000fd8da1b6fa739e40e46646d0c0f Mon Sep 17 00:00:00 2001 From: Maciej Bielecki Date: Fri, 6 May 2022 10:54:54 +0000 Subject: [PATCH 3/3] Fix migration handling in subdirs --- bin/git_rails | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/git_rails b/bin/git_rails index e08907c..8310d27 100755 --- a/bin/git_rails +++ b/bin/git_rails @@ -137,14 +137,14 @@ if [ ! -z "$migrations" ]; then fi # BUILD THE MIGRATION COMMAND FROM THE VERSION AND TYPE - version=`echo "$migration" | cut -d'_' -f1 | cut -d'/' -f3` + version=`echo "$migration" | grep -o 'db/migrate/.*' | cut -d'_' -f1 | cut -d'/' -f3` migrate_command="ActiveRecord::Migrator.run(:$migration_type, 'db/migrate', $version) rescue nil" # APPEND OR PREPREND TO THE COMMAND LIST DEPENDING ON MIGRATION TYPE if [[ $migration_type == "down" ]]; then # CHECKOUT DOWN MIGRATION AND SAVE PATH FOR CLEANUP - git checkout "$old_ref" -- "$migration" - migration_cleanup="$migration_cleanup $migration" + git checkout "$old_ref" -- ":/$migration" + migration_cleanup="$migration_cleanup $(git ls-files :/$migration)" migrate_commands="$migrate_command;$migrate_commands" else migrate_commands="$migrate_commands;$migrate_command"