Uploaded patches are empty
When I use the upload_patch command the file that is uploaded is empty. However, adding the same file manually in trac works.
Operating System: Mac OS 10.11.16.
Copy of the file ( I had to change the extension from .diff to .txt to upload here ) 39800.txt
git diff master --no-prefix output:
diff --git a/src/wp-includes/nav-menu-template.php b/src/wp-includes/nav-menu-template.php
index 737d6e6..ea7c22d 100644
--- a/src/wp-includes/nav-menu-template.php
+++ b/src/wp-includes/nav-menu-template.php
@@ -394,6 +394,18 @@ function _wp_menu_item_classes_by_context( &$menu_items ) {
) {
$classes[] = 'current-menu-item';
$menu_items[$key]->current = true;
+
+ $_anc_id = (int) $menu_item->db_id;
+
+ while(
+ ( $_anc_id = get_post_meta( $_anc_id, '_menu_item_menu_item_parent', true ) ) &&
+ ! in_array( $_anc_id, $active_ancestor_item_ids, true )
+ ) {
+ $active_ancestor_item_ids[] = $_anc_id;
+ }
+
+ $active_parent_item_ids[] = (int) $menu_item->menu_item_parent;
+
// if the menu item corresponds to the currently-requested URL
} elseif ( 'custom' == $menu_item->object && isset( $_SERVER['HTTP_HOST'] ) ) {
$_root_relative_current = untrailingslashit( $_SERVER['REQUEST_URI'] );
diff --git a/tests/phpunit/tests/post/nav-menu.php b/tests/phpunit/tests/post/nav-menu.php
index c6a028c..d0496a1 100644
--- a/tests/phpunit/tests/post/nav-menu.php
+++ b/tests/phpunit/tests/post/nav-menu.php
@@ -553,4 +553,63 @@ class Test_Nav_Menus extends WP_UnitTestCase {
$this->assertNotInstanceOf( 'WP_Post', get_post( $nav_created_post_ids[0] ) );
$this->assertNotInstanceOf( 'WP_Post', get_post( $nav_created_post_ids[1] ) );
}
+
+
+ /**
diff --git src/wp-includes/nav-menu-template.php src/wp-includes/nav-menu-template.php
index 737d6e6..ea7c22d 100644
--- src/wp-includes/nav-menu-template.php
+++ src/wp-includes/nav-menu-template.php
@@ -394,6 +394,18 @@ function _wp_menu_item_classes_by_context( &$menu_items ) {
) {
$classes[] = 'current-menu-item';
$menu_items[$key]->current = true;
+
+ $_anc_id = (int) $menu_item->db_id;
+
+ while(
+ ( $_anc_id = get_post_meta( $_anc_id, '_menu_item_menu_item_parent', true ) ) &&
+ ! in_array( $_anc_id, $active_ancestor_item_ids, true )
+ ) {
+ $active_ancestor_item_ids[] = $_anc_id;
+ }
+
+ $active_parent_item_ids[] = (int) $menu_item->menu_item_parent;
+
// if the menu item corresponds to the currently-requested URL
} elseif ( 'custom' == $menu_item->object && isset( $_SERVER['HTTP_HOST'] ) ) {
$_root_relative_current = untrailingslashit( $_SERVER['REQUEST_URI'] );
// if the menu item corresponds to the currently-requested URL
} elseif ( 'custom' == $menu_item->object && isset( $_SERVER['HTTP_HOST'] ) ) {
$_root_relative_current = untrailingslashit( $_SERVER['REQUEST_URI'] );
diff --git tests/phpunit/tests/post/nav-menu.php tests/phpunit/tests/post/nav-menu.php
index c6a028c..d0496a1 100644
--- tests/phpunit/tests/post/nav-menu.php
+++ tests/phpunit/tests/post/nav-menu.php
@@ -553,4 +553,63 @@ class Test_Nav_Menus extends WP_UnitTestCase {
$this->assertNotInstanceOf( 'WP_Post', get_post( $nav_created_post_ids[0] ) );
$this->assertNotInstanceOf( 'WP_Post', get_post( $nav_created_post_ids[1] ) );
}
+
+
+ /**
+ * @ticket 39800
+ */
+ function test_parent_ancestor_for_post_archive() {
+
+ register_post_type( 'books', array( 'label' => 'Books', 'public' => true, 'has_archive' => true ) );
+
+ $first_page_id = self::factory()->post->create( array( 'post_type' => 'page', 'post_title' => 'Top Level Page') );
+ $second_page_id = self::factory()->post->create( array( 'post_type' => 'page', 'post_title' => 'Second Level Page') );
+
+
+ $first_menu_id = wp_update_nav_menu_item( $this->menu_id, 0, array(
+ 'menu-item-type' => 'post_type',
+ 'menu-item-object' => 'page',
+ 'menu-item-object-id' => $first_page_id,
+ 'menu-item-status' => 'publish',
+ ));
+
+ $second_menu_id = wp_update_nav_menu_item( $this->menu_id, 0, array(
+ 'menu-item-type' => 'post_type',
+ 'menu-item-object' => 'page',
+ 'menu-item-object-id' => $second_page_id,
+ 'menu-item-status' => 'publish',
+ 'menu-item-parent-id' => $first_menu_id
+ ));
+
+ wp_update_nav_menu_item( $this->menu_id, 0, array(
+ 'menu-item-type' => 'post_type_archive',
+ 'menu-item-object' => 'books',
+ 'menu-item-status' => 'publish',
+ 'menu-item-parent-id' => $second_menu_id
+ ));
+
+ $this->go_to( get_post_type_archive_link( 'books') );
+
+ $menu_items = wp_get_nav_menu_items( $this->menu_id );
+ _wp_menu_item_classes_by_context( $menu_items );
+
+ $top_page_menu_item = $menu_items[0];
+ $secondary_page_menu_item = $menu_items[1];
+ $post_archive_menu_item = $menu_items[2];
+
+ $this->assertFalse( $top_page_menu_item->current_item_parent );
+ $this->assertTrue( $top_page_menu_item->current_item_ancestor );
+ $this->assertContains( 'current-menu-ancestor', $top_page_menu_item->classes );
+
+ $this->assertTrue( $secondary_page_menu_item->current_item_parent );
+ $this->assertTrue( $secondary_page_menu_item->current_item_ancestor );
+ $this->assertContains( 'current-menu-parent', $secondary_page_menu_item->classes );
+ $this->assertContains( 'current-menu-ancestor', $secondary_page_menu_item->classes );
+
+ $this->assertFalse( $post_archive_menu_item->current_item_parent );
+ $this->assertFalse( $post_archive_menu_item->current_item_ancestor );
+
+ $this->assertNotContains( 'current-menu-parent', $post_archive_menu_item->classes );
+ $this->assertNotContains( 'current-menu-ancestor', $post_archive_menu_item->classes );
+ }
}
(END)
I had the same experience from:
$ git checkout master -b doc-42505
... edit some src file
$ git commit -am "Fix typo and variable formatting in the inline description of wp_add_inline_script()."
... edit some src file
$ git commit -am "Fix typo and variable formatting in the inline description of wp_add_inline_style()."
$ grunt upload_patch:42505
This process uploads empty diff file on trac:
https://core.trac.wordpress.org/attachment/ticket/42505/42505.diff
Also tested
$ git diff master --no-prefix > 42505.diff
and then again:
$ grunt upload_patch:42505
but that also uploaded an empty 42505.2.diff on trac.
So ended doing a manual override for 42505.2.diff on trac
https://core.trac.wordpress.org/attachment/ticket/42505/42505.2.diff
@birgire Your issue is actually different, and your issue is caused by the fact you have ran git commit, after running git commit your Git repo will be in a "clean" state, so when you run git diff there will be no differences to create a diff/patch file.
Instead try this:
$ git checkout master -b doc-42505
... edit some src file
$ grunt upload_patch:42505
Now run git diff you should see that there are differences available to create a patch or upload via grunt upload
Thanks @ntwb for the clarification, it worked.
I was trying out this tool for the first time :-)
Tested it on another patch that was uploaded successfully:
https://core.trac.wordpress.org/attachment/ticket/42505/42505.3.diff
So I guess upload_patch is better suited for small patches, since it doesn't like commits?
ps: it would be nice if it didn't upload empty patches, with a notice/warning to the user. I might look into that later.
@birgire The tool currently works as expected in that "It uploads a diff/patch", if you have run git commit then you have "committed" the code to your checked out repo and there is no longer any diff/patch available to upload.
upload_patch can handle quite large diffs/patches, and diff/patches are quite different to commits
@ntwb I was more thinking about the coding workflow, how one could best use the tool and how to use it when writing e.g. a possible long unit tests files. It looks like we are not supposed to commit any changes to the checked out local branch, at least with upload_patch. Working for a long time on a patch and never commit anything locally before it's ready to be uploaded, sounds challenging :-)
It looks like we are not supposed to commit any changes to the checked out local branch.
Correct.
Working for a long time on a patch and never commit anything locally before it's ready to be uploaded, sounds challenging :-)
In this scenario, you might want to consider creating a branch of of master you can then commit back to and create a diff by comparing your branch to master. You could also maintain your own fork here on GiHub and push and pull to branches on that yourself.
@ntwb thanks for the suggestions, forking it would also have the benefit of running Travis for the patches.