git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* `git checkout` is not a no-op as documented
@ 2022-04-04 16:27 Maximilian Reichel
  0 siblings, 0 replies; only message in thread
From: Maximilian Reichel @ 2022-04-04 16:27 UTC (permalink / raw)
  To: git

Thank you for filling out a Git bug report!
Please answer the following questions to help us understand your issue.

What did you do before the bug happened? (Steps to reproduce your issue)
Running the following commands:
```
#!/bin/bash
git -c init.defaultBranch=master init workDir
cd workDir
git commit --allow-empty -m first
git checkout -b other
git commit --allow-empty -m second
git checkout master
git merge --no-ff --no-commit other
git merge # shows merge in progress
git checkout # should be no-op
git merge # shows no merge in progress
git commit --no-edit # fails
```

What did you expect to happen? (Expected behavior)
I tried to merge another branch with `--no-ff --no-commit` but used the checkout command before commiting the changes.
Since the documentation states:
> You could omit <branch>, in which case the command degenerates to "check out the current branch",
> which is a glorified no-op with rather expensive side-effects to show only the tracking information,
> if exists, for the current branch.
I expected that the checkout with omitted <branch> only shows the tracking information and does not change the current states since it is advertised as a no-op.
So I expected the following output:
```
Initialized empty Git repository in /test/workDir/.git/
[master (root-commit) c521e9e] first
Switched to a new branch 'other'
[other 617af42] second
Switched to branch 'master'
Automatic merge went well; stopped before committing as requested
fatal: You have not concluded your merge (MERGE_HEAD exists).
Please, commit your changes before you merge.
fatal: You have not concluded your merge (MERGE_HEAD exists).
Please, commit your changes before you merge.
[master d2d6409] Merge branch 'other'
```


What happened instead? (Actual behavior)
After running the checkout command, I can longer use `git commit` to finish the merge and commit the changes.
I got the following output:
```
Initialized empty Git repository in /test/workDir/.git/
[master (root-commit) c521e9e] first
Switched to a new branch 'other'
[other 617af42] second
Switched to branch 'master'
Automatic merge went well; stopped before committing as requested
fatal: You have not concluded your merge (MERGE_HEAD exists).
Please, commit your changes before you merge.
fatal: No remote for the current branch.
On branch master
nothing to commit, working tree clean
```

What's different between what you expected and what actually happened?
I expected `git checkout` to only show the tracking information as stated in the documentation.


Anything else you want to add:
I tested this on git 2.35.1 and 2.21.0, which are both affected. 

[System Info]
git version:
git version 2.35.1
cpu: x86_64
built from commit: 4c53a8c20f8984adb226293a3ffd7b88c3f4ac1a
sizeof-long: 8
sizeof-size_t: 8
shell-path: /bin/sh
uname: Linux 5.10.25-linuxkit #1 SMP Tue Mar 23 09:27:39 UTC 2021 x86_64
compiler info: gnuc: 10.2
libc info: glibc: 2.31
$SHELL (typically, interactive shell): <unset>


[Enabled Hooks]
not run from a git repository - no hooks to show

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-04-04 21:23 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-04 16:27 `git checkout` is not a no-op as documented Maximilian Reichel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).