Here is some extra nifty to add to drush: issue queue commands. I dropped iq.drush.inc in the 'pm' folder, but maybe it doesn't go there. Anyway, here is an example:
$ drush help --filter=pm
Project manager commands: (pm)
iq-apply-patch Look up the most recent patch attached to the specified issue, and apply it to its
(patch, ap) project.
iq-create-commit-com Create a commit comment for the specified issue number.
ment (iqccc, ccc)
iq-info (iqi) Show information about an issue from the queue on drupal.org
$ drush iq-info 1070558
Title : Allow drush si to be run multiple times, re-using same code each time
Project : Drush
Version : All-versions-5.x-dev
Component : PM (dl, en, up ...)
Category : feature request
Priority : normal
Assigned : Unassigned
Status : needs review
$ drush ccc 1070558
#1070558 by greg.1.anderson: Allow drush si to be run multiple times, re-using same code each time
$ drush iq-apply-patch 1070558
Downloading patchfile drush-si-reuse-2.patch for project drush [ok]
patching file commands/core/upgrade.drush.inc
Hunk #1 succeeded at 31 (offset -1 lines).
Hunk #2 succeeded at 43 (offset -1 lines).
Hunk #3 succeeded at 88 (offset -1 lines).
Hunk #4 succeeded at 106 (offset -1 lines).
Hunk #5 succeeded at 241 (offset -1 lines).
Hunk #6 succeeded at 279 (offset -1 lines).
Hunk #7 succeeded at 316 (offset -1 lines).
Hunk #8 succeeded at 328 (offset -1 lines).
Hunk #9 succeeded at 464 (offset -1 lines).
Hunk #10 succeeded at 488 (offset -1 lines).
Hunk #11 succeeded at 529 (offset -1 lines).
patching file commands/pm/pm.drush.inc
Hunk #1 succeeded at 221 (offset -1 lines).
Hunk #2 succeeded at 241 (offset -1 lines).
Hunk #3 succeeded at 1165 (offset -1 lines).
Hunk #4 succeeded at 1794 (offset -1 lines).
It cannot add patches to the queue or commit anything, etc., but it's a start, and already pretty useful.
| Comment | File | Size | Author |
|---|---|---|---|
| #100 | iq-100.patch | 46.79 KB | greg.1.anderson |
| #97 | iq-97.patch | 47.62 KB | greg.1.anderson |
| #94 | iq-94.patch | 44.81 KB | greg.1.anderson |
| #93 | iq-93.patch | 42.92 KB | greg.1.anderson |
| #92 | iq-92.patch | 42.12 KB | greg.1.anderson |
Comments
Comment #1
greg.1.anderson commentedHere is the patch.
Comment #2
msonnabaum commentedI like.
We should probably have it use `git am` though when the patch is created using `git format-patch`.
Comment #3
greg.1.anderson commentedI have noticed that if you follow the instructions at
http://drupal.org/node/97249/git-instructions/master, then the patches created must be applied viapatch -Np1, whereas traditionally, patches are applied viapatch -Np0. It is easy to make a "traditional" patch viagit diff, which is convenient for those who forgot to make a branch, are lazy, or just don't read instructions. Traditionalists might also resist the new instructions, and continue to make patches that apply withpatch -Np0.I think there is nothing for it but to open up the patch file and inspect it, but I'm not 100% sure what to key the difference off of.
Compare:
http://drupal.org/node/1069372
vs.
git diff --no-prefix
We could just move forward and stop supporting old pre-migration patches, and anything made with --no-prefix, or perhaps add --no-prefix as an option for
drush patch.Comment #4
msonnabaum commentedThe big difference is that the patch has the patcher's info it in so it shows them as the author, you as the committer like so:
http://drupal.org/commitlog/commit/2320/88c22bd06c91e7a151309834d2c7b4bb...
You don't really have to do everything in those instructions to make a patch like that though. All you need to do is make a commit after you do your changes and then use git format-patch. Patches that use git format-patch can then be applied by us with git am and the metadata stays in tact, as if we cherry-pick'd it from their branch.
My choice would be to only support patches made via this method.
Comment #5
greg.1.anderson commentedHere is an update, now using git am. It works pretty well 'clean', but is not very good at repetitive execution, e.g. running
drush iq-difftwice in a row does not work. This is because I don't really understand the git rebase command yet. I'm learning, but any help is appreciated.I'm not quite ready to give up on
patch; I have made a half-hearted attempt to use it as a fallback mechanism. Running with --no-prefix (which currently skips git am) works well; automatic fallback does not really work yet. I want to be able to usedrush patchto apply patches that other people make, and I think it will be common to find patches made with diff or git diff for a good time to come.I am now automatically creating a new branch whenever a patch is applied, using
git checkout -b .... The problem I have with this is that -b fails if the branch already exists (e.g. the second time you pull down the same patch). Is there an option that will makegit checkout -b xyzzywork just likegit checkout xyzzyif the branch already exists? Of course, this is probably a bad idea; there might be new patches that the user wanted to keep. Maybe I should test to see if the branch exists, then prompt the user to either abort, or destroy the existing branch and start over.I am also having trouble with:
git remote show origin -n | grep $(git branch | grep '*'| awk '{print $2}') | awk '{print $5}'This is from #1072926: Drush generate-patch for Git?. If I make a local branch when applying the patch, git remote show origin cannot find anything, whereas just
git branch | grep '*'does return the name of my local branch, so I am just using that. I'm not sure I understand the issue with remote branch tracking.Despite the limitations and unfinished status of this code, I am still finding it useful.
Comment #6
msonnabaum commentedI think we could solve the repetitive execution and the existing branch name problem by checking if the branch exists first, and deleting it if so. Seems pretty safe if we prefix it something like:
git checkout -b drushiq-[description]-[issue]We could check for it with:
git show-ref --verify refs/heads/drushiq-[description]-[issue]The `git remote show origin` is confusing because I think the patch instructions are a bit confusing. They work as long as you checked out your branch how it tells you to at the beginning, but say you do this:
Make changes…
That will fail because the branch was tracking master instead of 7.x-4.x, because I didn't use --branch 7.x-4.x in the original clone. This scenario seems likely to me since I'm probably not going to create a new clone for every patch I make. If we're creating or applying patches, we need to make sure we're doing it from local branches that are tracking the correct remote branches.
An easy way to avoid this is to specify the remote branch while creating the local one:
If you checkout the branch that way, `git remote show origin` will show you what remote branch the local branch is tracking and it should be safe to rebase before making a patch.
Comment #7
xjmTracking. This is awesome.
Comment #8
moshe weitzman commentedi really like this too. not sure if it belongs here or in drush_extras but i think it will be very popular. lets keep developing it here ... please keep asking questions as needed. i see that mark replied to the last one so i'm not sure how to help move this along right now.
Comment #9
lelizondo commentedsubscribing
Comment #10
greg.1.anderson commentedJust a late comment re: #8, yes, Mark's answer does make sense to me, and I'll add the changes to creating a local branch, deleting it first if it already exists (only operating on "drush-iq-*" branches). I still need to really understand what is going on with a rebase (what is rebase for, what does it mean?), just need to sit down with the git docs for a while. I've been tied up with site-upgrade and making fixes to a few of my Drupal sites for a little while now, but will return to this.
Comment #11
msonnabaum commentedIts worth mentioning that there's been some talk in #drupal-gitsupport about the current format-patch/am workflow, and not everyone is crazy about it. Some are suggesting just using git diff for now until we have per-issue repos, so it may be worth holding off on this until things settle down a bit.
Comment #12
rfayAwesome. Looking forward to looking at this!
Comment #13
dwwYeah, this looks really slick!
The way the test bot handles p0 vs. p1 is to just try applying at p1 first, and if that fails, try again at p0. Not sure if that's feasible here or not, but I wanted to mention it.
Also, it'd be nice to someday have an API to get issue metadata in json or something instead of having to scrape the HTML. See http://groups.drupal.org/node/126529 and http://3281d.com/projects/remote-issue-queues for more on this sort of approach.
Comment #14
kotnik commentedSubscribing, and looking forward to use this.
Comment #15
greg.1.anderson commentedThe project API would be very helpful. The drush issue-queue commands cannot successfully scrape this issue right now due to comment #6; the URL inside the code block is incorrectly converted into HTML, with the "
" following the link being included in the URL for the link (mouse over the "cd" on the next line and you'll see that the link incorrectly spans a line). This means that there is an escaped < in the link's href, which makes the html in this issue invalid to the xml parser. Drat.
Comment #16
greg.1.anderson commentedRegarding #11, the git user manual says:
The git instructions will show you how to use a stable tag, or how to base the change off of master. Historically, the convention on d.o has been to always submit patches that are based on HEAD of the most recent (or active) dev branch. Maybe this will change in the future. I could certainly code this up to always use git diff until we knew what the right workflow should be.
Per-issue repos sounds excessive to me. git seems pretty good with branching; wouldn't per-issue branches be more appropriate?
Comment #17
Josh The Geek commented+1
Comment #18
msonnabaum commentedGreg, I think the issue with per issue branches is a sort of middle point between how Drupal.org has traditionally worked and github. On github, you fork projects, which creates a copy of the main repo associated with you, and then you do a pull request where the maintainer adds your repository as a remote, and then cherry-picks or merges your changes into the main repo/branch. The only difference with issue branches is that its per issue rather than per user. Those repos will still have a feature branch where the work will be done.
That said, I still haven't watched the video from drupalcon where this was explained better. I'm doing a bit of guessing on how the issue branches will work.
Comment #19
dwwDiscussion of per-issue repos and how they'll work is totally off topic for this thread. ;) It's partly explained via our DCC talk:
http://groups.drupal.org/node/133289
Don't know where the video is posted, but that at least has links to our slides.
The gory details are at these two posts:
http://groups.drupal.org/node/52953
http://groups.drupal.org/node/50438
But please, let's stop discussing those here, okay? ;)
Thanks,
-Derek
Comment #20
moshe weitzman commentedI tried this out and it works pretty well at first glance. The repetitive execution thing is a bit hairy but I bet we can find a solution. I'll thinker a bit.
I really do hope someone takes on the relatively easy issue of making a page which shows issue metadata (including most recent attachment) in JSON.
Comment #21
greg.1.anderson commentedI've got some improvements to post; will do so shortly.
Comment #22
greg.1.anderson commentedHere is an improved version; still needs some work, but at least you can run 'drush diff' more than once now.
Comment #23
greg.1.anderson commentedA few more minor enhancements.
Comment #24
kotnik commentedYou have a lot of trailing whitespace, like here.
Powered by Dreditor.
Comment #25
greg.1.anderson commentedPer #19 (please read the background there, if you haven't already), I agree that we should not discuss WB or WC here, and instead use the existing threads referenced above. However, I'd like some feedback on how drush iq-* should implement WA.
The current code expects that you are working on a branch. If you used drush patch to start working, then you will be, but you might be on master if you just run drush diff without making a branch.
Drush diff tries to do a commit before it calls rebase and format patch, but it expects that the user will call git add first. If you don't call git add, you'll get a warning message and the rebase will fail, so this is okay. Maybe it could be better if drush patch called git add on every file that was modified by the patch.
If you make your own branch, then drush won't be able to find the issue associated with your patch (there might not be one...), so it won't be able to make a commit comment, so the commit won't go well. This could be fixed by having drush somehow compose a commit comment, perhaps based on the branch name?
If you have not made a branch and are working on master, then drush's idea to do a commit is suddenly not so good. I suppose this situation could be detected, and we could revert to git diff.
Comments welcome.
Comment #26
moshe weitzman commentedGood questions. Starting from the top of the workflow ...
@kotnick: It is fine to mention whitespace as part of a substantial review. But it is rude to just mention trivial stuff like whitespace in a patch review. If you can't dedicate more time, or have nothing more to add, then please don't post the review.
Comment #27
R.J. Steinert commentedsubscribe
Comment #28
moshe weitzman commentedComment #29
Josh The Geek commentedoptions, not arguments
Powered by Dreditor.
Comment #30
greg.1.anderson commentedRe #28.1, the xhtml is different if simpletest has run a test on the patch. I'll adjust the code so that it works with both simpletest-adjusted patches and straight attachments.
I have not been good about putting my enhancements to the iq commands on this issue, so I'll have to 3-way merge #28 in to my code. I'll post a new patch here once I did that.
@Josh: Fixed #29, and several similar typos; thanks.
Comment #31
moshe weitzman commentedMost of my changes were just removing tabs and fixing indentation. I suggest applying the attached diff. Just ignore any hunks that conflict with yours since there is no substantial change here.
Comment #32
greg.1.anderson commentedI still have not worked through all of the issues from #26, but here is an updated patch that fixes the bug from #28, and allows the iq commands to find attachments regardless of whether the automated test runner has touched the issue.
Comment #33
moshe weitzman commentedgave this a whirl. one more thought: we do
git fetch origin && git rebase origin/master && git format-patch origin/master --stdout. I think that hard coding origin/master is not right. Admin might be reviewing a patch for another branch. We should specify the same branch we used for tracking when we created the current branch.Comment #34
Josh The Geek commentedAlso, would it be possible to make an option so that the command uses diff, not format-patch? I prefer to keep me email away from Google.
Side note: isn't
git fetch origin && git rebase origin/masterthe long form ofgit pull --rebase origin?Comment #35
moshe weitzman commenteddrupal.org already solved the email privacy issue - http://drupal.org/node/1022156. we're only going to support the recommended workflow.
not sure if it applies here, but we occasionally use a longer git command in order to be compatible with older git versions.
Comment #36
greg.1.anderson commenteddrush itself currently requires git 1.7+; unless that changes, there's no reason why we could not use shorter command versions e.g. as described in #34. For now, though, getting things working correctly (e.g. #33) is more important than optimisations.
Comment #37
R.J. Steinert commentedhttp://1BeerToKillSubscribeComments.org
(my penance for that subscribe comment, sorry)
Comment #38
greg.1.anderson commentedThere's a good article on lulbot, Git Best Practices: Upgrading the Patch Process, that describes git diff vs git format-patch. This article recommends always using the --stdout flag with git format-patch.
Another useful bit of advise from the article is to always include the hash of the starting commit in the issue text so that people could potentially just check out your starting point and then apply the patch if they did not want to fix conflicts from commits added after your patch was made (started). drush iq-diff could maybe include this as a comment at the beginning of the patch as a service. (n.b. currently, iq-diff outputs junk at the head of the patch that must be removed before applying with git am. This junk should be sent to stderr so that it does not end up in the patch file.)
Finally, the article advises using the --3way flag with git am. This would be a useful addition to drush iq-patch.
I will incorporate these improvements to the drush iq-* commands.
Comment #39
sepla commentedsubscribing...
Comment #40
moshe weitzman commentedSome discussion about patch p0 and p1 at #745224: Apply patches from git diff and git format-patch
Comment #41
greg.1.anderson commentedAnother thing I was thinking about regarding applying patches is that drush make writes info about the patches it applies to a module when the module was patched. I think that iq-patch should do the same thing, or perhaps even use drush make to apply patches. This relates to #820954: Update core and modules with Drush make as well.
I am sort of stalled on this issue, though, because too often I get the error message that the patch could not be found in the issue due to various html scraping issues. I just don't feel motivated to fix those as they come up, because it's faster to open the issue, download the patch and apply it by hand than debug some sketchy html-correction code. Sure would be nice if we had a web api on d.o. to get this info, because as easy as the download-and-patch-by-hand workflow is, I like
drush patch 123456even better -- it's quite fun when it works.Comment #42
dwwYeah, I'd be happy to see a node/N/json view of all issue and project nodes that includes a JSON array of useful node data. For issues, that'd obviously include all the current metadata, title, etc, and it could also include a list of attachments from all comments, comment count, whatever. There are various discussions on g.d.o about this, but I don't think there's an issue on d.o about it yet.
Comment #43
greg.1.anderson commentedTake a look at the output of
drush iqi --long <issue-number>; something similar to this in json would be welcome.Here's an example from an arbitrary recent issue that has an attachment but is not too long:
Comment #44
moshe weitzman commented@dww - i will happily write a project_issue JSON patch if you can review it and a mail.inc patch within 2 weeks.
Comment #45
dww@moshe: Sorry, I can't make any promises right now. My life is going through some tumultuous times so I've got very spotty availability (and little or no mental focus when I do have any time). Ugh. But, don't let that stop you. There's always mikey_p and hunmonk to review and commit stuff. ;)
Comment #46
moshe weitzman commentedPosted patches which enable a JSON menu callback for project_issue nodes. See #112805: JSON menu callback for project issues
Comment #47
greg.1.anderson commentedUpdated patch that works with the JSON data from #112805: JSON menu callback for project issues, if available. Still some issues with the way git is called in this version.
Comment #48
helmo commentedlooks nice but it indeed needs some work.
I did a few minor fixes, added a branch in my drush_helmo sandbox for this.
http://drupalcode.org/sandbox/helmo/1277350.git/commitdiff_plain/master-...
pretty printed: http://drupalcode.org/sandbox/helmo/1277350.git/commitdiff/master-upstre...
Too bad we don't have iq-upload-patch yet ;)
Why is the code in commands/sql/iq.drush.inc? commands/pm seems more logical.
As per a similar issue in dreditor shouldn't this line include the prefix 'Issue '
#1061758: Make commit message button format something that doesn't start with #
Comment #49
greg.1.anderson commentedI had it in pm in #32 and earlier, but put it in sql in #47 by mistake.
Comment #50
helmo commentedAdded a few commits:
* Check bootstrap phase before calling drush_get_extensions(), was also still calling drush_pm_get_extensions()
* Add missing dt() call in drush_log call
* Don't add getcwd() to $filename as it already is a full path
* Fixed placement of iq.drush.inc, back to pm folder
And a new patch for review.
Comment #51
clemens.tolboom[edit : see next comment]
Comment #52
clemens.tolboom[edit: removed noise]
Comment #53
helmo commentedThis is a result of the "autosetuprebase = always" option we have in our gitconfig. We'll have to reevaluate this.
Comment #54
helmo commentedThe autosetuprebase option breaks the output parsing in _drush_iq_get_branch_merges_with().
It might work to also match for "rebases onto remote" but I think the function needs more work,
Comment #55
clemens.tolboom[edit: removed noise]
Comment #56
clemens.tolboom[edit: removed noise]
Comment #57
colanMarking the following as duplicates:
Comment #58
moshe weitzman commented#112805: JSON menu callback for project issues has been committed and deployed. See this issue in JSON format.
Hope folks can restart work on these commands again.
Comment #59
greg.1.anderson commentedIt was my goal to roll another patch here before the deploy to d.o, but I didn't manage it. It's awesome to see the JSON info live now. I'm going to try to roll a new version tonight to update to the new schema, and to take out the crufty html-scraping.
Comment #60
greg.1.anderson commentedHere is a re-roll updated to use the standard project issue JSON now available on d.o. Note that work is still needed in the way that git is used with the patch; notably, the suggestions from #26, #34, #38 and #53, to name a few, are not done.
Comment #61
tim.plunkettThis looks awesome so far.
Looking at the comment in
_drush_iq_find_patches()about multiple patches per comment, often in the core queue there will be the patch to apply, the patch with only tests and no fixes to purposefully fail, and an interdiff.txt. There is no set naming convention for distinguishing the two.Also, patches could be either .diff or .patch.
Comment #62
greg.1.anderson commentedHere are a couple of issues in core with multiple patches in one comment:
#681760: Try to improve performance and eliminate duplicates caused by node_access table joins
#1222106: Unify language negotiation APIs, declutter terminology
#1430300: Preprocess functions in an include file fail to get called when the theme implements a suggestion override
I suggest the following "soft logic" for sorting out multiple patches
...interdiff.D0.patch-test-only.patchunless it also has "combined" e.g.-test-combined.patchThese are reasonable guesses that seem like they will get the right answer fairly frequently. If people start using this tool, then perhaps naming conventions will arise that help Drush pick the right patch. We can always adjust our code if contrary conventions arise.
There are also comments that contain both a D8 and D7 version in the same change, one patch for each; for example: http://drupal.org/node/404302#comment-5656838
I'm not sure if we should perhaps also positively weight occurances of "d7" or "d8" in patch filenames that do or do not match the major version number of the bootstrapped Drupal site. If we open up the patch file and inspect it, we might find some information that would help us determine where the patch came from. For example, the D8 patch from the above-referenced patch contains a line that reads
index c148995..d01792e 100644. Those look like hashes, but I could not figure out what branch they came from using git.git show c148995will dump the base file, butgit log c148995prints nothing. Presumably there is a way to find out. It would be cool to find the base sha hash that the patch was rolled from, because we could use that information to insure that the user is patching from the correct place -- or maybe even offer to take them there if their tree is clean.Supporting .diff is of course easy and should be done.
Comment #63
moshe weitzman commentedWill try this out soon. Meanwhile, a few quickies ...
Comment #64
tim.plunkettWith respect to "tests only" patches, there is a new standard that is recognized by the test bot:
PATCHNAME-do-not-test.patchhttps://twitter.com/#!/randyfay/status/174364180730744834
Comment #65
tim.plunkettHm, that last post is about patches set explicitly to not be tested, not test only patches.
#1092232-21: Bot needs to handle patches named for all core versions -D[678]
Comment #66
greg.1.anderson commentedPresumably test-only patches will also be named -do-not-test as well -- you don't want the bot to show the failed result, test-only is for humans, right? All the same, I think I will still support all of #62, because the issue queue commands need to deal with old issues in addition to new issues.
It might be nice if test-bot results appeared in the json; then we could demote patches that failed testing, and promote those that passed.
Comment #67
dwwIn my experience, you want the bot to test both the test-only patch and the patch with both the new tests and the fix. That way, it's obvious that the test is catching a problem in core, and that the rest of the patch fixes the problem in core such that the new (and existing) tests all pass.
I'm not sure that the test bot stores data persistently in the DB about the status of test results for each patch. If so, then it should be relatively easy for pift.module to implement hook_project_issue_json_alter() just like comment_upload.module is doing. Although, I wonder if we're going to run into a weighting problem where pift.module needs to alter after comment_upload.module does so that it can alter the JSON that comment_upload injects. If pift.module doesn't store that data in the DB, I don't really know how this is going to work. Sadly, I know very little about the internal workings of pift.module. It's always been maintained by other folks. I highly suggest finding rfay, jthorston, boombatower, et al and getting their input on this.
Cheers,
-Derek
Comment #68
greg.1.anderson commentedpift is altering the HTML markup for the patch in the issue text, and I imagine that is done by an alter hook, so my guess is that someone already solved the ordering problem. Thanks for the names of the knowledgeable parties, though; I'll keep them in mind if I look into this.
Comment #69
tim.plunkettRight now, the commit messages being generated start with #, causing issues with rebasing.
Following http://drupal.org/node/52287, I switch it to start with 'Issue #'.
Also, I added a check for .diff as I said in #61.
Still cnw.
Comment #70
moshe weitzman commentedis anyone available to push this along? See feedback in #60 and #63
Comment #71
greg.1.anderson commentedThe thing that put this on the back burner for me (besides the fact that I have been putting a lot of work into drush_sup) is that I have been considering what the right approach for managing git for the user. As currently written, the format patch command requires that the patched module be checked out (cloned) from drupal.org (e.g.
drush dl --package-handler=git_drupalorg token). Perhaps this is a reasonable requirement, but it also seems it might be nice to help the user set up the right environment so that things would work right. For example, the apply patch command could do the required clone if the module wasn't already under git version control. If the Drupal site is already in a repository, though, then things get a bit questionable. What if the user has checked the drupal root into a local repository? At this point, I'm a little uncertain about whether git submodules, git subtree, dog, or some other strategy might be helpful. It would probably be best to try to push this along and not make it perfect; suggestions are welcome.Comment #72
moshe weitzman commentedI would omit complications like 'module is not under version control' and 'site is already under version control'. Lots of people work on core and modules for their own fun outside of real site. Those folks will have scratch sites not under version control and git clones of modules from git.drupal.org
Comment #73
greg.1.anderson commentedHere is an update of #69 to match the schema changes made to d.o at http://drupal.org/node/112805#comment-6005706.
Comment #74
greg.1.anderson commentedRemoved some dead code.
Comment #75
tim.plunkettTried to apply this patch and use it and it removed my entire git clone. The whole directory. Whoo!
Comment #76
greg.1.anderson commentedThat does not sound very friendly. :( What command did you use? Applying a patch will register the patch file for deletion, and the reset command will call
git branch -d, but I can't imagine what code would delete everything. Let me know what you did, and I'll try to reproduce.Comment #77
tim.plunkettComment #78
greg.1.anderson commentedHere is an updated version with a working ap command. iq-diff still needs some work.
Comment #79
greg.1.anderson commentediq-diff and iq-reset also fixed up in this version.
Now, the drush iq commands help manage git repository in an innocuous way. iq-apply-patch creates a new branch, but beyond that, your repository status is by default left unmodified. iq-diff still uses format-patch, so that author credit is included in the patch, but the requisite commit that format-patch requires is backed out again by iq-diff, so it behaves like git diff. The commit may be retained via the --commit flag, so folks who like this behavior can set a command-specific option in their drushrc file.
Needs docs, needs to be in commands/iq instead of commands/pm, but code could use review.
Comment #80
tim.plunkettI tested only ap here.
This didn't work at all, but didn't kill my repo.
This produced a whole bunch of warnings, but everything worked okay
Comment #81
greg.1.anderson commentedHere are some improvements on finding the Drupal root. Only lightly tested.
Comment #82
greg.1.anderson commentedHere is another patch, now with more testing, more error checking, and more (some) command examples.
One critical problem remains.
iq-diff can not correctly determine the branch to diff against. If you have two remote branches checked out (e.g. both the 7.x and 8.x branches of Drupal), then iq-diff will sometimes get the wrong branch, which will result in a huge and meaningless diff.
Here is what I need in order to get this working right.
iq-apply-patch will create a new branch, call it x. After the
git checkout -b x, I need to know what git command(s) will print out the name of the branch I was on before branch x was created. Any help in doing this would be greatly appreciated.Comment #83
tim.plunkettWhy not store the branch name before creating/switching?
git branch --no-color | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'will do that for you.Comment #84
moshe weitzman commentedAll branches have an upstream. Could we not set the upstream to origin (i.e. to the remote branch?) when we branch? I have not looked at this in any detail so ignore me as needed.
Comment #85
greg.1.anderson commentedI did consider #83, but I would rather not maintain an external cache for the repository. This could get messed up if you pushed a branch somewhere, or if you moved or renamed your working tree, etc.
Storing the branch inside git per #84 is a good option, but since gitk shows the info that I need, and since git must know how the commits branch, I figure getting the info straight out of git is the best way to go, if it is possible.
I can get the most recent commit hash via:
git log --format=format:%h --max-count=1If that hash is on our branch, then I could add in a --skip=1 and call again, looping until I find one that is interesting.
For example, I have this commit on my working branch:
If I walk backwards, eventually I get this:
It just so happens that I forked two feature branches from the same Drush commit on the master branch, so as far as git is concerned, 015436a is on all three branches. However, this is good enough, because I already have code that will find all of the branches with remote origins, so this will allow me to select 'master' over 'generate-profile'.
I am not sure if this is better than #84. If someone added a remote upstream by hand to some other branch (e.g. generate-profile in the above example), I could still differentiate between the two, because one would say "master merges with remote master" (or "rebases onto"), whereas the other would say "generate-profile merges with remote master" -- unless someone pushed their iq branch remotely. We could just say "don't do that" (exit with an error, provide a flag to disambiguate as necessary). Somehow adding the extra upstream seems like extra clutter to me, but maybe that's not important. Any opinions, or better ideas?
Comment #86
moshe weitzman commentedNo need to fuss with commits. I think this answer gives what the remote branch which is what we need here - http://stackoverflow.com/a/7251377
Comment #87
greg.1.anderson commentedI could not get any of that (#86) to work unless I set an upstream branch per #84. By default, all of those variables are empty. If I add an upstream branch, though...
This does not add any extra output to other commands, such as
git branchorgit remoteorgit remote show origin, so it seems that clutter is a non-issue, and this is probably the way to go. I'll just grab the current branch before creating the iq branch, and then set the upstream once it has been created. Then, iq-diff will be able to use git config and git rev-parse to get the name of the correct branch.One thing that does cross my mind, though, is that it would be a shame if
drush iq-diffdid not work with branches the user creates by hand. Perhaps I should fall back to the current implementation if there is no upstream branch set, and fall back to fussing with the commit history if there are multiple remotes.Comment #88
greg.1.anderson commentedOh, I was doing #87 on some branches I created by hand. I just noticed that #82 is already setting the upstream via
git checkout -b newbranch origin/master. So little clutter, I didn't even see it. :p Onward with git config branch.newbranch.merge...Comment #89
greg.1.anderson commentedThis resolves #82. Still need an iq topic. Still need an iq test.
Comment #90
greg.1.anderson commentedComment #91
greg.1.anderson commentediq topic.
Comment #92
greg.1.anderson commentediq test. Test reveals some minor rough edges, but they pass.
Comment #93
greg.1.anderson commentedImproved the code to better handle working in (no branch) mode (e.g. when checking out a specific tag of a project), and made iq-apply-patch a little more resilient by avoiding git-am entirely if the patch came from diff, and by running patch first in --dry-run mode before attempting to actually apply it.
Tests now run smoothly, and pass.
Comment #94
greg.1.anderson commentedIf there are multiple commits on the iq branch, iq-diff will now squash them, so that the format-patch will come out readable, like a git diff, but with author credit. All commits are included if --no-squash option is specified.
Comment #95
jonhattanHere's a quick review. Will start to use it more and more. Great job!
Found a warning when the nid is not an issue
URL label is stripped
This is wrong. In that issue there's no patch in #149, two patches in #150, and one in #151 (I was trying to see what happen when a comment has two patches).
Would be nice to see which comment iq-apply-patch is taking the patch from, in addition to the patch filename.
You mean "comment" instead of "commit" ?
typo: wiith
Perhaps re-visiting instead of re-open ?
This line is missing in some command definitions.
"git format-patch"
What issue title? I see the command callback can receive a optional number. It is missing in the command arguments.
Comment #96
greg.1.anderson commentedThank you for the review. Here is a new version that takes care of everything raised in #95, except for the miss-numbering of comment numbers in issue 357082. This is caused by a bug in the project_issue json that manifests when someone deletes a comment. :( This must be fixed in project_issue.
Comment #97
greg.1.anderson commentedPosted a fix to project_issue queue: #1730728: Project issue json needs comment index number included in data structure
Here is an update of the issue queue commands that reconciles with the above fix. Patches may now be identified either by id, as in 357082-6334764, or via index, as in 357082-#151. This code runs with or without the above project_issue patch, but without it, the index form for selecting patches will be incorrect whenever issue comments are deleted. For example, 357082-6334764is mis-identified as 357082-#150 without the patch.
Comment #98
moshe weitzman commentedSince we decided to move iq to Contrib, this should move to iq.drush.inc. The change to command.inc should be committed to drush core.
I think an alias of 'am' makes sense. Matches git.
drush_iq_download_infoComment #99
dwwNote: I deployed the fix for #1730728: Project issue json needs comment index number included in data structure to the live site...
Comment #100
greg.1.anderson commentedRegarding --author, we have a reference to the author's uid and d.o homepage url, but not the corresponding d.o author string. We'd need that from d.o to proceed here. I'd guess that dreditor scrapes the necessary string from the user's d.o homepage.
I looked, but could not find a good substitute or subset of _drush_iq_project_dir in the pm command files. drupal_get_path is close.
Other items form #98, #99 done, except for additional doxygen and refactoring to drush_iq, still in progress. Posting interim work here for reference; will close this as fixed shortly, once this is committed in drush_iq project. Thanks for all of the assistance on this issue -- the reviews, patch additions, and of course the d.o integration were all extremely helpful.
Comment #101
greg.1.anderson commentedReassigning to new project.
Comment #102
dwwRe --author: this is what dreditor uses:
https://drupal.org/user/46549/git-attribution
https://drupal.org/user/438598/git-attribution
...
Cheers,
-Derek
Comment #103
PatchRanger commentedBrilliant! Great work, greg.1.anderson!
I am currently working on Patch Manager module: I'm looking for an appropriate solution for patch applying (#1151002: A simpler way to patch). Patch Manager uses the /usr/bin/patch tool - but it is not acceptable for Windows-based users. Your project - what we need.
How can I specify the dependency of your project? (It seems to be impossible - or not?)
Would you mind if we merge the projects?
Patch Manager will give to Drush Issue Queue features as follows:
- All patches are stored in the system as nodes - none is lost.
- Administrative interface of all patches management - everything is under control.
What do you think about it, Greg?
Comment #104
dww@Staratel: I'm not sure you understand how drush works. It's not a drupal module, and you can run all of these drush commands inside directories that don't actually have a Drupal site installed at all. So you can't have a drupal module depend on a drush command in the same way you can have modules depend on each other. And there's no "system" where patches could be stored as nodes -- there might not be a database setup at all when running these drush commands.
Furthermore, the whole architecture of the patch_manager module is a bit scary from a security standpoint. To apply/revert patches, your webserver would need write access to all your Drupal files, which is generally a big no-no. I just posted #1733958: Document that this module depends on a less-secure website configuration to work about that.
So, I don't think merging projects makes any sense at all. There's possibly some useful code in drush you could harvest for patch_manager, but ultimately, they're fundamentally different architectures for running code. Generally, sites would be better off managing patches with drush (running as the user that owns all the source code files via a shell on their webserver) not via the Drupal admin UI itself. At least in terms of the security of their site configuration. In some cases people don't have direct shell access, and then a tool like patch_manager might make sense. But then a dependency on drush would entirely defeat the purpose.
Hope that helps clarify,
-Derek
Comment #105
PatchRanger commentedThanks for your response, Derek.
Exactly, that is why I'm looking for a way of applying patches in secure manner. I need a clean and OS-independent way of applying and managing patches. Drush Issue Queue is a great project for patch applying and to work with issue queue - but it has no options to manage patches that are already applied. When I say 'are stored in the system' - it means that Drupal installation is used to store patches that were applied to it. I understand that Drush could be used without any Drupal installation - but it could be used with it too. So I am going to implement patching using Drush Issue Queue in Patch Manager module (read below for more information).
Maybe I am missing something, but wouldn't it better to have a Drupal module that has a setting proposing user to choose which way to apply patch : the first one - using /usr/bin/patch is accessible only for UNIX-users and has warning that it needs insecure server configuration; and the second - using Drush (in fact, Drush with Drush Issue Queue) which has notification that it needs to be installed and a link to appropriate how-to. I think it is good approach to move users from insecure patching to Drush using, isn't it?
To go this way I need one of two things to be done:
1) Either Drush Issue Queue becomes a part of Patch Manager.
2) Or it is included in official Drush release - so it is not necessary to patch it itself before using.
Is my effort clear?
Comment #106
dwwAgain, moving this drush command inside patch_manager totally defeats the purpose of having it as a stand-alone drush command that can be used outside of a working Drupal site. So that's not a viable option at all.
Maybe I'm not understanding your proposal, but I don't see how you can have a setting inside patch_manager that will get the user to install and use drush. If I set this to "use drush", I still have to actually log in via the shell (if possible), install drush, and invoke the appropriate commands (which would be outside the control of patch_manager). So, I don't really see what this setting does. However, this is really off topic for this thread. Looks like that's what #1151002: A simpler way to patch is about, so we should talk there, not here.
However, once the dust settles and this set of drush commands here actually works, this is going to be committed as a stand-alone drush extension. It doesn't have to be part of drush core itself. As soon as there's an official release of drush_iq, installing it will be as simple as:
drush dl drush_iqThat's it.
Cheers,
-Derek
Comment #107
greg.1.anderson commented@Staratel: Thank you for your comments. Although I have not tried your module yet, it sounds like patch manager is a very useful and helpful module for some people. For my part, I like to manage my patch files in Drush make files, which I store in installation profiles that I generate with a script. I am in the progress of improving this at the moment, and will have another release of it up shortly. At one time I had hacked integration, but not sure what happened to that code -- will need to do it again. :p
As was mentioned, it would be less useful to have drush_iq be part of the patch manager module; however, I will put a pointer to your module in the drush_iq README. Adjusting the patch manager to use drush_iq, if available, would also be a useful feature, as you could then reference issues by id instead of url only. Note, however, that drush_iq uses git am and/or the patch tool to apply patches, so by itself it will not make your module more compatible with Windows. Please see the instructions for the Drush Windows Installer, and #1733630: Using mingw Rather than suggested instructions for notes on getting a patch tool for Windows via msysgit or mingw.
Aside: I have pushed out a dev release of drush_iq, so that should be visible on the project page shortly. I will be making a stable release soon too.
Comment #108
moshe weitzman commented@Greg - You can give author credit just with uid. Thats what I successfully tried at http://drupalcode.org/project/drush.git/commit/bc1dccf
Comment #109
greg.1.anderson commentedThe thing about author credit for --commit is that it will usually vanish again when you run iq-diff, as by default the format-patch is squashed down to a single commit crediting the poster as --author, with other contributors in the issue title. You must pass --no-squash to avoid this; however, it's probably not a good idea to avoid squashing, because that would make the patch harder to review.
I think I will do author credit in conjunction with an iq-merge command, which would, in conjunction, be useful for module maintainers.
Comment #110
greg.1.anderson commentedAdded some follow-on issues to the iq issue queue:
#1734876: Give author credit when applying patches created via diff when using --create, and add an iq-merge command.
#1734884: Add an iq-interdiff command
#1734888: Make it easier for your iq branch to follow along with a series of patches posted to an issue
#1734896: Consider improvements from article "Git Best Practices: Upgrading the Patch Process"
#1734906: Add an iq-submit command
Help and advice on any of these appreciated (esp. the last one :> ).
Comment #111
greg.1.anderson commentedOT: drupal.org support request. I accidentally typo'ed, and pushed a '7.x-1.x-dev' branch to the drush_iq project. I have since corrected this, and pushed the proper 7.x-1.x branch, but the old 7.x-1.x-dev branch still shows up on the version control instructions, which is potentially confusing. Is there any way for me to permanently delete the branch? If not, I will just empty it and put an explanation in a README file. :p
Edit: Got it:
git push origin :7.x-1.x-devthanks to #1074852: Remove unused tag and branches in git repo.Comment #112
tim.plunkettgit push origin :7.x-1.x-devComment #113
webchickI think as long as there are no release nodes pointing to a branch/tag, you can delete it in the normal Git way.
Comment #114
greg.1.anderson commentedThanks tim!
Comment #115
greg.1.anderson commentedPostscript: I had tried
git push origin 7.x-1.x-dev; that didn't work until I added the necessary ":". Thanks, all.Comment #116
greg.1.anderson commentedPushed a stable release, 7.x-1.0, including #1734876: Give author credit when applying patches created via diff when using --create, and add an iq-merge command..
Comment #117
webchickWOW! AWESOME! Can't wait to try this out. :D