Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add option to generate config from current checkout: repoman config --fromcwd #12

Merged
merged 4 commits into from

2 participants

Stephen Steneker Cliffano Subagio
Stephen Steneker

Added the config option --fromcwd to generate .repoman.json from the checked out repos in the current working directory:

repoman config --fromcwd

I find this useful to sync working directories which may be of mixed origin or a subset of those available from my GitHub projects. This also provides an easy way to get started with repoman.

Re-running config --fromcwd will regenerate the config (rather than complaining one already exists).

Cliffano Subagio
Owner

Thanks for this Stephen, I've been getting feature request (verbally) around generating config from local repos.

I'll do the merging closer to the weekend.

Cliffano Subagio cliffano merged commit d030eb6 into from
Stephen Steneker

Thanks for merging! Will you be bumping a release soon? :)

Cliffano Subagio
Owner

Heya Stephen,

I did some refactorings on my local repo (add unit tests, improve coverage, rename --fromcwd to --local). Almost done, but then was so busy last week I didn't have the time to continue.

I'll ping you after I push to master, in case I missed any obvious use case scenarios.

Cliffano Subagio
Owner

@stennie Do you mind trying master and let me know if it works for you? https://github.com/cliffano/repoman/commits/master

Stephen Steneker

Thanks @cliffano: repoman config --local appears to be working fine in master (githash 77a42eb).

Cliffano Subagio
Owner

Published in v0.0.16 .

There are edge cases like svn repo that was migrated to git, but I guess that's for future improvements.
FYI: slightly improve error message on svn-info jtrussell/node-svn-info#1

Thanks again @stennie

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
2  CHANGELOG.md
View
@@ -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
4 README.md
View
@@ -42,6 +42,10 @@ Create .repoman.json containing GitHub projects of multiple users and organisati
repoman --github-user cliffano --github-org jenkinsci,github config
+Create .repoman.json configuration file based on repos in your current working directory:
+
+ repoman config --fromcwd
+
Initialise local repositories:
repoman init
3  conf/commands.json
View
@@ -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",
2  lib/cli.js
View
@@ -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);
}
57 lib/localrepo.js
View
@@ -0,0 +1,57 @@
+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");
+ var origin;
+
+ if (fs.existsSync(gitrepo)) {
+ var gitconfig = ini.parse(fs.readFileSync(gitrepo, 'utf-8'));
+ 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);
+ 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;
7 lib/repoman.js
View
@@ -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);
4 package.json
View
@@ -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",
Something went wrong with that request. Please try again.