1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-04-21 12:16:54 +02:00

349 Commits

Author SHA1 Message Date
Jesse Duffield
7e85cdd027 Allow user to filter the files view to only show untracked files
This handles the situation where the user's own config says to not show
untracked files, as is often the case with bare repos managing a user's
dotfiles.
2025-02-07 09:04:55 +11:00
Stefan Haller
0864affc8f Fix checking out a different branch while pushing a branch for the first time
When pushing a branch that didn't have an upstream yet, we use the command line

  git push --set-upstream origin HEAD:branch-name

The HEAD: part of this is too unspecific; when checking out a different branch
while the push is still running, then git will set the upstream branch on the
newly checked out branch, not the branch that was being pushed. This might be
considered a bug in git; you might expect that it resolves HEAD at the beginning
of the operation, and uses the result at the end.

But we can easily work around this by explicitly supplying the real branch name
instead of HEAD.
2025-01-26 10:22:19 +01:00
Erich Fussi
2a87c048b9 Add '--' to 'git rev-list' to disambiguate branch name from path 2025-01-19 14:33:42 +01:00
Stefan Haller
eaaf123238 Combine GetPathDiff and GetAllDiff into one command (GetDiff)
This makes it more reusable for other purposes.
2025-01-07 17:46:51 +01:00
RiceChuan
c834e132c7 chore: use errors.New to replace fmt.Errorf with no parameters
Signed-off-by: RiceChuan <lc582041246@gmail.com>
2025-01-02 17:27:54 +11:00
John Mutuma
d7d5733a71 Revert unwanted change 2025-01-02 16:52:24 +11:00
John Mutuma
5240b2862f Add worktree option to fast forwarding operation 2025-01-02 16:52:24 +11:00
John Mutuma
e1c18226bf Add worktree option to fast forwarding operation 2025-01-02 16:52:24 +11:00
Stefan Haller
a9ef69b9c7 Fix moving a commit across a branch boundary in a stack
See the previous commit for a detailed explanation.
2024-12-23 12:18:48 +01:00
Stefan Haller
078445db63 Allow deleting a merge commit
For non-merge commits we change "pick" to "drop" when we delete them. We do this
so that we can use the same code for dropping a commit no matter whether we are
in an interactive rebase or not. (If we aren't, we could just as well delete the
pick line from the todo list instead of setting it to "drop", but if we are, it
is better to keep the line around so that the user can change it back to "pick"
if they change their mind.)

However, merge commits can't be changed to "drop", so we have to delete them
from the todo file. We add a new daemon instruction that does this.

We still don't allow deleting a merge commit from within an interactive rebase.
The reason is that we don't show the "label" and "reset" todos in lazygit, so
deleting a merge commit would leave the commits from the branch that is being
merged in the list as "pick" commits, with no indication that they are going to
be dropped because they are on a different branch, and the merge commit that
would have brought them in is gone. This could be very confusing.
2024-12-23 12:12:45 +01:00
Stefan Haller
64eb3d560b Simplify finding rebase todos
One of the comments we are deleting here said:

  // Comparing just the hash is not enough; we need to compare both the
  // action and the hash, as the hash could appear multiple times (e.g. in a
  // pick and later in a merge).

I don't remember what I was thinking when I wrote this code, but it's nonsense
of course. Maybe I was thinking that the hash that appears in a "merge" todo
would be the hash of the commit that is being merged in (which would then
actually appear in an earlier pick), but it isn't, it's the hash of the merge
commit itself (so that the rebase can reuse its commit message). Which means
that hashes are unique, no need to compare the action.
2024-12-23 12:12:45 +01:00
johannaschwarz
f455f99705 Add user config gui.showNumstatInFilesView
When enabled, it adds "+n -m" after each file in the Files panel to show how
many lines were added and deleted, as with `git diff --numstat` on the command
line.
2024-12-08 12:09:47 +01:00
Stefan Haller
7fb9e8fa9a Respect the diff context size when showing a range diff
This applies to both the "sticky" range diff when diffing mode is on, and the
more temporary one when selecting a range of commits.
2024-12-01 13:01:16 +01:00
Stefan Haller
5cca4c7063 Cleanup: move adding --ignore-all-space arg to DiffCmdObj
It is needed by both call sites of this function. This has the added benefit
that the argument doesn't unnecessarily show up in the status view when diffing
mode is on.
2024-12-01 13:01:15 +01:00
Stefan Haller
17bb3970c1 Filter out merge commits when generating todo changes in InteractiveRebase
We will need this because under some conditions we are going to use this
function to edit a range of commits, and we can't set merge commits to "edit".
This corresponds to the code in startInteractiveRebaseWithEdit which has similar
logic.

It is a bit unfortunate that we will have these two different ways of setting
todos to edit: startInteractiveRebaseWithEdit does it after stopping in the
rebase, in the Then function of its refresh, but InteractiveRebase does it in
the daemon with a ChangeTodoActionsInstruction. It still makes sense though,
given how InteractiveRebase works.

This not only affects "edit", but also "drop", "fixup", and "squash".
Previously, when trying to use these for a range selection that includes a merge
commit, they would fail with the cryptic error message "Some todos not found in
git-rebase-todo"; now they simply exclude the merge commit. I'm not sure if one
is better or worse than the other, and we should probably simply disable the
commands when a merge commit is selected, but that's out of scope in this PR.
2024-12-01 11:05:45 +01:00
Stefan Haller
c1b4201726 Allow deleting a range selection of branches
We allow deleting remote branches (or local and remote branches) only if *all*
selected branches have one.

We show the a warning about force-deleting as soon as at least one of the
selected branches is not fully merged.

The added test only tests a few of the most interesting cases; I didn't try to
cover the whole space of possible combinations, that would have been too much.
2024-12-01 10:59:54 +01:00
LU Jialin
de8dc935a3 use unsigned integer in test and fix CI/linter complaint 2024-11-19 08:21:19 +11:00
Stefan Haller
c712b1d0fe Better local branch delete confirmation
Currently we try to delete a branch normally, and if git returns an error and
its output contains the text "branch -D", then we prompt the user to force
delete, and try again using -D. Besides just being ugly, this has the
disadvantage that git's logic to decide whether a branch is merged is not very
good; it only considers a branch merged if it is either reachable from the
current head, or from its own upstream. In many cases I want to delete a branch
that has been merged to master, but I don't have master checked out, so the
current branch is really irrelevant, and it should rather (or in addition) check
whether the branch is reachable from one of the main branches. The problem is
that git doesn't know what those are.

But lazygit does, so make the check on our side, prompt the user if necessary,
and always use -D. This is both cleaner, and works better.

See this mailing list discussion for more:
https://lore.kernel.org/git/bf6308ce-3914-4b85-a04b-4a9716bac538@haller-berlin.de/
2024-09-28 11:19:32 +02:00
Stefan Haller
3d56357294 Fix copying commit author to clipboard
This was a regression introduced with the GitCommandBuilder in 25f8b0337.
2024-09-23 09:47:14 +02:00
Stefan Haller
b22149d832 Create fixup commit at end of its branch when there's a stack of branches 2024-09-15 11:19:39 +02:00
Stefan Haller
396215a5c9 Extract helper function for getting the hash of the last commit made 2024-09-15 11:19:39 +02:00
Stefan Haller
42c157a5e6 Add changeToFixup field to MoveFixupCommitDown 2024-09-15 11:19:39 +02:00
Neko Box Coder
6a418c65ca Specifying branch name source from refs/heads for fast forwarding 2024-08-18 10:42:57 +02:00
Stefan Haller
fd8e480363 Re-determine existing main branches if mainBranches config changed 2024-08-18 10:24:52 +02:00
Stefan Haller
3d6d677453 Store Common instead of just the list of configured main branches in MainBranches
This will make it possible to change the configured main branches at runtime.
We'll support this in the next commit.
2024-08-18 10:24:52 +02:00
Stefan Haller
f98b57aa5e Change direct access to Common.UserConfig to a getter
This will allow us to turn the field into an atomic.Value for safe concurrent
access.
2024-08-18 10:24:52 +02:00
Stefan Haller
75a95865ff Use filepath instead of path for file path operations
In practice, using path seems to work too, since Windows seems to be capable of
dealing with a path like C:/x/y instead of C:\x\y; but it's cleaner to do this
properly.
2024-08-18 10:24:52 +02:00
Neko Box Coder
4a2508e960 Allow rewording for last commit using GPG 2024-08-16 13:08:31 +02:00
Neko Box Coder
ce6388bdfa Adding guard to not do reword under git_commands when using gpg 2024-08-15 08:54:23 +02:00
István Donkó
b9107d5fc8 Support setting the similarity threshold for detecting renames 2024-07-13 14:24:26 +10:00
John Whitley
7a670964cd Optimize number of early calls to GetRepoPaths
This change reduces the number of calls during application startup to
one, calling GetRepoPaths() earlier than previously and plumbing the
repoPaths struct around to achieve this end.
2024-07-06 12:09:48 -07:00
Martin Kock
be21328c69 Allow cycling between multiple log commands
- Introduced a new optional user config command, allBranchesLogCmds
- When pressing 'a' in the Status view, cycle between non-empty, non-identical log commands
- There will always be at least one command to run, since allBranhesLogCmd has a default
- Update documentation & write an integration test
- Update translation string
2024-07-06 22:02:47 +10:00
T.
b26ff43d9e Update tracking behaviour for branches created from remote branches
The current behaviour when creating a new branch off of a remote branch
is to always track the branch it was created from.

For example, if a branch 'my_branch' is created off of the remote branch
'fix_crash_13', then 'my_branch' will be tracking the remote
'fix_crash_13' branch.

It is common practice to have both the local and remote branches named
the same when the local is tracking the remote one. Therefore, it is
reasonable to expect that 'my_branch' should not track the remote
'fix_crash_13' branch.

The new behaviour when creating a new branch off of a remote branch is
to track the branch it was created from only if the branch names match.
If the branch names DO NOT match then the newly created branch will not
track the remote branch it was created from.

For example, if a user creates a new branch 'fix_crash_13' off of the
remote branch 'fix_crash_13', then the local 'fix_crash_13' branch will
track the remote 'fix_crash_13' branch.
However, if the user creates a new branch called 'other_branch_name' off
of the remote branch 'fix_crash_13', then the local 'other_branch_name'
branch will NOT track the remote 'fix_crash_13' branch.
2024-07-04 22:34:36 +02:00
Noah
232be05785 feat: squash merge 2024-06-30 11:01:03 +10:00
Stefan Haller
4cd15a36e3 Fix custom patch operations on added files
Several custom patch commands on parts of an added file would fail with the
confusing error message "error: new file XXX depends on old contents". These
were dropping the custom patch from the original commit, moving the patch to a
new commit, moving it to a later commit, or moving it to the index.

We fix this by converting the patch header from an added file to a diff against
an empty file. We do this not just for the purpose of applying the patch, but
also for rendering it and copying it to the clip board. I'm not sure it matters
much in these cases, but it does feel more correct for a filtered patch to be
presented this way.
2024-06-23 12:40:31 +02:00
Stefan Haller
899e25b208 Show "exec" todos in the list of rebase todos
Unfortunately it isn't possible to delete them. This would often be useful, but
our todo rewriting mechanisms rely on being able to find todos by some
identifier (hash for pick, ref for update-ref), and exec todos don't have a
unique identifier.
2024-06-12 12:44:33 +02:00
AzraelSec
6b9cf72e79 feat: support range selection for commit attributes amend 2024-06-07 23:09:52 +02:00
Stefan Haller
373b1970ca Show divergence from base branch in branches list 2024-06-03 13:59:43 +02:00
Stefan Haller
8c385731f7 Add GetBaseBranch function 2024-06-03 13:02:46 +02:00
Stefan Haller
e79b4259e4 Make GetMergeBase a method of ExistingMainBranches 2024-06-03 13:02:46 +02:00
Stefan Haller
f4d922bc80 Factor out CommitLoader.mainBranches into its own class, and store it in Model 2024-06-03 13:02:46 +02:00
Stefan Haller
b2011dca35 Remove the cache invalidation logic from getMergeBase
It is a valid case for a branch to share no history with any of the main
branches, in which case git merge-base returns an error (and an empty string).
Since we can't distinguish this from one of the main branches having been
deleted, we shouldn't invalidate the cache in that case.
2024-06-03 13:02:46 +02:00
Jordan
39ea5d9ab1 Add HEAD: when referencing upstream branch
Update unit tests
2024-06-02 09:02:33 +02:00
Stefan Haller
116c18e957 Use --force instead of --force-with-lease when remote is not stored locally
--force-with-lease simply doesn't work in this case, it will always return a
"stale info" error.
2024-06-01 08:12:45 +02:00
Stefan Haller
e93617b1de Rename Force to ForceWithLease
This describes better what it is, and we're going to add the regular --force in
the next commit.

No change in behavior in this commit.
2024-06-01 08:12:45 +02:00
Stefan Haller
d890c68cd0 Add ahead/behind information for @{push}
In a triangular workflow the branch that you're pulling from is not the same as
the one that you are pushing to. For example, some people find it useful to set
the upstream branch to origin/master so that pulling effectively rebases onto
master, and set the push.default git config to "current" so that "feature"
pushes to origin/feature.

Another example is a fork-based workflow where "feature" has upstream set to
upstream/main, and the repo has remote.pushDefault set to "origin", so pushing
on "feature" pushes to origin/feature.

This commit adds new fields to models.Branch that store the ahead/behind
information against the push branch; for the "normal" workflow where you pull
and push from/to the upstream branch, AheadForPush/BehindForPush will be the
same as AheadForPull/BehindForPull.
2024-05-19 09:44:38 +02:00
Stefan Haller
0aba686f97 Rename Pushables/Pullables to AheadForPull/BehindForPull
In preparation for adding AheadForPush/BehindForPush in the next commit.
2024-05-19 09:44:38 +02:00
Jesse Duffield
fdff2dec79 Remove redundant variable dedeclarations
In go 1.22, loop variables are redeclared with each iteration of the
loop, rather than simple updated on each iteration. This means that we
no longer need to manually redeclare variables when they're closed over
by a function.
2024-05-19 16:38:21 +10:00
dsolerhww
5b80c0c792 Fix stashing partialy staged files for git version >= 2.35.0
Use `git stash push --staged` git feature available on git version >
2.35.0.
2024-05-18 09:59:00 +02:00
Stefan Haller
e0a2d97f0f Put subject last in git log's prettyFormat
We are going to truncate overly long lines returned from git log, and the most
likely field that is going to make the line too long is the subject; so we must
put it last, otherwise we'd end up with not enough fields to split when it's too
long.

It might not be obvious from the diff what's happening to the mock command
output in the test: it didn't have the divergence field (">") at all, which was
kind of a bug. It didn't matter for these tests though, because we are not
testing the divergence here, and our production code happens to be resilient
against it missing. But now we must add the ">" field before the subject.
2024-05-15 13:27:01 +02:00