Skip to content

Commit

Permalink
improv(push): handle cases where there is no tracking branch #21
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisgrieser committed Oct 9, 2024
1 parent f126dde commit 243cea0
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion lua/tinygit/commands/push-pull.lua
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ function M.push(opts, calledByCommitFunc)
end
end
if not opts then opts = {} end
local title = opts.forceWithLease and "Force Push" or "Push"

-- extra notification when called by user
if not calledByCommitFunc then
local title = opts.forceWithLease and "Force Push" or "Push"
if opts.pullBefore then title = "Pull & " .. title end
u.notify(title .. "", "info")
end
Expand All @@ -88,6 +88,24 @@ function M.push(opts, calledByCommitFunc)
return
end

-- Handle missing tracking branch, see #21
local hasNoTrackingBranch = u.syncShellCmd({ "git", "status", "--short", "--branch" })
:find("## (.-)%.%.%.") == nil
if hasNoTrackingBranch then
local noAutoSetupRemote = u.syncShellCmd { "git", "config", "--get", "push.autoSetupRemote" }
== "false"
if noAutoSetupRemote then
u.notify("There is no tracking branch. Aborting push.", "warn", title)
return
end
if opts.pullBefore then
local msg = "Not pulling since not tracking any branch. Skipping to push."
u.notify(msg, "info", title)
pushCmd(opts)
return
end
end

-- Pull & Push
vim.system(
{ "git", "pull" },
Expand Down

0 comments on commit 243cea0

Please sign in to comment.