cloning -> pushing new branch not currently supported. Easy fix. #1

Open
bpostlethwaite opened this Issue May 30, 2013 · 2 comments

Projects

None yet

2 participants

@bpostlethwaite

Cloning a repo only pulls the master branch, leaving other branches in the remote as remote branches. When pushing this cloned repo to a git server (like pushover), only the master branch is pushed, even if the commit that triggered the github hook is for a different branch. I made a fix with github-post-receive that does an extra call to comandante to ensure the remote branch specified in the github payload is pushed. Unless I am doing something wrong... anyway, in case I am not, an additional git checkout branch seems to solve the problem.

 var c = run('git', [ 'clone', source ], opts);
        c.on('error', cb);

        c.on('exit', function (code) {
            if (code !== 0) return;
            opts.cwd += '/'+ path.basename(
                payload.repository.url
                    .replace(/^https?:\/\/github\.com\//, '')
            );

          var branch = payload.ref.split('/')[2]

          var args = [ 'checkout', branch ]
          var r = run('git', args, opts)
          r.on('error', cb)

          r.on('exit', function (code) {
            if (code !== 0) return;

            var args = [ 'push', '-f', remote,  branch];

            var p = run('git', args, opts);

            p.on('error', cb);
            p.on('exit', function (code) {
              if (code === 0) cb();
            })
          })
        })
@substack
Owner

Can you send this as a pull request? I would love to merge this fix but I don't want to mess it up by copying it wrong.

@bpostlethwaite

Pull request is ready - simple diff.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment