pre-git icon indicating copy to clipboard operation
pre-git copied to clipboard

Commit-wizard fails for submodules

Open ryan-kimber opened this issue 8 years ago • 7 comments

Commit attempt fails with [Error: Cannot find file ./.git/COMMIT_EDITMSG]

ryan-kimber avatar Mar 20 '16 01:03 ryan-kimber

The error happens in ggit.commitMessage()

Changing commit-message.js to this allows it to work:

var Q = require('q');
  var exists = require('fs').existsSync;
  var fileInfo = require('fs').lstatSync;
  var read = require('fs').readFileSync;
  var filename = './.git/COMMIT_EDITMSG';

  function commitMessage() {
    var commitMsgFile = filename;  
    if(!fileInfo('./.git').isDirectory()) { 
      var unparsedText = "" + read('./.git');
      console.log("ParsedText: " + unparsedText.substring('gitdir: '.length).trim());
      commitMsgFile = unparsedText.substring('gitdir: '.length).trim() + '/COMMIT_EDITMSG';
    }   

    if (!exists(commitMsgFile)) {
        return Q.reject(new Error('Cannot find file ' + commitMsgFile));
    }

    var text = read(commitMsgFile, 'utf8');
    /* jshint -W064 */
    return Q(text);

  }

  module.exports = commitMessage;

It should check if './.git' is a file or a directory. If it's a directory, the existing logic is fine. If it's a file, it should read the property 'gitdir' from the file and use that as the location of '.git'.

ryan-kimber avatar Mar 20 '16 02:03 ryan-kimber

That seems like an excellent pull request candidate :)

Sent from my iPhone

On Mar 19, 2016, at 22:31, Ryan Kimber [email protected] wrote:

The error happens in ggit.commitMessage()

Changing commit-message.js to this allows it to work: ` var Q = require('q'); var exists = require('fs').existsSync; var fileInfo = require('fs').lstatSync; var read = require('fs').readFileSync; var filename = './.git/COMMIT_EDITMSG';

function commitMessage() { var commitMsgFile = filename;

if(!fileInfo('./.git').isDirectory()) { var unparsedText = "" + read('./.git'); console.log("ParsedText: " + unparsedText.substring('gitdir: '.length).trim()); commitMsgFile = unparsedText.substring('gitdir: '.length).trim() + '/COMMIT_EDITMSG'; }

if (!exists(commitMsgFile)) { return Q.reject(new Error('Cannot find file ' + commitMsgFile)); }

var text = read(commitMsgFile, 'utf8'); /* jshint -W064 */ return Q(text);

}

module.exports = commitMessage; `

It should check if './.git' is a file or a directory. If it's a directory, the existing logic is fine. If it's a file, it should read the property 'gitdir' from the file and use that as the location of '.git'.

— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub

bahmutov avatar Mar 20 '16 02:03 bahmutov

Submitted, but I suspect you'll have a number of other locations in the code that should be checking '.git' to see if it's actually a file and not a directory.

A utility function to get the project's Git home would be handy.

ryan-kimber avatar Mar 20 '16 02:03 ryan-kimber

Supporting people submitting pull requests probably isn't what you'd like to be doing, but the CI build seems to be failing, and it doesn't appear to be related to my change.

/home/travis/build/bahmutov/ggit/node_modules/describe-it/describe-it.js:15 var isVar = isVariable(functionSignature); ^

The TravisCI build output is at available here. I'm afraid it's getting pretty late here in Toronto. I'm calling it a night.

ryan-kimber avatar Mar 20 '16 03:03 ryan-kimber

Hi,

I fixed the travis to use Node 4.2.2 (this is because my require hook uses internal code, which changed in latest v4 and v5 node versions)

I also upgraded ggit to latest version to make your folder method available.

bahmutov avatar Mar 21 '16 14:03 bahmutov

Hey @bahmutov, did I need to do something else on this? I've switched off of my pre-git fork to [email protected], but it doesn't seem to pick up the .git config from the parent repository for submodules. Just checking before I dive in further.

ryan-kimber avatar Oct 02 '17 16:10 ryan-kimber

ughhh, not sure why this does not find the right git folder, you can see diagnostic messages using DEBUG=pre-git but I don't have time to work on this, unfortunately.

bahmutov avatar Oct 02 '17 19:10 bahmutov