Class RealRepoController
java.lang.Object
io.github.jbastgen.stemma.app.git.RealRepoController
Carries out the actions of one real (not sample) repository view through the Git backend and keeps the view's
RepoState up to date.
Every action runs off the JavaFX thread, one after the other per repository (see
RepositoryService.submit(java.nio.file.Path, java.util.function.Function<io.github.jbastgen.stemma.git.api.GitRepository, T>)), reports its result as a toast, and finishes by reloading the repository, so
the view always shows what is really on disk. All methods must be called on the JavaFX thread.
-
Field Summary
FieldsModifier and TypeFieldDescriptionCalled with the reason when a push was rejected and a forced push could be offered; the view sets it. -
Constructor Summary
ConstructorsConstructorDescriptionRealRepoController(RepositoryService service, Path workTree, RepoState state, Host host, Runnable refresh) -
Method Summary
Modifier and TypeMethodDescriptionvoidAbandons the merge; the branch is as it was.static List<io.github.jbastgen.stemma.git.api.BackupInfo> allBackups(io.github.jbastgen.stemma.git.api.GitRepository repo) The backups of all kinds, newest first.voidReplaces the last commit by one with this message and the staged changes (none is fine: only the message changes).voidapplyStash(int index) Applies a stash and keeps it.booleanautoFetch(boolean prune, Consumer<AutoFetch.Outcome> onDone) Feature 54: fetches all remotes without a word (no toast, no reload unless something changed) and tells the caller how it went.voidSwitches to the branch.voidcheckoutRemote(String remote, String branch) Checks out a branch that only exists on a remote: a local tracking branch is created, or the local one is used.voidcheckRemoteTags(String remote) Asks a remote which tags it has, so that the side panel can mark the tags that exist only here.voidcherryPick(List<String> commitIds, boolean recordOrigin, boolean noCommit, int mainline) Copies commits onto the current branch.voidcherryPick(List<String> commitIds, boolean recordOrigin, boolean noCommit, int mainline, boolean copyLabels) As above;copyLabelsgives each new commit the labels of the commit it was copied from.voidCommits.Builds a privacy-filtered prompt for the next commit message off the UI thread.voidcreateBranch(String name, String startCommit, boolean checkout) Creates a branch at the commit, optionally switching to it.voidCreates a tag, without pushing it.voidCreates a tag and, whenpushTonames a remote, pushes it there right away.voiddeleteBranch(String name, boolean force, Runnable onNotMerged) Deletes a local branch;onNotMergedis called if git refuses because it is not fully merged.voiddeleteRemoteTag(String remote, String tag) Deletes a tag on a remote; the local tag stays.voidDeletes the tag.voiddiscard(Collection<String> paths) Discards the local changes of the files.voiddiscardFiles(List<FileChange> files) Discards these files of the working tree (seeDiscardPlan): modified and deleted files go back to HEAD, new files are removed, untracked files are deleted, or moved to the trash when the settings say so.voiddiscardLines(String path, Set<String> keys, boolean hunk) Throws away the lines ofpathwith these keys from the working tree.voiddropStash(int index) Drops the stash.voidWrites the files of a commit as a Zip archive in the background and tells where it is and how big it is.voidfetchRemotes(List<String> remotes) Fetches the remotes one after the other, in this order (nullor empty: all remotes of the repository).voidflowFinish(Kind kind, String branch, String tagMessage) Finishes the given branch (full name, e.g.voidflowFinish(Kind kind, String branch, String tagMessage, boolean squash, String squashMessage) Finishes the given branch; withsquashits commits are combined into one when merged.voidSets Git Flow up with the default prefixes.voidflowSetUp(GitFlowWizard.Choice choice) Runs the set-up of the wizard: the first commit if wanted, the branch, the configuration, the checkout and the push.voidStarts a feature, release or hotfix.voidReads what the Git Flow wizard needs (off the UI thread) and hands it, with the current configuration, tothen.voidforcePush(io.github.jbastgen.stemma.git.api.PushForce force) Pushes the current branch over the remote one: with the lease, or (only when the settings allow) without.voidWrites the lines to the ignore file and tells what happened (written, or already ignored).voidloadBlame(String revision, String path, io.github.jbastgen.stemma.git.api.BlameOptions options, BiConsumer<List<io.github.jbastgen.stemma.git.api.BlameLine>, String> then) Blames a file as it is in a revision (wip= the last commit) in the background (feature 47);thengets the lines or, when it fails, null and the reason, on the UI thread.voidloadCodeMetrics(Consumer<CodeMetrics> then) Counts the lines of the text files of the last commit in the background;thengets the result on the UI thread.loadCommitData(List<String> ids) Reads message and changes of the commits for a description (off the JavaFX thread).voidloadCommitStats(int limit, Consumer<List<io.github.jbastgen.stemma.git.api.CommitStat>> then) Reads the commits with their files and lines in the background;thengets them on the UI thread.voidloadDetails(String commitId) Starts loading message body and changed files of a commit, once.voidStarts loading the diff of one file, once.voidloadFileBytes(String sel, String path, Consumer<byte[]> then) The content of a file in a commit, or in the working tree forwip; null when it is not there.voidloadFileHistory(String path, boolean follow, int limit, BiConsumer<List<io.github.jbastgen.stemma.git.api.FileCommit>, String> then) The commits that changed a file or folder, in the background (feature 46);thengets them, or null and the reason, on the UI thread.voidloadFilePaths(String sel, Consumer<List<String>> then) The paths of the files of a commit (wip= HEAD);thengets them on the UI thread, null when it fails.voidloadFileText(String sel, String path, Consumer<String> onText) Reads the text of a file for the preview: from the working tree for"wip", else as it was in the commit; the text goes toonTexton the UI thread, null when the file is not there or is not text.voidloadHeadMessage(Consumer<String[]> onMessage) The summary and the description of the last commit, for amending it; null when the history is empty.voidloadImages(String newSel, String oldRef, String path, Consumer<ImageFiles.Versions> onLoaded) Reads the two versions of a picture file for the diff view:newSelis"wip"(the working tree) or a commit,oldRefthe commit it is compared with (null: the file is new, there is no earlier version).voidFinds out which key the repository has in the label index; once.voidloadStashDetails(int index, Consumer<io.github.jbastgen.stemma.git.api.StashDetails> then) Reads the files of a stash and hands them tothenon the UI thread (nothing on a failure: a toast says why).voidThe changes of one file of a stash commit, as lines.voidMerges the branch into the current one, with the message the template gives.voidMerges with a message of the user; an empty message means the configured template.mergeMessagePrompt(String source, String target, String kind) The prompt for the message of a merge, a squash or a tag (feature 4): the commits thatsourcebrings intotargetand the message template.static StringThe message of the underlying failure, without the wrapper exceptions of the futures.voidopenFileOfCommit(String commitId, String path) Opens a file as it was in a commit: a read-only copy is written to the folder for opened files and opened with the system's program.voidpopStash(int index) Applies the stash and drops it.voidpreviewReset(String target, IntConsumer onCount) Asks how many commits a reset totargettakes off the branch (-1: it could not be told).static voidpruneBackups(io.github.jbastgen.stemma.git.api.GitRepository repo) Deletes the backups that are older than the time they are kept; a failure is only logged, they stay until next time.voidpull()Pulls: fetches and merges the upstream.voidpush()Pushes the current branch; a branch without upstream is published and its upstream is set.voidpushAllTags(String remote) Pushes all tags that the remote does not have.voidPushes one tag to a remote.voidReplays the current branch on top ofonto.voidAbandons the rebase; the branch is as it was.voidContinues the rebase after the conflicts were resolved.voidrebaseInteractive(String onto, List<io.github.jbastgen.stemma.git.api.RebaseStep> steps) Rebases ontoontowith the steps of the interactive rebase dialog.voidSkips the commit that conflicts and continues.voidreload()Loads the repository again and updates the view.voidReloads only if something changed since the last load: asks for the changed files and the branches (two cheap reads) instead of everything.voidrenameBranch(String oldName, String newName, String alsoOnRemote) Renames a local branch.repoName()The name of the repository: the folder name.voidMoves the current branch totarget.voidResolves one conflicting file: with the external tool of the settings if one is chosen and the file is text, else in Stemma's own merge tool.voidMakes commits that undo the given ones.voidAbandons the cherry-pick or revert; the branch is as it was.voidContinues the cherry-pick or revert after the conflicts were resolved.voidLeaves out the commit that stopped the cherry-pick or revert.voidsetAllStaged(boolean staged) Stages every file of the working tree, or unstages them all ("Select all").voidGives a commit exactly these labels.voidsetStaged(List<FileChange> files, boolean staged) Stages these files, or unstages them; conflicted files are not staged this way (seesetAllStaged(boolean)).voidReplaces the lastcountcommits by one withmessage.voidStages the hunk ofpathwhose header isheaderLine.voidstageLines(String path, Set<String> keys) Stages the lines ofpathwith these keys (seeHunks.ChangeLine), feature 50.voidstash()Stashes all changes, untracked files included.voidStashes what the options say, with a message of the user's own (blank = git's).voidstashBranch(int index, String branch) Makes a branch where the stash was made, with the stash applied to it.voidstopTrackingAndIgnore(IgnoreFile.Target target, List<String> paths) Stops tracking the files (they stay on the disk, and the next commit removes them from the repository) and ignores them: Git ignores only files it does not track.voidtoggleStaged(String path) Stages a file, or unstages it when it is staged; a file with conflict markers cannot be staged.voidundoReset(io.github.jbastgen.stemma.git.api.BackupInfo backup) Brings back what a hard reset took: the files as they were (changes, untracked files, deletions) and the branch at the commit it was at.voidunstageHunk(String path, String headerLine) Unstages the hunk ofpathwhose header isheaderLine.voidunstageLines(String path, Set<String> keys) Unstages the lines ofpathwith these keys.voidwithCopyOfCommitFile(String commitId, String path, Consumer<Path> then) Writes a read-only copy of a file as it was in a commit (seeOpenedFiles) and hands it tothenon the UI thread.voidwriteChangelog(String content, boolean stage) Writes the changelog file in the working tree and, if wanted, stages it.
-
Field Details
-
offerForcePush
Called with the reason when a push was rejected and a forced push could be offered; the view sets it.
-
-
Constructor Details
-
RealRepoController
public RealRepoController(RepositoryService service, Path workTree, RepoState state, Host host, Runnable refresh) - Parameters:
service- the application service that runs the Git workworkTree- the repositorystate- the state the view shows; changed only on the JavaFX threadhost- what the controller needs of the window: toasts, settings, servicesrefresh- redraws the view after a reload
-
-
Method Details
-
reload
public void reload()Loads the repository again and updates the view. Also used when the window regains focus. -
reloadIfChanged
public void reloadIfChanged()Reloads only if something changed since the last load: asks for the changed files and the branches (two cheap reads) instead of everything. Used when the window is used again. -
loadDetails
Starts loading message body and changed files of a commit, once. The view is refreshed when they arrive. -
loadDiff
Starts loading the diff of one file, once.selis a commit id or"wip". -
setAllStaged
public void setAllStaged(boolean staged) Stages every file of the working tree, or unstages them all ("Select all"). Files with unresolved conflicts are not staged this way: staging one marks it resolved, which has to be decided for each file. -
setStaged
Stages these files, or unstages them; conflicted files are not staged this way (seesetAllStaged(boolean)). -
toggleStaged
Stages a file, or unstages it when it is staged; a file with conflict markers cannot be staged. -
stageHunk
Stages the hunk ofpathwhose header isheaderLine. -
unstageHunk
Unstages the hunk ofpathwhose header isheaderLine. -
stageLines
Stages the lines ofpathwith these keys (seeHunks.ChangeLine), feature 50. -
unstageLines
Unstages the lines ofpathwith these keys. -
discardLines
Throws away the lines ofpathwith these keys from the working tree. A backup of the working tree is written first (if the settings say so) and the message offers Undo; when the backup fails nothing is discarded. -
commit
Commits. With nothing staged, everything is staged first ("Commit all"). During a merge nothing is staged automatically: resolved files must be staged on purpose, so conflict markers are never committed by accident. -
loadHeadMessage
The summary and the description of the last commit, for amending it; null when the history is empty. -
amend
Replaces the last commit by one with this message and the staged changes (none is fine: only the message changes). The labels of the old commit move to the new one, because the label index is keyed by commit id. -
openFileOfCommit
Opens a file as it was in a commit: a read-only copy is written to the folder for opened files and opened with the system's program. -
loadFileText
Reads the text of a file for the preview: from the working tree for"wip", else as it was in the commit; the text goes toonTexton the UI thread, null when the file is not there or is not text. -
loadImages
public void loadImages(String newSel, String oldRef, String path, Consumer<ImageFiles.Versions> onLoaded) Reads the two versions of a picture file for the diff view:newSelis"wip"(the working tree) or a commit,oldRefthe commit it is compared with (null: the file is new, there is no earlier version). A side the file does not exist on is null; the result goes toonLoadedon the UI thread (null when reading failed). -
withCopyOfCommitFile
Writes a read-only copy of a file as it was in a commit (seeOpenedFiles) and hands it tothenon the UI thread. -
ignore
Writes the lines to the ignore file and tells what happened (written, or already ignored). -
stopTrackingAndIgnore
Stops tracking the files (they stay on the disk, and the next commit removes them from the repository) and ignores them: Git ignores only files it does not track. -
discardFiles
Discards these files of the working tree (seeDiscardPlan): modified and deleted files go back to HEAD, new files are removed, untracked files are deleted, or moved to the trash when the settings say so. -
discard
Discards the local changes of the files. -
stash
public void stash()Stashes all changes, untracked files included. -
stash
Stashes what the options say, with a message of the user's own (blank = git's). -
applyStash
public void applyStash(int index) Applies a stash and keeps it. A conflict is reported and leaves the stash where it is. -
stashBranch
Makes a branch where the stash was made, with the stash applied to it. -
loadStashDetails
public void loadStashDetails(int index, Consumer<io.github.jbastgen.stemma.git.api.StashDetails> then) Reads the files of a stash and hands them tothenon the UI thread (nothing on a failure: a toast says why). -
loadStashDiff
The changes of one file of a stash commit, as lines. -
popStash
public void popStash(int index) Applies the stash and drops it. -
dropStash
public void dropStash(int index) Drops the stash. -
checkout
Switches to the branch. -
checkoutRemote
Checks out a branch that only exists on a remote: a local tracking branch is created, or the local one is used. -
createBranch
Creates a branch at the commit, optionally switching to it. -
deleteBranch
Deletes a local branch;onNotMergedis called if git refuses because it is not fully merged. -
merge
Merges the branch into the current one, with the message the template gives. -
merge
Merges with a message of the user; an empty message means the configured template. -
mergeMessagePrompt
The prompt for the message of a merge, a squash or a tag (feature 4): the commits thatsourcebrings intotargetand the message template. Built off the UI thread; files and diffs are not sent.- Parameters:
kind-merge,squashortag
-
loadFilePaths
The paths of the files of a commit (wip= HEAD);thengets them on the UI thread, null when it fails. -
loadFileBytes
The content of a file in a commit, or in the working tree forwip; null when it is not there. -
loadBlame
public void loadBlame(String revision, String path, io.github.jbastgen.stemma.git.api.BlameOptions options, BiConsumer<List<io.github.jbastgen.stemma.git.api.BlameLine>, String> then) Blames a file as it is in a revision (wip= the last commit) in the background (feature 47);thengets the lines or, when it fails, null and the reason, on the UI thread. -
loadFileHistory
public void loadFileHistory(String path, boolean follow, int limit, BiConsumer<List<io.github.jbastgen.stemma.git.api.FileCommit>, String> then) The commits that changed a file or folder, in the background (feature 46);thengets them, or null and the reason, on the UI thread.- Parameters:
follow- follow a file across renames (not for a folder)
-
loadCommitStats
public void loadCommitStats(int limit, Consumer<List<io.github.jbastgen.stemma.git.api.CommitStat>> then) Reads the commits with their files and lines in the background;thengets them on the UI thread. -
loadCodeMetrics
Counts the lines of the text files of the last commit in the background;thengets the result on the UI thread. -
writeChangelog
Writes the changelog file in the working tree and, if wanted, stages it. -
loadCommitData
Reads message and changes of the commits for a description (off the JavaFX thread). -
repoName
The name of the repository: the folder name. -
commitMessagePrompt
Builds a privacy-filtered prompt for the next commit message off the UI thread. -
loadLabelKey
public void loadLabelKey()Finds out which key the repository has in the label index; once. -
setLabels
Gives a commit exactly these labels. -
rebase
Replays the current branch on top ofonto. -
rebaseInteractive
public void rebaseInteractive(String onto, List<io.github.jbastgen.stemma.git.api.RebaseStep> steps) Rebases ontoontowith the steps of the interactive rebase dialog. -
rebaseContinue
public void rebaseContinue()Continues the rebase after the conflicts were resolved. -
rebaseSkip
public void rebaseSkip()Skips the commit that conflicts and continues. -
rebaseAbort
public void rebaseAbort()Abandons the rebase; the branch is as it was. -
cherryPick
public void cherryPick(List<String> commitIds, boolean recordOrigin, boolean noCommit, int mainline) Copies commits onto the current branch.- Parameters:
commitIds- oldest first
-
cherryPick
public void cherryPick(List<String> commitIds, boolean recordOrigin, boolean noCommit, int mainline, boolean copyLabels) As above;copyLabelsgives each new commit the labels of the commit it was copied from. -
revert
Makes commits that undo the given ones. -
sequenceContinue
public void sequenceContinue()Continues the cherry-pick or revert after the conflicts were resolved. -
sequenceSkip
public void sequenceSkip()Leaves out the commit that stopped the cherry-pick or revert. -
sequenceAbort
public void sequenceAbort()Abandons the cherry-pick or revert; the branch is as it was. -
squash
Replaces the lastcountcommits by one withmessage. -
resolve
Resolves one conflicting file: with the external tool of the settings if one is chosen and the file is text, else in Stemma's own merge tool. Files that cannot be merged line by line (binary, deleted on one side) ask which version to keep. -
abortMerge
public void abortMerge()Abandons the merge; the branch is as it was. -
createTag
Creates a tag, without pushing it. -
createTag
Creates a tag and, whenpushTonames a remote, pushes it there right away. -
pushTag
Pushes one tag to a remote. -
pushAllTags
Pushes all tags that the remote does not have. -
deleteRemoteTag
Deletes a tag on a remote; the local tag stays. -
checkRemoteTags
Asks a remote which tags it has, so that the side panel can mark the tags that exist only here. A network call, so it only happens when the user asks for it. -
renameBranch
Renames a local branch. Git Flow's configuration follows when it is the production or development branch;alsoOnRemote(a remote name, or null) publishes the new name there, makes it the upstream and deletes the old name on that remote. -
deleteTag
Deletes the tag. -
previewReset
Asks how many commits a reset totargettakes off the branch (-1: it could not be told). -
reset
Moves the current branch totarget. A hard reset first writes a backup (if the settings say so) and then offers Undo in its message; when the backup fails nothing is reset.- Parameters:
label- how the user calls the target (a short id, a branch or a tag name)
-
undoReset
public void undoReset(io.github.jbastgen.stemma.git.api.BackupInfo backup) Brings back what a hard reset took: the files as they were (changes, untracked files, deletions) and the branch at the commit it was at. What is in the working tree now is saved in a backup of its own first, so that the undo can be undone. -
allBackups
public static List<io.github.jbastgen.stemma.git.api.BackupInfo> allBackups(io.github.jbastgen.stemma.git.api.GitRepository repo) The backups of all kinds, newest first. -
pruneBackups
public static void pruneBackups(io.github.jbastgen.stemma.git.api.GitRepository repo) Deletes the backups that are older than the time they are kept; a failure is only logged, they stay until next time. -
fetchRemotes
Fetches the remotes one after the other, in this order (nullor empty: all remotes of the repository). A remote that fails (network down, wrong credentials) does not stop the others; one message at the end reports everything. -
autoFetch
Feature 54: fetches all remotes without a word (no toast, no reload unless something changed) and tells the caller how it went. Never asks for a password: the backends run without a terminal, so a repository that needs one simply fails.- Returns:
falsewhen there was nothing to do (no remotes),onDoneis not called then
-
exportZip
Writes the files of a commit as a Zip archive in the background and tells where it is and how big it is. -
pull
public void pull()Pulls: fetches and merges the upstream. -
forcePush
public void forcePush(io.github.jbastgen.stemma.git.api.PushForce force) Pushes the current branch over the remote one: with the lease, or (only when the settings allow) without. -
push
public void push()Pushes the current branch; a branch without upstream is published and its upstream is set. -
flowInit
Sets Git Flow up with the default prefixes. -
flowWizardFacts
Reads what the Git Flow wizard needs (off the UI thread) and hands it, with the current configuration, tothen. -
flowSetUp
Runs the set-up of the wizard: the first commit if wanted, the branch, the configuration, the checkout and the push. -
flowStart
Starts a feature, release or hotfix. -
flowFinish
Finishes the given branch (full name, e.g.feature/login). -
flowFinish
public void flowFinish(Kind kind, String branch, String tagMessage, boolean squash, String squashMessage) Finishes the given branch; withsquashits commits are combined into one when merged. -
message
The message of the underlying failure, without the wrapper exceptions of the futures.
-