pre-git
pre-git copied to clipboard
Commit-wizard fails for submodules
Commit attempt fails with [Error: Cannot find file ./.git/COMMIT_EDITMSG]
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'.
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
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.
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.
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.
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.
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.