From aa7fbafb2ccad9dc4747009271dc154076969aef Mon Sep 17 00:00:00 2001 From: Erica Marigold Date: Fri, 21 Jun 2024 12:58:18 +0530 Subject: [PATCH] fix: fix some bugs in git wrapper scripts --- bin/gc.luau | 46 +++++++++++++++++++++++----------------------- bin/gl.luau | 2 +- bin/gp.luau | 8 +++++--- 3 files changed, 29 insertions(+), 27 deletions(-) diff --git a/bin/gc.luau b/bin/gc.luau index 8003a7f..39e7e06 100644 --- a/bin/gc.luau +++ b/bin/gc.luau @@ -10,11 +10,11 @@ function main(args: {string}) return gitStatusChild.code end - local statusDiff:{{ file: string, type: string }} = {} + local statusDiff: {{ file: string, type: string }} = {} local statusLines = gitStatusChild.stdout:split("\n") for lineCount, line in statusLines do - if lineCount >= 6 and lineCount then + if lineCount > 6 then local type, file = line:match("^%s(.+): (.+)$") if type == nil then break @@ -53,7 +53,7 @@ function main(args: {string}) for type, filesAndCount: { count: number, [number]: string, - } in typeCounts do + } in typeCounts do local count = filesAndCount.count local bullet = dim("•") stdio.write(` {bullet} { @@ -61,7 +61,7 @@ function main(args: {string}) } files {type}`) if count == 1 then - stdio.write(` ({dim(filesAndCount[1])})`) + stdio.write(` ({dim(filesAndCount[1]:gsub("%s", ""))})\n`) continue end @@ -70,29 +70,29 @@ function main(args: {string}) files.count = nil for _, file in files do -- TODO: Map colors to type - print(` {bullet} {stdio.color("cyan") .. file .. stdio.color("reset")}`) + print(` {bullet} {stdio.color("cyan") .. file:gsub("%s", "") .. stdio.color("reset")}`) end + end - print("Commit message:") - -- TODO: Conventional commit prompts - local commitMessage = stdio.prompt("text") - local gitCommitChild = process.spawn("git", {"commit", "-a", "-m", commitMessage}) - if not gitCommitChild.ok then - stdio.ewrite(gitCommitChild.stderr) - return gitCommitChild.code - end + print("Commit message:") + -- TODO: Conventional commit prompts + local commitMessage = stdio.prompt("text") + local gitCommitChild = process.spawn("git", {"commit", "-a", "-m", commitMessage}) + if not gitCommitChild.ok then + stdio.ewrite(gitCommitChild.stderr) + return gitCommitChild.code + end - stdio.write("\n") - local toPush = stdio.prompt("confirm", "Push changes to remote?") - if toPush then - local pushChild = process.spawn("lune", { "run", "$HOME/bin/gp.luau" }, { - shell = true, - stdio = "forward" - }) + stdio.write("\n") + local toPush = stdio.prompt("confirm", "Push changes to remote?") + if toPush then + local pushChild = process.spawn("lune", { "run", "$HOME/bin/gp.luau" }, { + shell = true, + stdio = "forward" + }) - if not pushChild.ok then - return pushChild.code - end + if not pushChild.ok then + return pushChild.code end end diff --git a/bin/gl.luau b/bin/gl.luau index 16a2f61..419c485 100644 --- a/bin/gl.luau +++ b/bin/gl.luau @@ -43,7 +43,7 @@ local function outputToCommit(_, line) } end -function main(args: {string}) +function main(args: {string?}) local range = args[1] local gitLogChild = process.spawn( "git", diff --git a/bin/gp.luau b/bin/gp.luau index f1bb65e..1eb4be8 100644 --- a/bin/gp.luau +++ b/bin/gp.luau @@ -2,7 +2,7 @@ local process = require("@lune/process") local stdio = require("@lune/stdio") local task = require("@lune/task") -local gitLog = require("./gl.luau") +local gitLog = require("gl.luau") type Commit = gitLog.Commit local function dots(count: number) @@ -15,14 +15,16 @@ end function main(args: {string}) print("Unpushed commits:") - local childExit = gitLog.main({"main..HEAD"}) + local childExit = gitLog.main({"origin/main..HEAD"}) if childExit ~= 0 then return childExit end stdio.write("Pushing to remote") task.spawn(dots, 3) - local pushChild = process.spawn("git", {"push"}) + local pushChild = process.spawn("git", {"pull", "--rebase", "&&", "git", "push"}, { + shell = true + }) if not pushChild.ok then stdio.ewrite("\r" .. pushChild.stderr) return pushChild.code