Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add option to generate config from current checkout:

 repoman config --fromcwd
  • Loading branch information...
commit 758125a547f1f7b0ba4676703747501522149d51 1 parent cbd34a0
@stennie stennie authored
View
2  CHANGELOG.md
@@ -1,5 +1,5 @@
### 0.0.16-pre
-*
+* Add option to generate config from current checkout: config --fromcwd [Stephen Steneker](https://github.com/stennie)
### 0.0.15
* Change get command for git to use --rebase
View
3  conf/commands.json
@@ -11,7 +11,8 @@
{ "arg": "--github-auth-user <githubAuthUser>", "desc": "GitHub authentication username" },
{ "arg": "--github-auth-pass <githubAuthPass>", "desc": "GitHub authentication password" },
{ "arg": "--gitorious-url <gitoriousUrl>", "desc": "Gitorious URL" },
- { "arg": "--gitorious-project <gitoriousProject>", "desc": "Comma-separated Gitorious projects" }
+ { "arg": "--gitorious-project <gitoriousProject>", "desc": "Comma-separated Gitorious projects" },
+ { "arg": "--fromcwd", "desc": "Look for checked out repos in current directory" }
],
"examples": [
"repoman --github-user cliffano config",
View
2  lib/cli.js
@@ -19,6 +19,8 @@ function _config(args) {
url: args.gitoriousUrl,
project: args.gitoriousProject
};
+ } else if (args.fromcwd) {
+ opts.localrepos = true;
}
new Repoman().config(opts, bag.exit);
}
View
56 lib/localrepo.js
@@ -0,0 +1,56 @@
+var fs = require('fs'),
+ ini = require('ini'),
+ path = require('path');
+
+/**
+ * class LocalRepo
+ *
+ * @param {Object} repos: repository name and details mapping (schemas/repoman.Schema)
+ * @param {Object} scms: SCM details mapping (schemas/scms.Schema)
+ */
+function LocalRepo(basedir) {
+ this.basedir = basedir || ".";
+}
+
+LocalRepo.prototype.generate = function (cb) {
+ var filelist = fs.readdirSync(this.basedir);
+ var config = {};
+ var err;
+
+ var ignoreme = /^([.]|node_modules)/;
+ filelist.forEach(function (filepath) {
+ if (!filepath.match(ignoreme)) {
+ var fsstat = fs.statSync(filepath);
+ if (fsstat.isDirectory()) {
+ var gitrepo = path.join(filepath,".git", "config");
+ var svnrepo = path.join(filepath,".svn", "entries");
+
+ if (fs.existsSync(gitrepo)) {
+ var gitconfig = ini.parse(fs.readFileSync(gitrepo, 'utf-8'));
+ var origin = gitconfig['remote "origin"']['url'];
+ if (origin) {
+ console.log("GIT repo found in: %s", filepath);
+ config[filepath] = {
+ type: "git",
+ url: origin
+ }
+ }
+
+ } else if (fs.existsSync(svnrepo)) {
+ var svninfo = require('svn-info').sync(filepath);
+ var origin = svninfo['repositoryRoot'];
+ if (origin) {
+ console.log("SVN repo found in: %s", filepath);
+ config[filepath] = {
+ type: "svn",
+ url: origin
+ }
+ }
+ }
+ }
+ }
+ })
+ cb(err, config)
+}
+
+module.exports = LocalRepo;
View
7 lib/repoman.js
@@ -3,6 +3,7 @@ var _ = require('lodash'),
bag = require('bagofcli'),
fs = require('fs'),
fsx = require('fs.extra'),
+ LocalRepo = require('./localrepo'),
GitHub = require('./github'),
Gitorious = require('./gitorious'),
jazz = require('jazz'),
@@ -54,6 +55,12 @@ Repoman.prototype.config = function (opts, cb) {
(opts.gitorious.project) ? opts.gitorious.project.split(',') : [],
_writeConfig);
+ } else if (opts.localrepos) {
+
+ console.log('Creating %s configuration file from checked out repositories in: %s', file, process.cwd());
+ var localrepo = new LocalRepo();
+ localrepo.generate(_writeConfig);
+
} else {
console.log('Creating sample configuration file: %s', file);
fsx.copy(p.join(__dirname, '../examples/' + file), file, cb);
View
4 package.json
@@ -39,9 +39,11 @@
"fs.extra": "~1.2.1",
"github": "~0.1.12",
"gitoriou.js": "~0.0.1",
+ "ini": "~1.1.0",
"jazz": "~0.0.18",
"lodash": "~2.4.1",
- "prompt": "~0.2.12"
+ "prompt": "~0.2.12",
+ "svn-info": "~0.1.2"
},
"devDependencies": {
"buster-node": "~0.7.0",
Please sign in to comment.
Something went wrong with that request. Please try again.