Closed binsee closed 2 years ago
Unable to successfully push new branch.
Outer git push -u
will fail with process.exit(1)
.
The inner git push
cannot get the specified branch name, resulting in the inability to git push remote branch
Running git branch --set-upstream-to
before git push
will not work because the remote does not have this branch.
If the outer process.exit(0)
will cause the push not to be the latest commit.
There are two solutions:
npm version
, that is, the last commit was a modified version, then the version is not modified this time, just process.exit(0)
. If you run npm version
, you need to execute git push
again after the current hook
returns to ensure that the latest commit is pushed.-u
and branch
parameters to pre-push
.The git push
hook definitely should be improved.
Let's try to find some solutions to make it better and we can discuss it in our next community meeting.
I think this problem can be solved by the new feature of git-push hook.
refer to:
pre-push
~~~~~~~~
This hook is called by linkgit:git-push[1] and can be used to prevent a push from taking place. The hook is called with two parameters which provide the name and location of the destination remote, if a named remote is not being used both values will be the same.
Information about what is to be pushed is provided on the hook's standard input with lines of the form:
After testing, this feature has been supported in earlier versions. I tested the two versions installed on the mac, and they all work
git version 2.21.1 (Apple Git-122.3)
git version 2.35.1
pre-push
file:
#!/usr/bin/env node
var path = require('path')
, scripts = require('../../')
, name = path.basename(__filename)
, project = scripts();
const readline = require('readline').createInterface({
input: process.stdin,
output: process.stdout
});
readline.question('', data => {
console.log('input data:', data)
readline.close()
});
console.log('args:',JSON.stringify(process.argv.slice(2)));
setTimeout(() => {
process.exit(-1);
}, 1000);
> git push origin test
args: ["origin","git@github.com:binsee/sidecar.git"]
refs/heads/test 65b8bd5bd8e8c889fb8ec6228cfada35164cc423 refs/heads/test 0000000000000000000000000000000000000000
input data: refs/heads/test 65b8bd5bd8e8c889fb8ec6228cfada35164cc423 refs/heads/test 0000000000000000000000000000000000000000
According to the official documentation, this feature has been supported since at least the 2015 version of git 2.2.3.
So, we can use this feature to improve pre-push
.
https://github.com/wechaty/puppet-xp/commits/main?after=983ec43712db872ba6a92307005e119be5262dd4+69&branch=main