-
Notifications
You must be signed in to change notification settings - Fork 22
Support Git submodules. #50
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -131,30 +131,60 @@ exports.isDir = function (path) { | |
| }; | ||
|
|
||
|
|
||
| // Given a path, determine if the path is a regular file | ||
| exports.isFile = function (path) { | ||
|
|
||
| try { | ||
| var stat = Fs.statSync(path); | ||
| return stat.isFile(); | ||
| } | ||
| catch (e) { | ||
| return false; | ||
| } | ||
| }; | ||
|
|
||
|
|
||
| // Given a starting directory, find the root of a git repository. | ||
| // In this case, the root is defined as the first directory that contains | ||
| // a directory named ".git" | ||
| // | ||
| // Returns a string if found, otherwise undefined | ||
| // Returns undefined if not found, otherwise an object containing: | ||
| // root: path to the root of the Git repo | ||
| // - this is the first directory (traversing upward) that contains a ".git" | ||
| // directory (most cases) or a ".git" file (submodule inside another Git repo) | ||
| // gitDir: path to the ".git"-ish directory of the Git repo | ||
| // - in most cases, this is the ".git" directory inside the Git repo root | ||
| // - in the submodule case, this is the directory pointed to by the ".git" file | ||
| exports.findGitRoot = function (start) { | ||
|
|
||
| start = start || Path.dirname(internals.findParent(module).filename); | ||
| var root; | ||
| var gitDir = Path.join(start, '.git'); | ||
|
|
||
| if (exports.isDir(Path.join(start, '.git'))) { | ||
| if (exports.isDir(gitDir)) { | ||
| root = start; | ||
| } | ||
| else if (exports.isFile(gitDir)) { | ||
| // This is a git submodule inside another git repo! | ||
| // Resolve the path to its ".git"-ish directory. | ||
| root = start; | ||
| gitFile = Fs.readFileSync(gitDir, { encoding: 'utf8' }); | ||
| matches = gitFile.split('\n')[0].match(/^gitdir: (.+)$/); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. likewise need a |
||
| if (!matches) { | ||
| return internals.throwWarn('Unable to find a .git directory for this (submodule) project'); | ||
| } | ||
| // This path is relative to the root of the Git repo. | ||
| gitDir = Path.join(root, matches[1]); | ||
| } | ||
| /* $lab:coverage:off$ */ | ||
| // Coverage disabled here due to false positive on else if, since we have to trap the throwWarn method | ||
| else if (Path.dirname(start) !== start) { | ||
| root = exports.findGitRoot(Path.dirname(start)); | ||
| return exports.findGitRoot(Path.dirname(start)); | ||
| } | ||
| else { | ||
| return internals.throwWarn('Unable to find a .git directory for this project'); | ||
| } | ||
| /* $lab:coverage:on$ */ | ||
|
|
||
| return root; | ||
| return { root: root, gitDir: gitDir }; | ||
| }; | ||
|
|
||
|
|
||
|
|
@@ -191,7 +221,10 @@ exports.findProjectRoot = function (start) { | |
| // Returns an array | ||
| exports.findProjects = function (start, depth) { | ||
|
|
||
| start = start || exports.findGitRoot(internals.findParent(module).filename); | ||
| if (!start) { | ||
| gitRoot = exports.findGitRoot(internals.findParent(module).filename); | ||
| start = gitRoot ? gitRoot.root : undefined; | ||
| } | ||
| depth = depth || 0; | ||
| ++depth; | ||
|
|
||
|
|
@@ -229,8 +262,8 @@ exports.findProjects = function (start, depth) { | |
| exports.installHooks = function (hooks, root) { | ||
|
|
||
| hooks = Array.isArray(hooks) ? hooks : [hooks]; | ||
| var gitRoot = exports.findGitRoot(root); | ||
| var hookRoot = Path.join(gitRoot, '.git', 'hooks'); | ||
| var hookRoot = Path.join(exports.findGitRoot(root).gitDir, 'hooks'); | ||
|
|
||
| var source = Path.resolve(__dirname, '..', 'bin', 'validate.sh'); | ||
|
|
||
| if (!exports.isDir(hookRoot)) { | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need a
varhere or this is a global leak