Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GitFlow Support #842

Closed
red2678 opened this issue Jan 18, 2021 · 12 comments
Closed

GitFlow Support #842

red2678 opened this issue Jan 18, 2021 · 12 comments

Comments

@red2678
Copy link
Contributor

red2678 commented Jan 18, 2021

Will GitFlow actions (ex. git flow feature publish) be supported in v5.x?

@typicode
Copy link
Owner

Not using git-flow personally, but I guess nothing in v5 prevents from using it.
Did you have something particular in mind?

@red2678
Copy link
Contributor Author

red2678 commented Jan 19, 2021

Awesome. I incorrectly linked you to the original git-flow repo; this is the most recent iteration gitflow-avh.

Quick note, the gitflow-avh version was merged into Git for Windows as of version 2.6.4. I am not sure if it matters to Husky that I am using Git For Windows, but I wanted to point it out. The gitflow-avh version is also installable on all other platforms and comes packaged with Ubuntu as of version 18.04.

I am looking for support of the default hooks emitted from gitflow-avh's commands. A few examples can be found here

There is a pre and a post for just about every gitflow-avh command.

Example Command: git flow feature publish

This will emit two "hookable" events pre-flow-feature-publish and post-flow-feature-publish

All the core gitflow-avh commands would be supported then. So:

  • {post,pre)-flow-feature-{finish,publish,pull,start,track,delete}
  • {post,pre}-flow-hotfix-{finish,publish,start,delete}
  • {post,pre}-flow-bugfix-{finish,publish,start,delete}
  • {post,pre}-flow-release-{finish,publish,start,track,delete}

This similar issue was opened, and while GitFlow is an older workflow, I think there is a desire for this feature. #123

@typicode
Copy link
Owner

I'm not on Windows right now. But you could give a try with the following commands:

git init
npm init -y
npm install husky@next -D
npx husky install
# Add one the hook you'd like to test
npx husky add .husky/<pre-flow-...> "touch ok"
# Run the corresponding git flow command
# Check that "ok" file was created

@red2678
Copy link
Contributor Author

red2678 commented Jan 21, 2021

Done, but it did not work. I did try the above actually before posting here (as well as again rn). I assumed since the events I wanted to hook into were part of GIT that Husky supported them out of the box. I had to add one step to the test.

Here are the steps I tried:

git init
git flow init (accept all defaults)
npm init -y
npm install husky@next -D
npx husky install
npx husky add .husky/pre-flow-feature-start "touch ok"
# Run the corresponding git flow feature start command
# Check that "ok" file was created (it was not)

Just as a sanity check I took the file (pre-flow-feature-start) created by huksy and manually put it in ~test_project_root\.git\hooks (removing the call to husky.sh and when I ran the flow command the file ok was created.

I made this screencast for you. Hope it helps!

E002Iif3v4.mp4

@typicode
Copy link
Owner

Thanks for the screencast 👍
Do you know if it was supported in husky 4?

@red2678
Copy link
Contributor Author

red2678 commented Jan 26, 2021

You're welcome! I always like recording vs typing out tons of text.

As for it working on v4, no I don't know (it probably did though). I did not have much time to dedicate to this issue when I posted it, sorry to just push it all on you like that. Anyway, I figured out the issue :) Now we just need to fix it, potentially.

Reproduce The Issue

git init on an empty directory

This will initialize an empty repo and the config file will look like the below (unless you have global or system configs set).

[core]
	repositoryformatversion = 0
	filemode = false
	bare = false
	logallrefupdates = true
	symlinks = false
	ignorecase = true

Notice the missing core hooksPath

Next, we initialize git flow.

git flow init

This adds needed config information for git flow to work and the config file now looks more or less like:

[core]
	repositoryformatversion = 0
	filemode = false
	bare = false
	logallrefupdates = true
	symlinks = false
	ignorecase = true
[gitflow "branch"]
	master = master
	develop = develop
[gitflow "prefix"]
	feature = feature/
	bugfix = bugfix/
	release = release/
	hotfix = hotfix/
	support = support/
	versiontag = 
[gitflow "path"]
	hooks = C:/Users/anthony/Workspaces/testing/.git/hooks

Notice the added gitflow "path"

Now we install husky.

npm install husky@next -D
npx husky install

This adds needed config information for husky to work and the config file now looks more or less like:

[core]
	repositoryformatversion = 0
	filemode = false
	bare = false
	logallrefupdates = true
	symlinks = false
	ignorecase = true
	hooksPath = .husky ** <----------- ADDED  ----------- **
[gitflow "branch"]
	master = master
	develop = develop
[gitflow "prefix"]
	feature = feature/
	bugfix = bugfix/
	release = release/
	hotfix = hotfix/
	support = support/
	versiontag = 
[gitflow "path"]
	hooks = C:/Users/anthony/Workspaces/testing/.git/hooks ** <----------- STILL THE SAME ----------- **

The Issue

When husky is installed into an existing project that is using gitflow husky does not update the gitflow "path" to point to the correct hooks directory (.husky or whatever you defined it to be).

Note: Husky will work if it is installed BEFORE you setup gitflow. Why? Because when you install Husky the core hooksPath is set so when you go to setup gitflow it will correctly suggest you use the hooks dir from the config file (.husky).

So the below will work:

git init
npm init -y
npm install husky@next -D
npx husky install
git flow init (accept all defaults) <---------- moved down from step 2 ----------
npx husky add .husky/pre-flow-feature-start "touch ok"
# Run the corresponding git flow feature start command
# Check that "ok" file was created (it was!!)

TL;DR - The Fix

Well, I guess the "real fix" would be to make it so that when husky is installed it checks for a gitflow "path" in the git config file and updates it to use whatever directory husky is using. How to do that, atm I am not sure. I need to get back to work lol. I will try to take a peek later when time permits.

You can run git config "gitflow.path.hooks" .husky to manually change the git config file to use the correct directory.

Cheers!

@typicode
Copy link
Owner

Awesome! Thanks for the detailed analysis and fix! 🙂

@red2678
Copy link
Contributor Author

red2678 commented Jan 27, 2021

Thanks! I did fork v5 and took a look (congratulations on the release btw). Its simplicity is very impressive!

To the issue. I am not sure that modifying Husky's install process to look for GitFlow is the right approach.

The command git config "gitflow.path.hooks" .husky could be run as you do here during install:

cp.spawnSync('git', ['config', 'core.hooksPath', tmpDir])

However, I would argue that MOST people are not using GitFlow. So perhaps we handle this with some documentation around using Husky with GitFlow. Maybe it would be better to just tell people to run the command and set their hooks directory?

Before I make PR I wanted to get your input.

@typicode
Copy link
Owner

Thanks :)

I agree, a mention in the doc would be better.

@red2678
Copy link
Contributor Author

red2678 commented Jan 28, 2021

Well, PR made #847 but I am getting a build error.

@typicode
Copy link
Owner

It's merged :) Regarding the build error, it's a bug. I'll check the config.

@red2678
Copy link
Contributor Author

red2678 commented Jan 28, 2021

Awesome @typicode thanks!

@red2678 red2678 closed this as completed Jan 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants