Code Monkey home page Code Monkey logo

Comments (4)

binsee avatar binsee commented on September 4, 2024

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:

  1. Filter out the repeated 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.
  2. Submit pr to git and pass -u and branch parameters to pre-push.

from git-scripts.

huan avatar huan commented on September 4, 2024

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.

from git-scripts.

binsee avatar binsee commented on September 4, 2024

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:

  <local ref> SP <local object name> SP <remote ref> SP <remote object name> LF

For instance, if the command +git push origin master:foreign+ were run the
hook would receive a line like the following:

  refs/heads/master 67890 refs/heads/foreign 12345

although the full object name would be supplied.  If the foreign ref does not
yet exist the `<remote object name>` will be the all-zeroes object name.  If a
ref is to be deleted, the `<local ref>` will be supplied as `(delete)` and the
`<local object name>` will be the all-zeroes object name.  If the local commit
was specified by something other than a name which could be expanded (such as
`HEAD~`, or an object name) it will be supplied as it was originally given.

If this hook exits with a non-zero status, `git push` will abort without
pushing anything.  Information about why the push is rejected may be sent
to the user by writing to standard error.

I haven't confirmed which version of git this feature is from, and I hope it can be used as soon as possible.

from git-scripts.

binsee avatar binsee commented on September 4, 2024

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);
  • test:
> git push origin test
args: ["origin","[email protected]: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.

from git-scripts.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.