Created
October 4, 2022 19:27
-
-
Save fricci/ed75f459c181c436a246bce55ea58d01 to your computer and use it in GitHub Desktop.
Checkout, commit and push to remote git repository
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import * as fs from 'fs'; | |
| import * as http from 'isomorphic-git/http/node/index.cjs'; | |
| import git from 'isomorphic-git'; | |
| import * as uuid from 'uuid'; | |
| const repo = 'https://github.com/fricci/git_test_repo.git'; | |
| const target = '/Users/fczina/Projects/git_sandbox/test' | |
| async function clone() { | |
| await git.clone({ | |
| fs, | |
| http, | |
| dir: target, | |
| url: repo, | |
| ref: 'main', | |
| depth: 1 | |
| }); | |
| } | |
| async function writeTestDataToFile() { | |
| const testData = uuid.v4(); | |
| fs.appendFileSync(target + '/test.file', '\n' + testData) | |
| } | |
| async function commit() { | |
| await git.add({ fs, dir: target, filepath: '.' }); | |
| await git.commit({ | |
| fs, | |
| dir: target, | |
| author: { | |
| name: 'Ferenc Czina', | |
| email: 'ferenc@czina.me', | |
| }, | |
| message: 'Test commit' | |
| }); | |
| } | |
| async function push() { | |
| await git.push({ | |
| fs, | |
| http, | |
| dir: target, | |
| remote: 'origin', | |
| ref: 'main', | |
| onAuth: () => ({ | |
| username: 'USERNAME', | |
| password: 'PASSWORD' | |
| }), | |
| }); | |
| } | |
| fs.rmSync(target, { recursive: true, force: true }); | |
| await clone(); | |
| await writeTestDataToFile(); | |
| await commit(); | |
| await push(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment