Last active
February 16, 2024 09:56
Revisions
-
bartoszmajsak revised this gist
Feb 16, 2024 . 1 changed file with 9 additions and 0 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -88,3 +88,12 @@ fi exit 0 ---- ## Regular branches If you want to use the same approach for regular (existing) branches, use this alias instead [source,bash] ---- git config --global alias.worktree-add "f() { git worktree add ../"$1" "$1"; }; f" ---- -
bartoszmajsak revised this gist
Feb 15, 2024 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,8 @@ ## Motivation Most of the times, when PR is not trivial in scope and size, Web UI can lead to loosing focus and context while scrolling down through the blob of changes. It's way more efficient to go through the code in the IDE. The GH plugins available for most of them can help with that, but they simply checkout the branch for you... I got tired of stashing changes, creating "wip" commits and shuffling branches. -
bartoszmajsak revised this gist
Feb 15, 2024 . 1 changed file with 5 additions and 2 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -22,9 +22,12 @@ And so this workflow was born. <1> Common project settings, usually files globally .gitignored. I use this to add my `.autoenv`, `tools-version` and other utilities, so I have consistent set up across the PRs without manual steps. <2> Cloned repository, main branch, where you would usually work. For the `main` folder, assuming you have your settings in `dev-settings` folder, you have to populate them [source,bash] ---- find ../dev-settings -type f -exec ln -s '{}' . ---- This step is only needed once, for subsequent PR projects it is automated (TODO: add "hook" for clone) -
bartoszmajsak revised this gist
Feb 15, 2024 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -19,7 +19,7 @@ And so this workflow was born. └── main # <2> ---- <1> Common project settings, usually files globally .gitignored. I use this to add my `.autoenv`, `tools-version` and other utilities, so I have consistent set up across the PRs without manual steps. <2> Cloned repository, main branch, where you would usually work. For the `main` folder, once you put your `+dev-settings+` in the new location, you have to populate them -
bartoszmajsak revised this gist
Feb 15, 2024 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -19,10 +19,10 @@ And so this workflow was born. └── main # <2> ---- <1> Common project settings, usually files globally `+.gitignore+`d. I use this to add my `.autoenv`, `tools-version` and other utilities, so I have consistent set up across the PRs without manual steps. <2> Cloned repository, main branch, where you would usually work. For the `main` folder, once you put your `+dev-settings+` in the new location, you have to populate them `find ../dev-settings -type f -exec ln -s '{}' . ` -
bartoszmajsak revised this gist
Feb 15, 2024 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -11,7 +11,6 @@ And so this workflow was born. . Leverages https://opensource.com/article/21/4/git-worktree[git worktree] to have multiple branches within the same cloned repo. . Relies on https://cli.github.com/[GH CLI] to easily checkout PRs the same way as branches. . Uses simple git hook to populate common project settings into new PR directory (optional) .Project structure (root folder) [source,bash] @@ -20,7 +19,7 @@ And so this workflow was born. └── main # <2> ---- <1> Common project settings, usually files globally `.gitignore`d. I use this to add my `.autoenv`, `tools-version` and other `.gitignore`d utilities, so I have consistent set up across the PRs without manual steps. <2> Cloned repository, main branch, where you would usually work. For the `main` folder, once you put your `dev-settings` in the new location, you have to populate them -
bartoszmajsak revised this gist
Feb 15, 2024 . 1 changed file with 50 additions and 8 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,20 +2,64 @@ Most of the times, when PR is not trivial in scope and size, Web UI can often lead to loosing focus and context while scrolling down through the blog of changes. It's way more efficient to go through the code in the IDE. I got tired of stashing changes, creating "wip" commits and shuffling branches. And so this workflow was born. ## How it works . Leverages https://opensource.com/article/21/4/git-worktree[git worktree] to have multiple branches within the same cloned repo. . Relies on https://cli.github.com/[GH CLI] to easily checkout PRs the same way as branches. . Uses simple git hook to populate common project settings into new PR directory (optional) . I use this to add my `.autoenv`, `tools-version` and other `.gitignore`d utilities, so I have consistent set up across the PRs without manual steps. .Project structure (root folder) [source,bash] ---- ├── dev-settings # <1> └── main # <2> ---- <1> Common project settings, usually files globally `.gitignore`d <2> Cloned repository, main branch, where you would usually work. For the `main` folder, once you put your `dev-settings` in the new location, you have to populate them `find ../dev-settings -type f -exec ln -s '{}' . ` This step is only needed once, for subsequent PR projects it is automated (TODO: add "hook" for clone) Now, from the `main` folder we can add PR worktrees using special alias: [source,bash] ---- ❯ git worktree-add-pr 402 remote: Enumerating objects: 2, done. remote: Counting objects: 100% (1/1), done. remote: Total 2 (delta 1), reused 1 (delta 1), pack-reused 1 Unpacking objects: 100% (2/2), 258 bytes | 258.00 KiB/s, done. From github.com:opendatahub-io/opendatahub-operator * [new ref] refs/pull/402/head -> pr-402 Switched to branch 'pr-402' Switched to branch 'main' Your branch is up to date with 'origin/main'. Preparing worktree (checking out 'pr-402') HEAD is now at 1a90cd0 Allow multiple component names for Dashboard Setting up the worktree... ---- This updates directory structure: [source,bash] ---- ├── dev-settings ├── main └── pr-402 ---- Now you can open `pr-402` as a project in your IDE of choice and you can comfortably walk through the code, hack suggestions and run tests! To remove, just call regular git command `git worktree remove -f pr-402` ## Git configuration @@ -35,10 +79,8 @@ checkout_type="$3" if [ "$previous_head" = "0000000000000000000000000000000000000000" ]; then echo "Setting up the worktree..." find ../dev-settings -type f -exec ln -s '{}' . \; fi exit 0 ---- -
bartoszmajsak revised this gist
Feb 15, 2024 . 1 changed file with 42 additions and 1 deletion.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,44 @@ ## Motivation Most of the times, when PR is not trivial in scope and size, Web UI can often lead to loosing focus and context while scrolling down through the blog of changes. It's way more efficient to go through the code in the IDE. I got tired of stashing changes, creating "wip" commints and shuffling branches. And so this workflow was born. ## How it works . Leverages git worktree to have multiple branches within the same cloned repo . Relies on https://cli.github.com/[GH CLI] for dealing with PR branches . Uses simple git hook to populate common project settings into new PR directory (optional) . I use this to add my `.autoenv`, `tools-version` and other git-ignored utilities, so I have consistent set up across the PRs without manual steps. ## Pre requisites ## Git configuration [source,bash] ---- git config --global alias.worktree-add-pr "!f() { gh pr checkout $1 -b pr-$1; git co -; git worktree-add pr-$1; }; f" ---- ..git/hooks/post-checkout [source,bash] ---- #!/bin/bash previous_head="$1" new_head="$2" checkout_type="$3" if [ "$previous_head" = "0000000000000000000000000000000000000000" ]; then echo "Setting up the worktree..." find ../dev-settings -type f -exec ln -s '{}' . \; // <1> fi exit 0 ---- <1> folder in the main project directory -
bartoszmajsak revised this gist
Feb 15, 2024 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,3 @@ ## Pre requisites . GH CLI[https://cli.github.com/] -
bartoszmajsak created this gist
Feb 15, 2024 .There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,3 @@ ## Pre requisites . [GH CLI](https://cli.github.com/)