How to 'edit' a diff patch properly during ember-cli update?

The last step to upgrade an ember-cli app, after you type ember init, I found a new option edit that allow you to edit a diff patch directly, “Great!” I thought at first…until I encounter an error message again and again, it says:

Patch was not cleanly applied. Please choose another action.

Okay, copy that, but how am I suppose to patch it cleanly? For example, I started with a patch file like this:

Index: /Users/nightire/code/dearann/client/app/app.js
===================================================================
--- /Users/nightire/code/dearann/client/app/app.js
+++ /Users/nightire/code/dearann/client/app/app.js 
@@ -1,17 +1,16 @@
 import Ember from 'ember';
 import Resolver from 'ember/resolver';
 import loadInitializers from 'ember/load-initializers';
+import config from './config/environment';

 Ember.MODEL_FACTORY_INJECTIONS = true;

 var App = Ember.Application.extend({
+  modulePrefix: config.modulePrefix,
+  podModulePrefix: config.podModulePrefix,
+  Resolver: Resolver
-  modulePrefix: 'dearann', // TODO: loaded via config
-  Resolver: Resolver,
-  ready: function () {
-    moment.locale('zh-cn');
-  }
 });

+loadInitializers(App, config.modulePrefix);
-loadInitializers(App, 'dearann');

 export default App;

and change to this (use vim) :

Index: /Users/nightire/code/dearann/client/app/app.js
===================================================================
--- /Users/nightire/code/dearann/client/app/app.js
+++ /Users/nightire/code/dearann/client/app/app.js 
@@ -1,17 +1,16 @@
import Ember from 'ember';
import Resolver from 'ember/resolver';
import config from './config/environment';
import loadInitializers from 'ember/load-initializers';

Ember.MODEL_FACTORY_INJECTIONS = true;

var App = Ember.Application.extend({
  Resolver: Resolver,
  modulePrefix: config.modulePrefix,
  podModulePrefix: config.podModulePrefix,
  ready: function () {
    moment.locale('zh-cn');
  }
});

loadInitializers(App, config.modulePrefix);

export default App;

Save and exit, then I think it should be work enough, but still “was not cleanly” even after I delete the first five lines as well, that drives me crazy!

Is there anyone who can manage this correctly? I would appreciate it someone can show me a screencast or short GIF demonstration, thanks in advance.

I think this is what you want.

Index: /Users/nightire/code/dearann/client/app/app.js
===================================================================
--- /Users/nightire/code/dearann/client/app/app.js
+++ /Users/nightire/code/dearann/client/app/app.js 
@@ -1,17 +1,19 @@
 import Ember from 'ember';
 import Resolver from 'ember/resolver';
 import loadInitializers from 'ember/load-initializers';
+import config from './config/environment';

 Ember.MODEL_FACTORY_INJECTIONS = true;

 var App = Ember.Application.extend({
+  modulePrefix: config.modulePrefix,
+  podModulePrefix: config.podModulePrefix,
+  Resolver: Resolver,
-  modulePrefix: 'dearann', // TODO: loaded via config
-  Resolver: Resolver,
   ready: function () {
     moment.locale('zh-cn');
   }
 });

+loadInitializers(App, config.modulePrefix);
-loadInitializers(App, 'dearann');

 export default App;

The header @@ -1,17 +1,16 @@ is key. This represents @@ from-range to-range @@.

If you don’t want a line removed, then replace - with a blank space ' ' . Make sure the indentation lines up. For each substitution, add 1 to the second number in the to-range. In this case, I’ve kept the ready function, so

@@ -1,17 +1,16 @@

becomes

@@ -1,17 +1,19 @@.

Note that I also added a comma to the end of + Resolver: Resolver.

If you don’t want to include a + line, then just delete the line. Subtract 1 from the second number in the to-range for each deleted line.

HT @joaquin_win for Joaquín Windmüller — Selectively select changes to commit with git (or Imma edit your hunk).

4 Likes

Thank you very much, now I understand it at all.

1 Like