@@ -515,6 +515,9 @@ exports.computeChanges = co.wrap(function *(repo, index, targetCommit) {
515515 * `repo`. If `conflicts` is non-empty, return a non-empty string desribing
516516 * them. Otherwise, return the empty string.
517517 *
518+ * Half-open the conflicting repos and fetch all commits that are in the
519+ * conflict; this will make it easier for users to resolve the conflict.
520+ *
518521 * @param {NodeGit.Repository } repo
519522 * @param {NodeGit.Index } index
520523 * @param {Object } conflicts from sub name to `Conflict`
@@ -523,11 +526,47 @@ exports.computeChanges = co.wrap(function *(repo, index, targetCommit) {
523526exports . writeConflicts = co . wrap ( function * ( repo , index , conflicts ) {
524527 let errorMessage = "" ;
525528 const names = Object . keys ( conflicts ) . sort ( ) ;
529+ const opener = new Open . Opener ( repo , null ) ;
530+ const fetcher = yield opener . fetcher ( ) ;
526531 for ( let name of names ) {
527- yield ConflictUtil . addConflict ( index , name , conflicts [ name ] ) ;
532+ let conflict = conflicts [ name ] ;
533+ let configured = false ;
534+ try {
535+ // We just want to see if it's configured
536+ const url = yield fetcher . getSubmoduleUrl ( name ) ;
537+ configured = true ;
538+ } catch ( e ) {
539+ // nope, so we cannot fetch
540+ }
541+ if ( configured ) {
542+ const bare = Open . SUB_OPEN_OPTION . FORCE_BARE ;
543+ const subRepo = yield opener . getSubrepo ( name , bare ) ;
544+
545+ for ( const stage of [ conflict . ancestor , conflict . our ,
546+ conflict . their ] ) {
547+ if ( stage !== null ) {
548+ yield fetcher . fetchSha ( subRepo , name , stage . id ) ;
549+ }
550+ }
551+ }
552+ yield ConflictUtil . addConflict ( index , name , conflict ) ;
528553 errorMessage += `\
529- Conflicting entries for submodule ${ colors . red ( name ) }
554+ Conflicting entries for submodule ${ colors . red ( name ) } .
530555` ;
556+ if ( conflict . our !== null && conflict . their !== null ) {
557+ // add-add
558+ const root = repo . workdir ( ) ;
559+ const our = conflict . our . id ;
560+ const their = conflict . their . id ;
561+ errorMessage += `
562+ To choose your version of the ${ name } , use the following magic:
563+ git -C ${ root } update-index --cache-info 160000,${ our } ,${ name }
564+ To choose their version of the ${ name } , use the following magic:
565+ git -C ${ root } update-index --cache-info 160000,${ their } ,${ name }
566+ To compare, try:
567+ git -C ${ root } ${ name } diff ${ their } ${ our }
568+ ` ;
569+ }
531570 }
532571 return errorMessage ;
533572} ) ;
0 commit comments