N
N
newaitix2018-04-29 21:23:15
JavaScript
newaitix, 2018-04-29 21:23:15

Nodejs script to upload to the repository.?

I wondered: - Is it possible to create a script that will automatically commit files to github?
- Probably yes, and probably it needs to be done through the execution of commands in git bash. I answered myself and rummaged through the Internet.
Created a repository manually Manually made a couple of commits.
Then he prescribed

var exec = require('child_process').exec;
exec('git status',{cwd:'./public/'},function(error,stdout,stderr){console.log(stdout);});

And when I saw the answer I was very happy
On branch master
Your branch is up to date with 'origin/master'.

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        modified:   library.js
        modified:   library.min.js

Then another line
exec('git add .',{cwd:'./public/'},function(error,stdout,stderr){console.log(stdout);});

And another answer
On branch master
Your branch is up to date with 'origin/master'.

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        modified:   library.js
        modified:   library.min.js

Then
exec('git commit -m ""',{cwd:'./public/'},function(error,stdout,stderr){console.log(stdout);});

And further
exec('git push -u origin master',{cwd:'./public/'},function(error,stdout,stderr){console.log(stdout);});

But received in response only the end of the answer
Branch 'master' set up to track remote branch 'master' from 'origin'.

I go into the repository and there everything is as it was, everything remains the same.
How can I make the script upload the necessary files to the git repository itself?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
newaitix, 2018-04-29
@newaitix

Decided so

var exec = require('child_process').exec;
exec('git init',{cwd:'./public/'},function(error,stdout,stderr){
  exec('git status',{cwd:'./public/'},function(error,stdout,stderr){
    exec('git add .',{cwd:'./public/'},function(error,stdout,stderr){
      exec('git commit -m "sadsdasd"',{cwd:'./public/'},function(error,stdout,stderr){
        exec('git push origin master:username,{cwd:'./public/'},function(error,stdout,stderr){
        });
      });
    });
  });
});

Instead of username, you need to specify the name of the wizard.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question