Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use git reset instead of git pull to avoid attempting a merge commit #8595

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

andersk
Copy link

@andersk andersk commented Mar 9, 2021

Summary

Use git reset instead of git pull to avoid attempting a merge commit. Also, use git remote set-head in case the repository’s default branch has been renamed.

Fixes #5303.

Test plan

Tested with this reproduction script:

#!/usr/bin/env bash
set -eux
tmpdir="$(mktemp -dt)"
trap 'rm -rf "$tmpdir"' EXIT
cd "$tmpdir"

git init some-library
cd some-library
echo '{"name": "some-library", "version": "1.0.0"}' > package.json
git add package.json
git commit -am 'Initial commit'
echo '{"name": "some-library", "version": "1.0.1"}' > package.json
git commit -am 'Bump version'
some_library="git+file://$PWD"

mkdir ../my-app
cd ../my-app
echo '{}' > package.json
XDG_CONFIG_HOME="$tmpdir" yarn add "$some_library"

cd ../some-library
echo '{"name": "some-library", "version": "1.0.2"}' > package.json
git commit --amend -am 'Force push'

# Uncomment to test branch rename:
#git branch -m develop

cd ../my-app
XDG_CONFIG_HOME="$tmpdir" yarn add "$some_library"

Without this fix, the second yarn add fails with:

+ yarn add git+file:///tmp/tmp.8JjoQJZXLa/some-library
yarn add v1.22.10
warning package.json: No license field
warning No license field
[1/4] Resolving packages...
error Command failed.
Exit code: 128
Command: git
Arguments: pull
Directory: /home/anders/.cache/yarn/v6/.tmp/ea609cd4e4a2249a3f41d450a33f8312
Output:
hint: Pulling without specifying how to reconcile divergent branches is
hint: discouraged. You can squelch this message by running one of the following
hint: commands sometime before your next pull:
hint: 
hint:   git config pull.rebase false  # merge (the default strategy)
hint:   git config pull.rebase true   # rebase
hint:   git config pull.ff only       # fast-forward only
hint: 
hint: You can replace "git config" with "git config --global" to set a default
hint: preference for all repositories. You can also pass --rebase, --no-rebase,
hint: or --ff-only on the command line to override the configured default per
hint: invocation.
Committer identity unknown

*** Please tell me who you are.

Run

  git config --global user.email "[email protected]"
  git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

fatal: unable to auto-detect email address (got 'anders@virtual-fork.(none)')
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.

Even if one provides the requested Git configuration first, it still fails:

+ yarn add git+file:///tmp/tmp.bxRQFzTmbn/some-library
yarn add v1.22.10
warning package.json: No license field
warning No license field
[1/4] Resolving packages...
error Command failed.
Exit code: 1
Command: git
Arguments: pull
Directory: /home/anders/.cache/yarn/v6/.tmp/ed8d0fef0fcae909d28ca542249075a8
Output:
hint: Pulling without specifying how to reconcile divergent branches is
hint: discouraged. You can squelch this message by running one of the following
hint: commands sometime before your next pull:
hint: 
hint:   git config pull.rebase false  # merge (the default strategy)
hint:   git config pull.rebase true   # rebase
hint:   git config pull.ff only       # fast-forward only
hint: 
hint: You can replace "git config" with "git config --global" to set a default
hint: preference for all repositories. You can also pass --rebase, --no-rebase,
hint: or --ff-only on the command line to override the configured default per
hint: invocation.
Auto-merging package.json
CONFLICT (content): Merge conflict in package.json
Automatic merge failed; fix conflicts and then commit the result.
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.

With this fix, it works correctly with or without the Git configuration:

+ yarn add git+file:///tmp/tmp.IehTe8fiZv/some-library
yarn add v1.23.0-0
warning package.json: No license field
warning No license field
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
warning No license field
success Saved 1 new dependency.
info Direct dependencies
└─ [email protected]
info All dependencies
└─ [email protected]
Done in 0.27s.

Also, use git remote set-head in case the repository’s default branch
has been renamed.

Fixes yarnpkg#5303.

Signed-off-by: Anders Kaseorg <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can't install project when yarn cache is present and no global git user is configured
1 participant