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

Add MergedCommits pre-rebase hook #182

Closed
wants to merge 9 commits into from
Closed

Add MergedCommits pre-rebase hook #182

wants to merge 9 commits into from

Conversation

jawshooah
Copy link
Collaborator

Closes #179

Returns a list of branches containing the commit that the given
ref points to.
Commits that have already been merged into one of a specified
set of destination branches should not be rebased.
@jawshooah
Copy link
Collaborator Author

Not sure that dest_branches is the most expressive name for a list of long-lived branches that are frequent merge targets, but I couldn't come up with anything better on the spot. Definitely open to suggestions.

`git branch --contains #{commit_ref}`.
split("\n").
reject { |s| s[/detached from/] }. # ignore detached HEAD
map { |s| s[2..-1] } # trim leading 2 characters
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sadly, the output of git branch can change based on the user's column.branch config setting, so we need to specify the --column flag explicitly to override whatever that is set to.

After playing around with a few of the options the best output I could find was:

git branch --contains <hash> --column=dense`

...which outputs:

  master * current-branch some/other/branch another-branch

Since the asterisk marks the current branch and branches can't have spaces, we could split(/\s+/) and filter out the asterisk to get all branches.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, wasn't aware of that option. Still need to snip out the (detached from <hash>) entry before splitting on whitespace, though.

@sds
Copy link
Owner

sds commented Apr 15, 2015

Thanks for addressing those comments. Merged in 7acea7f.

@sds sds closed this Apr 15, 2015
@jawshooah jawshooah deleted the pre-rebase/merged-commits branch July 14, 2015 01:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add pre-rebase hook that prevents rebasing already-merged commits
2 participants