├── .gitignore ├── CODEOWNERS ├── README.md ├── babel.config.js ├── husky.config.js ├── lint-staged.config.js ├── package-lock.json ├── package.json ├── src ├── __tests__ │ ├── exercise-01.test.js │ ├── exercise-02.test.js │ ├── exercise-03.test.js │ ├── exercise-04.test.js │ ├── exercise-05.test.js │ ├── exercise-06.test.js │ ├── exercise-07.test.js │ ├── exercise-08.test.js │ ├── exercise-09.test.js │ ├── exercise-10.test.js │ ├── exercise-11.test.js │ ├── exercise-12.test.js │ └── exercise-13.test.js └── exercises │ ├── .gitkeep │ ├── exercise-01.txt │ ├── exercise-03-a.txt │ └── exercise-03-b.txt └── utils ├── baseRemote.js └── git.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .DS_STORE 3 | -------------------------------------------------------------------------------- /CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @daniassembler -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # git-basics-vscode-pill 2 | 3 | Assembler School Git Basics VSCode Pill 4 | 5 | @daniassembler 6 | -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [ 3 | [ 4 | "@babel/preset-env", 5 | { 6 | targets: { 7 | node: "current", 8 | }, 9 | }, 10 | ], 11 | ], 12 | }; 13 | -------------------------------------------------------------------------------- /husky.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | // hooks: { 3 | // "pre-commit": "lint-staged", 4 | // }, 5 | }; 6 | -------------------------------------------------------------------------------- /lint-staged.config.js: -------------------------------------------------------------------------------- 1 | // https://github.com/okonet/lint-staged 2 | module.exports = { 3 | // "./**/*.{js,json,txt,ts,md,html,css}": () => ["jest --bail --lastCommit"], 4 | }; 5 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "git-basics-vscode-pill", 3 | "version": "1.0.0", 4 | "description": "assembler-school-git-basics-vscode-pill", 5 | "scripts": { 6 | "validate-exercise-01": "jest -t exercise-01", 7 | "validate-exercise-02": "jest -t exercise-02", 8 | "validate-exercise-03-a": "jest -t exercise-03-a", 9 | "validate-exercise-03-b": "jest -t exercise-03-b", 10 | "validate-exercise-04-a": "jest -t exercise-04-a", 11 | "validate-exercise-04-b": "jest -t exercise-04-b", 12 | "validate-exercise-05": "jest -t exercise-05", 13 | "validate-exercise-06": "jest -t exercise-06", 14 | "validate-exercise-07": "jest -t exercise-07", 15 | "validate-exercise-08": "jest -t exercise-08", 16 | "validate-exercise-09": "jest -t exercise-09", 17 | "validate-exercise-10": "jest -t exercise-10", 18 | "validate-exercise-11": "jest -t exercise-11", 19 | "validate-exercise-12": "jest -t exercise-12", 20 | "validate-exercise-13": "jest -t exercise-13" 21 | }, 22 | "keywords": [ 23 | "git", 24 | "basics", 25 | "assemblerschool" 26 | ], 27 | "author": "Daniel Lucaci ", 28 | "license": "MIT", 29 | "dependencies": { 30 | "@types/jest": "^25.2.1", 31 | "git-tools": "^0.3.0", 32 | "jest": "^25.5.2", 33 | "simple-git": "^2.2.0" 34 | }, 35 | "devDependencies": { 36 | "@babel/core": "^7.9.6", 37 | "@babel/preset-env": "^7.9.6", 38 | "babel-jest": "^25.5.1", 39 | "husky": "^4.2.5", 40 | "lint-staged": "^10.2.1" 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/__tests__/exercise-01.test.js: -------------------------------------------------------------------------------- 1 | const git = require("../../utils/git"); 2 | 3 | describe("exercise-01", () => { 4 | test("create a new file and add it to the staging area", async () => { 5 | let status = await git.status(); 6 | 7 | expect(status.created).toHaveLength(1); 8 | expect(status.created).toContain("src/exercises/exercise-01.txt"); 9 | }); 10 | }); 11 | -------------------------------------------------------------------------------- /src/__tests__/exercise-02.test.js: -------------------------------------------------------------------------------- 1 | const git = require("../../utils/git"); 2 | 3 | describe("exercise-02", () => { 4 | test("create a new commit with the new file", async () => { 5 | let status = await git.status(); 6 | 7 | let raw = await git.raw([ 8 | "log", 9 | "--oneline", 10 | "-n", 11 | "1", 12 | "--grep", 13 | "exercise-02", 14 | ]); 15 | 16 | expect(status.created).not.toContain("src/exercises/exercise-01.txt"); 17 | expect(raw).toMatch(/commit exercise-02/); 18 | }); 19 | }); 20 | -------------------------------------------------------------------------------- /src/__tests__/exercise-03.test.js: -------------------------------------------------------------------------------- 1 | const git = require("../../utils/git"); 2 | 3 | describe("exercise-03-a", () => { 4 | test("create 2 new files and add all of them to the staging area", async () => { 5 | let status = await git.status(); 6 | 7 | expect(status.created).toHaveLength(2); 8 | expect([ 9 | "src/exercises/exercise-03-a.txt", 10 | "src/exercises/exercise-03-b.txt", 11 | ]).toEqual(expect.arrayContaining(status.created)); 12 | }); 13 | }); 14 | 15 | describe("exercise-03-b", () => { 16 | test("create a new commit with the new files", async () => { 17 | let status = await git.status(); 18 | 19 | let raw = await git.raw([ 20 | "log", 21 | "--oneline", 22 | "-n", 23 | "1", 24 | "--grep", 25 | "exercise-03", 26 | ]); 27 | 28 | expect(status.created).not.toContain("src/exercises/exercise-03-a.txt"); 29 | expect(status.created).not.toContain("src/exercises/exercise-03-b.txt"); 30 | 31 | expect(raw).toMatch(/commit exercise-03/); 32 | }); 33 | }); 34 | -------------------------------------------------------------------------------- /src/__tests__/exercise-04.test.js: -------------------------------------------------------------------------------- 1 | const git = require("../../utils/git"); 2 | 3 | describe("exercise-04-a", () => { 4 | test("make a change and add it to the staging index", async () => { 5 | let status = await git.status(); 6 | 7 | expect(status.staged).toContain("src/exercises/exercise-03-a.txt"); 8 | expect(status.modified).toContain("src/exercises/exercise-03-a.txt"); 9 | }); 10 | }); 11 | 12 | describe("exercise-04-b", () => { 13 | test("use the git plugin to unstage the changes", async () => { 14 | let status = await git.status(); 15 | 16 | expect(status.staged).not.toContain("src/exercises/exercise-03-a.txt"); 17 | expect(status.modified).toContain("src/exercises/exercise-03-a.txt"); 18 | }); 19 | }); 20 | -------------------------------------------------------------------------------- /src/__tests__/exercise-05.test.js: -------------------------------------------------------------------------------- 1 | const git = require("../../utils/git"); 2 | 3 | describe("exercise-05", () => { 4 | test("use the git plugin to discard all the changes made to a file", async () => { 5 | let status = await git.status(); 6 | 7 | expect(status.staged).not.toContain("src/exercises/exercise-03-a.txt"); 8 | expect(status.modified).not.toContain("src/exercises/exercise-03-a.txt"); 9 | }); 10 | }); 11 | -------------------------------------------------------------------------------- /src/__tests__/exercise-06.test.js: -------------------------------------------------------------------------------- 1 | const git = require("../../utils/git"); 2 | 3 | describe("exercise-06", () => { 4 | test("create a new branch named develop and create a commit", async () => { 5 | let [branches, count] = await Promise.all([ 6 | git.branch(), 7 | git.raw(["rev-list", "develop", "^main", "--count"]), 8 | ]); 9 | 10 | expect(branches.current).toBe("develop"); 11 | 12 | expect(branches.all).toContain("main"); 13 | expect(branches.all).toContain("develop"); 14 | 15 | let n = Number(count); 16 | 17 | expect(branches.current).toMatch(/develop/); 18 | expect(n).toEqual(1); 19 | }); 20 | }); 21 | -------------------------------------------------------------------------------- /src/__tests__/exercise-07.test.js: -------------------------------------------------------------------------------- 1 | const git = require("../../utils/git"); 2 | 3 | describe("exercise-07", () => { 4 | test("switch back to the main branch", async () => { 5 | let branches = await git.branch(); 6 | 7 | expect(branches.current).toBe("main"); 8 | 9 | expect(branches.all).toContain("main"); 10 | expect(branches.all).toContain("develop"); 11 | }); 12 | }); 13 | -------------------------------------------------------------------------------- /src/__tests__/exercise-08.test.js: -------------------------------------------------------------------------------- 1 | const git = require("../../utils/git"); 2 | const BASE_REMOTE = require("../../utils/baseRemote"); 3 | 4 | describe("exercise-08", () => { 5 | test("use the git plugin to push the repository to code.assembler", async () => { 6 | let [branches, remotes, status] = await Promise.all([ 7 | git.branch(), 8 | git.getRemotes(true), 9 | git.status(), 10 | ]); 11 | 12 | expect(status.current).toBe("main"); 13 | expect(status.tracking).toBe("origin/main"); 14 | expect(branches.branches.hasOwnProperty("remotes/origin/main")).toBe(true); 15 | 16 | expect(branches.branches.main.commit).toBe( 17 | branches.branches["remotes/origin/main"].commit 18 | ); 19 | 20 | expect(branches.all).toContain("main"); 21 | expect(branches.all).toContain("remotes/origin/main"); 22 | 23 | expect(remotes).toHaveLength(1); 24 | expect(remotes[0].name).toBe("origin"); 25 | expect(remotes[0].refs.fetch).not.toBe(BASE_REMOTE); 26 | expect(remotes[0].refs.push).not.toBe(BASE_REMOTE); 27 | }); 28 | }); 29 | -------------------------------------------------------------------------------- /src/__tests__/exercise-09.test.js: -------------------------------------------------------------------------------- 1 | const git = require("../../utils/git"); 2 | 3 | describe("exercise-09", () => { 4 | test("create a new stash entry without a message", async () => { 5 | let stashList = await git.stashList(); 6 | 7 | expect(stashList.total).toBe(1); 8 | }); 9 | }); 10 | -------------------------------------------------------------------------------- /src/__tests__/exercise-10.test.js: -------------------------------------------------------------------------------- 1 | const git = require("../../utils/git"); 2 | 3 | describe("exercise-10", () => { 4 | test("use git stash pop to remove the stash entry", async () => { 5 | let stashList = await git.stashList(); 6 | 7 | expect(stashList.total).toBe(0); 8 | }); 9 | }); 10 | -------------------------------------------------------------------------------- /src/__tests__/exercise-11.test.js: -------------------------------------------------------------------------------- 1 | const git = require("../../utils/git"); 2 | 3 | describe("exercise-11", () => { 4 | test("create a new stash entry with a message", async () => { 5 | let stashList = await git.stashList(); 6 | 7 | expect(stashList.total).toBe(1); 8 | expect(stashList.latest.message).toMatch(/my stash message/i); 9 | }); 10 | }); 11 | -------------------------------------------------------------------------------- /src/__tests__/exercise-12.test.js: -------------------------------------------------------------------------------- 1 | const git = require("../../utils/git"); 2 | 3 | describe("exercise-12", () => { 4 | test("clear the stash list", async () => { 5 | let stashList = await git.stashList(); 6 | 7 | expect(stashList.total).toBe(0); 8 | }); 9 | }); 10 | -------------------------------------------------------------------------------- /src/__tests__/exercise-13.test.js: -------------------------------------------------------------------------------- 1 | const git = require("../../utils/git"); 2 | 3 | describe("exercise-13", () => { 4 | test("create a new file and store it in a stash entry", async () => { 5 | let stashList = await git.stashList(); 6 | let raw = await git.raw(["ls-tree", "-r", "stash@{0}^3", "--name-only"]); 7 | 8 | expect(stashList.total).toBe(1); 9 | expect(stashList.latest.message).toMatch(/stash with untracked files/i); 10 | expect(raw).toMatch(/src\/exercises\/exercise-13.txt/i); 11 | }); 12 | }); 13 | -------------------------------------------------------------------------------- /src/exercises/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blakejohns5/git-basics-vscode/1f29e7c7176ae6b750d03879cde2f42e8031f231/src/exercises/.gitkeep -------------------------------------------------------------------------------- /src/exercises/exercise-01.txt: -------------------------------------------------------------------------------- 1 | Hello Assembler! -------------------------------------------------------------------------------- /src/exercises/exercise-03-a.txt: -------------------------------------------------------------------------------- 1 | Hello again. -------------------------------------------------------------------------------- /src/exercises/exercise-03-b.txt: -------------------------------------------------------------------------------- 1 | and hello again. -------------------------------------------------------------------------------- /utils/baseRemote.js: -------------------------------------------------------------------------------- 1 | const BASE_REMOTE = 2 | "https://code.assemblerschool.com/mike/git-basics-vscode.git"; 3 | 4 | module.exports = BASE_REMOTE; 5 | -------------------------------------------------------------------------------- /utils/git.js: -------------------------------------------------------------------------------- 1 | const simpleGit = require("simple-git/promise"); 2 | 3 | const git = simpleGit(); 4 | 5 | module.exports = git; 6 | --------------------------------------------------------------------------------