cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From shaz...@apache.org
Subject cordova-coho git commit: Added --pull-only option to merge-pr command
Date Thu, 10 Aug 2017 23:30:31 GMT
Repository: cordova-coho
Updated Branches:
  refs/heads/master 18bca8748 -> 9691db78c


Added --pull-only option to merge-pr command

For easy review of PRs to test locally, without applying to master branch.


Project: http://git-wip-us.apache.org/repos/asf/cordova-coho/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-coho/commit/9691db78
Tree: http://git-wip-us.apache.org/repos/asf/cordova-coho/tree/9691db78
Diff: http://git-wip-us.apache.org/repos/asf/cordova-coho/diff/9691db78

Branch: refs/heads/master
Commit: 9691db78c6b2e7f3eabd6ee965d91b67cc36f003
Parents: 18bca87
Author: Shazron Abdullah <shazron@gmail.com>
Authored: Thu Aug 10 16:30:22 2017 -0700
Committer: Shazron Abdullah <shazron@gmail.com>
Committed: Thu Aug 10 16:30:22 2017 -0700

----------------------------------------------------------------------
 src/merge-pr.js | 108 ++++++++++++++++++++++++++++++---------------------
 1 file changed, 63 insertions(+), 45 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-coho/blob/9691db78/src/merge-pr.js
----------------------------------------------------------------------
diff --git a/src/merge-pr.js b/src/merge-pr.js
index 0fd7212..81a31a2 100644
--- a/src/merge-pr.js
+++ b/src/merge-pr.js
@@ -49,54 +49,72 @@ module.exports = function *(argv) {
         process.exit(1);
    }
    
+   var pull_only = argv['pull-only'];
    var localBranch = 'pr/' + argv.pr;
    var currentRepo = repoutil.getRepoById(repoutil.resolveCwdRepo());
    var remote = 'https://github.com/apache/' + currentRepo.repoName;
    var origin = 'https://git-wip-us.apache.org/repos/asf/' + currentRepo.repoName;
-   yield gitutil.stashAndPop('', function*() {
-       var commitMessage
-       yield executil.execHelper(executil.ARGS('git checkout master'));
-    
-       yield executil.execHelper(['git', 'pull', origin, 'master']);
-       var commit = yield executil.execHelper(executil.ARGS('git rev-parse HEAD'), /*silent*/
true);
-       yield executil.execHelper(['git', 'fetch', /*force update*/ '-fu', remote,
-            'refs/pull/' + argv.pr + '/head:' + localBranch]);
-       try {
-            yield executil.execHelper(executil.ARGS('git merge --ff-only ' + localBranch),
-                /*silent*/ true, /*allowError*/ true);
-                commitMessage = yield executil.execHelper(executil.ARGS('git log --format=%B
-n 1 HEAD'), /*silent*/ true);
-               yield executil.execHelper(['git', 'commit', '--amend', '-m', 
-                    commitMessage + '\n\n This closes #' + argv.pr]);
-       } catch (e) {   
-           if (e.message.indexOf('fatal: Not possible to fast-forward, aborting.') > 0)
{
-               // Let's try to rebase
-               yield executil.execHelper(executil.ARGS('git checkout ' + localBranch));
-               yield executil.execHelper(['git', 'pull', '--rebase', origin, 'master']);
-               yield executil.execHelper(executil.ARGS('git checkout master'));
-               yield executil.execHelper(executil.ARGS('git merge --ff-only ' + localBranch));
-               commitMessage = yield executil.execHelper(executil.ARGS('git log --format=%B
-n 1 HEAD'), /*silent*/ true);
-               yield executil.execHelper(['git', 'commit', '--amend', '-m', 
-                    commitMessage + '\n\n This closes #' + argv.pr]);
-           } else {
-               throw e;
-           }
-       }
-      console.log(); 
-      var commits =  yield executil.execHelper(['git', 'log',
-            '--graph',
-            '--pretty=format:%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold
blue)<%an>%Creset',
-            '--abbrev-commit',
-            '--stat',
-            commit + '..HEAD'], /*silent*/ true);
+   if (currentRepo.github) {
+       origin = remote;
+   }
+
+    function* mergePr(){
+        var commitMessage;
+        yield executil.execHelper(executil.ARGS('git checkout master'));
+
+        yield executil.execHelper(['git', 'pull', origin, 'master']);
+        var commit = yield executil.execHelper(executil.ARGS('git rev-parse HEAD'), /*silent*/
true);
+        yield executil.execHelper(['git', 'fetch', /*force update*/ '-fu', remote,
+                'refs/pull/' + argv.pr + '/head:' + localBranch]);
+
+        if (!pull_only) {
+            try {
+                yield executil.execHelper(executil.ARGS('git merge --ff-only ' + localBranch),
+                    /*silent*/ true, /*allowError*/ true);
+                    commitMessage = yield executil.execHelper(executil.ARGS('git log --format=%B
-n 1 HEAD'), /*silent*/ true);
+                    yield executil.execHelper(['git', 'commit', '--amend', '-m', 
+                        commitMessage + '\n\n This closes #' + argv.pr]);
+            } catch (e) {   
+                if (e.message.indexOf('fatal: Not possible to fast-forward, aborting.') >
0) {
+                    // Let's try to rebase
+                    yield executil.execHelper(executil.ARGS('git checkout ' + localBranch));
+                    yield executil.execHelper(['git', 'pull', '--rebase', origin, 'master']);
+                    yield executil.execHelper(executil.ARGS('git checkout master'));
+                    yield executil.execHelper(executil.ARGS('git merge --ff-only ' + localBranch));
+                    commitMessage = yield executil.execHelper(executil.ARGS('git log --format=%B
-n 1 HEAD'), /*silent*/ true);
+                    yield executil.execHelper(['git', 'commit', '--amend', '-m', 
+                        commitMessage + '\n\n This closes #' + argv.pr]);
+                } else {
+                    throw e;
+                }
+            }
+            console.log(); 
+            var commits =  yield executil.execHelper(['git', 'log',
+                '--graph',
+                '--pretty=format:%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold
blue)<%an>%Creset',
+                '--abbrev-commit',
+                '--stat',
+                commit + '..HEAD'], /*silent*/ true);
 
-       if (commits) {
-           console.log('---------------');
-           console.log('Commits merged:');
-           console.log('---------------');
-           console.log(commits);
-           console.log(chalk.red.bold('Success! Please test, squash, and rebase to meaningful
commits before pushing to remote master using: git push origin master'));
-       } else {
-           console.log(chalk.red.bold('Nothing to merge - Has this already been merged?'));
-       }
-   });
+            if (commits) {
+                console.log('---------------');
+                console.log('Commits merged:');
+                console.log('---------------');
+                console.log(commits);
+                console.log(chalk.red.bold('Success! Please test, squash, and rebase to meaningful
commits before pushing to remote master using: git push origin master'));
+            } else {
+                console.log(chalk.red.bold('Nothing to merge - Has this already been merged?'));
+            }
+
+        } else {
+            // git checkout localbranch
+            yield executil.execHelper(executil.ARGS('git checkout ' + localBranch));
+        }
+    }
+   
+   if (!pull_only) {
+        yield gitutil.stashAndPop('', mergePr);
+   } else {
+       yield mergePr();
+   }
 };
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


Mime
View raw message