Updated Branches: refs/heads/master 1be586bf2 -> edb206f4e
Add flag to repo-status for diffing 2 local branches. Project: http://git-wip-us.apache.org/repos/asf/cordova-coho/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-coho/commit/edb206f4 Tree: http://git-wip-us.apache.org/repos/asf/cordova-coho/tree/edb206f4 Diff: http://git-wip-us.apache.org/repos/asf/cordova-coho/diff/edb206f4 Branch: refs/heads/master Commit: edb206f4e9923b54e9d762d4fe6117f483cbc9af Parents: 1be586b Author: Andrew Grieve <[email protected]> Authored: Thu Sep 5 16:18:44 2013 -0400 Committer: Andrew Grieve <[email protected]> Committed: Thu Sep 5 16:18:44 2013 -0400 ---------------------------------------------------------------------- coho | 42 +++++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-coho/blob/edb206f4/coho ---------------------------------------------------------------------- diff --git a/coho b/coho index 141e11d..ed78386 100755 --- a/coho +++ b/coho @@ -746,14 +746,22 @@ function repoStatusCommand(argv) { var opt = optimist .options('b', { alias: 'branch', - desc: 'The name of the branch to report on. Can be specified multiple times to specify multiple branches.', + desc: 'The name of the branch to report on. Can be specified multiple times to specify multiple branches. The local version of the branch is compared with the origin\'s version unless --b2 is specified.', default: 'master' - }); + }) + .options('branch2', { + desc: 'The name of the branch to diff against. This is origin/$branch by default.' + }) + .options('diff', { + desc: 'Show a diff of the changes (use --no-diff to disable)', + default: true + }) opt = registerHelpFlag(opt); var argv = opt .usage('Reports what changes exist locally that are not yet pushed.\n' + '\n' + - 'Usage: $0 repo-status -r auto -b master -b 2.9.x') + 'Example usage: $0 repo-status -r auto -b master -b 2.9.x\n' + + 'Example usage: $0 repo-status -r plugins -b dev --branch2 master --no-diff') .argv; if (argv.h) { @@ -761,35 +769,43 @@ function repoStatusCommand(argv) { process.exit(1); } var branches = Array.isArray(argv.b) ? argv.b : [argv.b]; + var branches2 = Array.isArray(argv.branch2) ? argv.branch2 : [argv.branch2]; var repos = computeReposFromFlag(argv.r); + if (branches.length != branches2.length) { + fatal('Must specify the same number of --branch and --branch2 flags'); + } + var logs = ''; var diffs = ''; forEachRepo(repos, function(repo) { // Determine remote name. updateRepos([repo], [], true); - branches.forEach(function(branchName) { + branches.forEach(function(branchName, i) { if (!localBranchExists(branchName)) { return; } - gitCheckout(branchName); - var targetBranch = remoteBranchExists(repo, branchName) ? branchName : 'master'; - var changes = execHelper('git log --oneline ' + repo.remoteName + '/' + targetBranch + '..' + branchName, true); + var targetBranch = branches2[i] || (remoteBranchExists(repo, branchName) ? repo.remoteName + '/' + branchName : 'master'); + var changes = execHelper('git log --oneline ' + targetBranch + '..' + branchName, true); if (changes) { - logs += repo.repoName + ' on branch ' + branchName + ': Local commits exist.\n'; + logs += repo.repoName + ' on branch ' + branchName + ' (vs ' + targetBranch + '): Commits exist.\n'; logs += changes + '\n'; - diffs += 'Diff for for ' + repo.repoName + ' on branch ' + branchName + ' (truncated):\n'; - diffs += execHelper('git diff ' + repo.remoteName + '/' + targetBranch + '..' + branchName, true).split('\n').slice(0, 30).join('\n'); - diffs += '\n\n'; + if (argv.diff) { + diffs += 'Diff (truncated) for ' + repo.repoName + ' on branch ' + branchName + ' (vs ' + targetBranch + '):\n'; + diffs += execHelper('git diff ' + targetBranch + '..' + branchName, true).split('\n').slice(0, 30).join('\n'); + diffs += '\n\n'; + } } else { - logs += repo.repoName + ' on branch ' + branchName + ': No local commits\n'; + logs += repo.repoName + ' on branch ' + branchName + ' (vs ' + targetBranch + '): No changes\n'; } }); }); print('\n\n'); print(logs); - print(diffs); + if (argv.diff) { + print(diffs); + } } function repoResetCommand(argv) {
