├── .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 │ ├── exercise-14.test.js │ └── exercise-15.test.js └── exercises │ └── .gitkeep └── utils └── git.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .DS_STORE 3 | -------------------------------------------------------------------------------- /CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @daniassembler -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # git-basics-1-pill 2 | 3 | Assembler School Git Basics 1 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-1-pill", 3 | "version": "1.0.0", 4 | "description": "assembler-school-git-basics-1-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 | "validate-exercise-14": "jest -t exercise-14", 22 | "validate-exercise-15": "jest -t exercise-15" 23 | }, 24 | "keywords": [ 25 | "git", 26 | "basics", 27 | "assemblerschool" 28 | ], 29 | "author": "Daniel Lucaci ", 30 | "license": "MIT", 31 | "dependencies": { 32 | "@types/jest": "^25.2.1", 33 | "git-tools": "^0.3.0", 34 | "jest": "^25.5.2", 35 | "simple-git": "^2.2.0" 36 | }, 37 | "devDependencies": { 38 | "@babel/core": "^7.9.6", 39 | "@babel/preset-env": "^7.9.6", 40 | "babel-jest": "^25.5.1", 41 | "husky": "^4.2.5", 42 | "lint-staged": "^10.2.1" 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /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(/exercise-02 commit/); 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(/exercise-03 commit/); 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 git reset HEAD 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 git checkout command 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", async () => { 5 | let branches = await git.branch(); 6 | 7 | expect(branches.current).toMatch(/main/); 8 | 9 | expect(branches.all).toContain("main"); 10 | expect(branches.all).toContain("develop"); 11 | }); 12 | }); 13 | -------------------------------------------------------------------------------- /src/__tests__/exercise-07.test.js: -------------------------------------------------------------------------------- 1 | const git = require("../../utils/git"); 2 | 3 | describe("exercise-07", () => { 4 | test("switch to the develop branch and create a new commit", async () => { 5 | let branches = await git.branch(); 6 | let count = await git.raw(["rev-list", "develop", "^main", "--count"]); 7 | 8 | let n = Number(count); 9 | 10 | expect(branches.current).toMatch(/develop/); 11 | expect(n).toEqual(1); 12 | }); 13 | }); 14 | -------------------------------------------------------------------------------- /src/__tests__/exercise-08.test.js: -------------------------------------------------------------------------------- 1 | const git = require("../../utils/git"); 2 | 3 | describe("exercise-08", () => { 4 | test("create a new branch named feature based on the develop branch", async () => { 5 | let branches = await git.branch(); 6 | let count = await git.raw([ 7 | "rev-list", 8 | "feature", 9 | "develop", 10 | "^main", 11 | "--count", 12 | ]); 13 | 14 | let n = Number(count); 15 | 16 | expect(n).toEqual(1); 17 | expect(branches.current).toMatch(/main/); 18 | expect(branches.all).toContain("develop"); 19 | expect(branches.all).toContain("feature"); 20 | expect(branches.all).toContain("main"); 21 | }); 22 | }); 23 | -------------------------------------------------------------------------------- /src/__tests__/exercise-09.test.js: -------------------------------------------------------------------------------- 1 | const git = require("../../utils/git"); 2 | 3 | describe("exercise-09", () => { 4 | test("remove the branch feature", async () => { 5 | let branches = await git.branch(); 6 | 7 | expect(branches.current).toMatch(/main/); 8 | expect(branches.all).toContain("develop"); 9 | expect(branches.all).not.toContain("feature"); 10 | expect(branches.all).toContain("main"); 11 | }); 12 | }); 13 | -------------------------------------------------------------------------------- /src/__tests__/exercise-10.test.js: -------------------------------------------------------------------------------- 1 | const git = require("../../utils/git"); 2 | 3 | describe("exercise-10", () => { 4 | test("create merge commit with main and develop", async () => { 5 | let branches = await git.branch(); 6 | let count = await git.raw([ 7 | "rev-list", 8 | "develop", 9 | "main", 10 | "--merges", 11 | "--count", 12 | ]); 13 | 14 | let n = Number(count); 15 | 16 | expect(n).toEqual(1); 17 | expect(branches.current).toMatch(/main/); 18 | expect(branches.all).toContain("develop"); 19 | expect(branches.all).toContain("main"); 20 | }); 21 | }); 22 | -------------------------------------------------------------------------------- /src/__tests__/exercise-11.test.js: -------------------------------------------------------------------------------- 1 | const git = require("../../utils/git"); 2 | 3 | describe("exercise-11", () => { 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-12.test.js: -------------------------------------------------------------------------------- 1 | const git = require("../../utils/git"); 2 | 3 | describe("exercise-12", () => { 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-13.test.js: -------------------------------------------------------------------------------- 1 | const git = require("../../utils/git"); 2 | 3 | describe("exercise-13", () => { 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-14.test.js: -------------------------------------------------------------------------------- 1 | const git = require("../../utils/git"); 2 | 3 | describe("exercise-14", () => { 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-15.test.js: -------------------------------------------------------------------------------- 1 | const git = require("../../utils/git"); 2 | 3 | describe("exercise-15", () => { 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-15.txt/i); 11 | }); 12 | }); 13 | -------------------------------------------------------------------------------- /src/exercises/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/juliomc23/git-basics-1/6b971734e483879880bc5ce14448f3e754e57fed/src/exercises/.gitkeep -------------------------------------------------------------------------------- /utils/git.js: -------------------------------------------------------------------------------- 1 | const simpleGit = require("simple-git/promise"); 2 | 3 | const git = simpleGit(); 4 | 5 | module.exports = git; 6 | --------------------------------------------------------------------------------