office: stage nothing before the ignores are decided, create the session on the owning machine, and name files that are in the repo but now ignored
This commit is contained in:
46
bin/office
46
bin/office
@@ -334,7 +334,7 @@ def run_on_remote(host, folder, opts):
|
||||
raise h.Refused(3, "could not copy the commands to %s: %s"
|
||||
% (host, (copy.stderr or copy.stdout).strip()[:300]))
|
||||
install_wrapper(addr, remote_bin)
|
||||
inner = [folder, "--no-switch"]
|
||||
inner = [folder]
|
||||
for flag, value in (("--project", opts["project"]), ("--session", opts["session"]), ("--new", opts["new"])):
|
||||
if value:
|
||||
inner += [flag, value]
|
||||
@@ -363,7 +363,11 @@ def run_on_remote(host, folder, opts):
|
||||
if not interactive:
|
||||
sys.stdout.write(out.stdout)
|
||||
if out.returncode != 0:
|
||||
raise h.Refused(3, "the other machine refused: %s" % (out.stderr or out.stdout).strip()[:300])
|
||||
detail = ""
|
||||
if not interactive:
|
||||
detail = (out.stderr or out.stdout or "").strip()[:300]
|
||||
raise h.Refused(3, "the other machine stopped with exit %d%s"
|
||||
% (out.returncode, ": " + detail if detail else ""))
|
||||
return 0
|
||||
|
||||
|
||||
@@ -554,6 +558,7 @@ def prepare_git(folder, opts, session):
|
||||
"""
|
||||
if rp.is_repo(folder) and rp.has_commit(folder):
|
||||
note_ignore(folder, opts)
|
||||
warn_tracked_but_ignored(folder)
|
||||
return "ready"
|
||||
|
||||
if opts["dry"]:
|
||||
@@ -604,10 +609,10 @@ def prepare_git(folder, opts, session):
|
||||
h.say(" made a repository on branch %s" % rp.branch(folder))
|
||||
changed, note = rp.ensure_ignore(folder)
|
||||
h.say(" %s" % note)
|
||||
if not rp.stage_all(folder):
|
||||
raise h.Refused(2, "git add failed in %s" % folder)
|
||||
|
||||
if opts["commit_all"] or (opts["git_init"] and opts["git_init_commits"]):
|
||||
if not rp.stage_all(folder):
|
||||
raise h.Refused(2, "git add failed in %s" % folder)
|
||||
ok, why = rp.commit_all(folder)
|
||||
if not ok:
|
||||
h.say(" could not commit: %s" % why)
|
||||
@@ -616,15 +621,18 @@ def prepare_git(folder, opts, session):
|
||||
return "ready"
|
||||
|
||||
h.say("")
|
||||
h.say(" EVERYTHING IS STAGED AND NOTHING IS COMMITTED. What you commit is what")
|
||||
h.say(" the agent will be able to see, so check it before you commit.")
|
||||
h.say(" NOTHING IS STAGED AND NOTHING IS COMMITTED YET, which is the right order:")
|
||||
h.say(" decide what to leave out first, then stage what is left.")
|
||||
open_git_session(folder, session, opts)
|
||||
h.say("")
|
||||
h.say(" In lazygit:")
|
||||
h.say("")
|
||||
h.say(" i put the selected file or folder into .gitignore")
|
||||
h.say(" space stage or unstage e edit a file, .gitignore included")
|
||||
h.say(" c commit ? every key")
|
||||
h.say(" a stage everything that is left after the ignores")
|
||||
h.say(" c commit e edit a file ? every key")
|
||||
h.say("")
|
||||
h.say(" Ignore first, stage second: a file that is already staged stays staged")
|
||||
h.say(" even after you ignore it, and would still be committed.")
|
||||
h.say("")
|
||||
h.say(" Then, after committing, repeat this command to create the project:")
|
||||
h.say("")
|
||||
@@ -632,6 +640,26 @@ def prepare_git(folder, opts, session):
|
||||
return "staged"
|
||||
|
||||
|
||||
def warn_tracked_but_ignored(folder):
|
||||
"""Ignoring a file does not remove it from the repository.
|
||||
|
||||
A path already in a commit stays there until it is removed from the index.
|
||||
Saying so is the difference between a rule and a misunderstanding.
|
||||
"""
|
||||
# -c is required: without it git refuses, and the check silently passed
|
||||
# while four files sat in the commit that .gitignore said to ignore.
|
||||
out = rp.git(folder, "ls-files", "-c", "-i", "--exclude-standard")
|
||||
if out.returncode != 0 or not out.stdout.strip():
|
||||
return
|
||||
names = [n for n in out.stdout.strip().split("\n") if n][:6]
|
||||
h.say(" warning: .gitignore now names %d file(s) that are already in the" % len(names))
|
||||
h.say(" repository. Ignoring does not untrack them:")
|
||||
for n in names:
|
||||
h.say(" %s" % n)
|
||||
h.say(" to remove them, commit the removal:")
|
||||
h.say(" git rm --cached -r <the paths above> && git commit -m 'stop tracking them'")
|
||||
|
||||
|
||||
def note_ignore(folder, opts):
|
||||
"""Say when worktrees are about to be committed. Never change anything."""
|
||||
state = rp.is_repo(folder)
|
||||
@@ -726,7 +754,7 @@ def main():
|
||||
# Nothing is committed, so the project cannot have worktrees yet, and
|
||||
# creating it without them is a decision that cannot be undone.
|
||||
h.say("")
|
||||
h.say("the project was not created: commit the staged files, then run this again.")
|
||||
h.say("the project was not created: commit your files, then run this again.")
|
||||
return 0
|
||||
|
||||
if opts["new"]:
|
||||
|
||||
Reference in New Issue
Block a user