Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Commit-wizard fails for submodules #74

Open
ryan-kimber opened this issue Mar 20, 2016 · 7 comments
Open

Commit-wizard fails for submodules #74

ryan-kimber opened this issue Mar 20, 2016 · 7 comments

Comments

@ryan-kimber
Copy link

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

@ryan-kimber
Copy link
Author

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'.

@bahmutov
Copy link
Owner

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

@ryan-kimber
Copy link
Author

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
Copy link
Author

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.

@bahmutov
Copy link
Owner

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.

@ryan-kimber
Copy link
Author

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.

@bahmutov
Copy link
Owner

bahmutov commented Oct 2, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants