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 ability to compare between two branches #4

Closed
chris-mitchell opened this issue Oct 21, 2020 · 12 comments
Closed

Add ability to compare between two branches #4

chris-mitchell opened this issue Oct 21, 2020 · 12 comments
Assignees
Labels
enhancement New feature or request

Comments

@chris-mitchell
Copy link
Contributor

Currently, the git client will only query for HEAD~1 and determine the files in the last commit.

We should add the ability to let a developer specify a branch to compare against and determine all the changed files between HEAD and that branch.

We should configure this in the extension and let the user decide which option to use and the branch to compare against.

@chris-mitchell chris-mitchell added the enhancement New feature or request label Oct 21, 2020
@michaelcarrano
Copy link

I've been slowly working on a similar plugin at work, so thanks for open sourcing this and finishing my work for me! 😆

For instance, what I was working on, the main focus was for CI so my branches would be a remote branch, not local (although I was planning on a way to config local vs remote). Would need to handle a situation where the branch does not exists, is there a fallback or do you error?

If I were to try and spend some time implementing this enhancement, do you have any guidance on what you would like to see for this enhancement? Please don't wait for me to get around to this enhancement as my day to day varies on how much coding I can do.

@chris-mitchell
Copy link
Contributor Author

chris-mitchell commented Nov 9, 2020

Glad to hear this is helpful for you!

We currently only support running on the local branch and will assume the last commit has all the changes to consider. This is a byproduct of how our CI system works, but understand most aren't like this.

If this was to be added, I would expect that we'd want to allow configuration via the extension

And then updating the GitClient to make the appropriate queries into git. findChangedFilesSince returns a list of files which will be used to determine the changeset.

@digitalbuddha
Copy link
Contributor

I'm planning to take this issue up today

@digitalbuddha digitalbuddha self-assigned this Nov 13, 2020
@digitalbuddha
Copy link
Contributor

Merged preliminary config. I need to push it down to module granularity next

@jonnycaley
Copy link
Contributor

I was also thinking of another ability for the plugin: comparing the changes of the current branch to the parent fork point. Would this be ok to implement?

If so, I noticed in the thread above you mentioned to implement a similar extension to this plugin "allow configuration via the extension". Am I along the right lines in thinking of adding a commitCommand config value that defaults to your current implementation but also allows for extension of other commit sha obtaining commands that can be added in the future?

Something like this? https://gist.github.com/jonnycaley/ad196a3a258dfb0e271a4a261a646426

If not, no worries 😄

@digitalbuddha
Copy link
Contributor

Yup makes sense! I've added the base git logic here. It just needs to be enabled if the extension has a prop.

const val PREV_MERGE_CMD = "git show-branch -a | grep '\\*' | grep -v `git rev-parse --abbrev-ref HEAD` | head -n1 | sed 's/.*\\[\\(.*\\)\\].*/\\1/' | sed 's/[\\^~].*//'"

I can finish impl over holidays unless someone wants to go to ahead and complete it.

@jonnycaley
Copy link
Contributor

What does that command do? I can't work it out from the shell output 😅

@digitalbuddha
Copy link
Contributor

It should be finding the last merge commit. In theory that should be where you last branched

@jonnycaley
Copy link
Contributor

jonnycaley commented Dec 16, 2020

Ahhh, when I pasted that into a shell it doesn't remove every other \ so I was getting confused. 😅

I think that command gets the parent branch (also found here). We should be able to combine it with the current branch and the command git merge-base current parent to find the commit fork point, something like this:

git merge-base $(git rev-parse --abbrev-ref HEAD) $(git show-branch -a | grep '\*' | grep -v `git rev-parse --abbrev-ref HEAD` | head -n1 | sed 's/.*\[\(.*\)\].*/\1/' | sed 's/[\^~].*//')

If that looks ok i'd like to have a crack at it over the next week or so 😄

@digitalbuddha
Copy link
Contributor

Looks great, please do!

@jonnycaley
Copy link
Contributor

jonnycaley commented Dec 17, 2020

I'm running into bad sha1 reference when I try and run the command PREV_MERGE_CMD in the process builder (works fine in a bash shell). Any ideas why and how to get around it?

@jonnycaley
Copy link
Contributor

It seems ProcessBuilder does not use a shell to execute the commands, so grep is not supported. I'll use kotlin string manipulation instead to get the branch name

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants