Skip to content

Commit

Permalink
fix fast-forwarding, test --rebase 0
Browse files Browse the repository at this point in the history
  • Loading branch information
ds300 committed Jul 19, 2023
1 parent e653491 commit c26a1ae
Show file tree
Hide file tree
Showing 16 changed files with 665 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ index 5aa41be..5ee751b 100644
* To Public License, Version 2, as published by Sam Hocevar. See
* http://www.wtfpl.net/ for more details. */
-'use world';
+'goodye world';
+'goodbye world';
module.exports = leftPad;

var cache = [
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`Test rebase-insert: 00: Rebase to the second patch 1`] = `
"SNAPSHOT: Rebase to the second patch
patch-package 0.0.0
Un-applied patch file left-pad+1.3.0+003+goodbye.patch
Un-applied left-pad+1.3.0+003+goodbye.patch
Make any changes you need inside node_modules/left-pad
Expand Down Expand Up @@ -82,7 +82,7 @@ exports[`Test rebase-insert: 03: the state file should show three patches applie
},
{
\\"didApply\\": true,
\\"patchContentHash\\": \\"a0e432bbacdaaf527665fdc224772280cd69e994db738b2c6ac422bc16eda53e\\",
\\"patchContentHash\\": \\"c9063ed6ae00867ee243fa71590c369ce0bb699f3a63a10df86d3ec988782715\\",
\\"patchFilename\\": \\"left-pad+1.3.0+004+goodbye.patch\\"
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ index 5aa41be..5ee751b 100644
* To Public License, Version 2, as published by Sam Hocevar. See
* http://www.wtfpl.net/ for more details. */
-'use world';
+'goodye world';
+'goodbye world';
module.exports = leftPad;

var cache = [
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ exports[`Test rebase-update: 01: the state file should show three patches applie
},
{
\\"didApply\\": true,
\\"patchContentHash\\": \\"a0e432bbacdaaf527665fdc224772280cd69e994db738b2c6ac422bc16eda53e\\",
\\"patchContentHash\\": \\"c9063ed6ae00867ee243fa71590c369ce0bb699f3a63a10df86d3ec988782715\\",
\\"patchFilename\\": \\"left-pad+1.3.0+003+goodbye.patch\\"
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ index 5aa41be..5ee751b 100644
* To Public License, Version 2, as published by Sam Hocevar. See
* http://www.wtfpl.net/ for more details. */
-'use world';
+'goodye world';
+'goodbye world';
module.exports = leftPad;

var cache = [
164 changes: 164 additions & 0 deletions integration-tests/rebase-zero/__snapshots__/rebase-zero.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Test rebase-zero: 00: rebase to zero 1`] = `
"SNAPSHOT: rebase to zero
patch-package 0.0.0
Un-applied left-pad+1.3.0+003+goodbye.patch
Un-applied left-pad+1.3.0+002+world.patch
Un-applied left-pad+1.3.0+001+hello.patch
Make any changes you need inside node_modules/left-pad
When you are done, run
patch-package left-pad --append 'MyChangeDescription'
to insert a new patch file.
END SNAPSHOT"
`;

exports[`Test rebase-zero: 01: it creates a new patch at the start and renames all the other patches, applying them 1`] = `
"SNAPSHOT: it creates a new patch at the start and renames all the other patches, applying them
patch-package 0.0.0
β€’ Creating temporary folder
β€’ Installing left-pad@1.3.0 with npm
β€’ Diffing your files with clean files
βœ” Created file patches/left-pad+1.3.0+001+WhileOne.patch
Renaming left-pad+1.3.0+001+hello.patch to left-pad+1.3.0+002+hello.patch
Renaming left-pad+1.3.0+002+world.patch to left-pad+1.3.0+003+world.patch
Renaming left-pad+1.3.0+003+goodbye.patch to left-pad+1.3.0+004+goodbye.patch
Fast forwarding...
βœ” left-pad+1.3.0+002+hello.patch
βœ” left-pad+1.3.0+003+world.patch
βœ” left-pad+1.3.0+004+goodbye.patch
left-pad+1.3.0+001+WhileOne.patch
left-pad+1.3.0+002+hello.patch
left-pad+1.3.0+003+world.patch
left-pad+1.3.0+004+goodbye.patch
the state file
{
\\"isRebasing\\": false,
\\"patches\\": [
{
\\"didApply\\": true,
\\"patchContentHash\\": \\"dfc6e6951dc7d5bf2e1768a353933c73ba6bccd76c7927d28384107f3be2e8eb\\",
\\"patchFilename\\": \\"left-pad+1.3.0+001+WhileOne.patch\\"
},
{
\\"didApply\\": true,
\\"patchContentHash\\": \\"404c604ed830db6a0605f86cb9165ced136848f70986b23bf877bcf38968c1c9\\",
\\"patchFilename\\": \\"left-pad+1.3.0+002+hello.patch\\"
},
{
\\"didApply\\": true,
\\"patchContentHash\\": \\"f2859c7193de8d9578bdde7e226de516adc8d972d6e76997cbe1f41b1a535359\\",
\\"patchFilename\\": \\"left-pad+1.3.0+003+world.patch\\"
},
{
\\"didApply\\": true,
\\"patchContentHash\\": \\"c9063ed6ae00867ee243fa71590c369ce0bb699f3a63a10df86d3ec988782715\\",
\\"patchFilename\\": \\"left-pad+1.3.0+004+goodbye.patch\\"
}
],
\\"version\\": 1
}the js file
/* This program is free software. It comes without any warranty, to
* the extent permitted by applicable law. You can redistribute it
* and/or modify it under the terms of the Do What The Fuck You Want
* To Public License, Version 2, as published by Sam Hocevar. See
* http://www.wtfpl.net/ for more details. */
'goodbye world';
module.exports = leftPad;
var cache = [
'',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' '
];
function leftPad (str, len, ch) {
// convert \`str\` to a \`string\`
str = str + '';
// \`len\` is the \`pad\`'s length now
len = len - str.length;
// doesn't need to pad
if (len <= 0) return str;
// \`ch\` defaults to \`' '\`
if (!ch && ch !== 0) ch = ' ';
// convert \`ch\` to a \`string\` cuz it could be a number
ch = ch + '';
// cache common use cases
if (ch === ' ' && len < 10) return cache[len] + str;
// \`pad\` starts with an empty string
var pad = '';
// loop
while (1) {
// add \`ch\` to \`pad\` if \`len\` is odd
if (len & 1) pad += ch;
// divide \`len\` by 2, ditch the remainder
len >>= 1;
// \\"double\\" the \`ch\` so this operation count grows logarithmically on \`len\`
// each time \`ch\` is \\"doubled\\", the \`len\` would need to be \\"doubled\\" too
// similar to finding a value in binary search tree, hence O(log(n))
if (len) ch += ch;
// \`len\` is 0, exit the loop
else break;
}
// pad \`str\`!
return pad + str;
}
END SNAPSHOT"
`;

exports[`Test rebase-zero: 02: rebase to zero again 1`] = `
"SNAPSHOT: rebase to zero again
patch-package 0.0.0
Un-applied left-pad+1.3.0+004+goodbye.patch
Un-applied left-pad+1.3.0+003+world.patch
Un-applied left-pad+1.3.0+002+hello.patch
Un-applied left-pad+1.3.0+001+WhileOne.patch
Make any changes you need inside node_modules/left-pad
When you are done, run
patch-package left-pad --append 'MyChangeDescription'
to insert a new patch file.
END SNAPSHOT"
`;

exports[`Test rebase-zero: 03: it creates a new patch at the start called 'initial' if you dont do --append 1`] = `
"SNAPSHOT: it creates a new patch at the start called 'initial' if you dont do --append
patch-package 0.0.0
β€’ Creating temporary folder
β€’ Installing left-pad@1.3.0 with npm
β€’ Diffing your files with clean files
βœ” Created file patches/left-pad+1.3.0+001+initial.patch
Renaming left-pad+1.3.0+001+WhileOne.patch to left-pad+1.3.0+002+WhileOne.patch
Renaming left-pad+1.3.0+002+hello.patch to left-pad+1.3.0+003+hello.patch
Renaming left-pad+1.3.0+003+world.patch to left-pad+1.3.0+004+world.patch
Renaming left-pad+1.3.0+004+goodbye.patch to left-pad+1.3.0+005+goodbye.patch
Fast forwarding...
βœ” left-pad+1.3.0+002+WhileOne.patch
βœ” left-pad+1.3.0+003+hello.patch
βœ” left-pad+1.3.0+004+world.patch
βœ” left-pad+1.3.0+005+goodbye.patch
left-pad+1.3.0+001+initial.patch
left-pad+1.3.0+002+WhileOne.patch
left-pad+1.3.0+003+hello.patch
left-pad+1.3.0+004+world.patch
left-pad+1.3.0+005+goodbye.patch
END SNAPSHOT"
`;
Loading

0 comments on commit c26a1ae

Please sign in to comment.