Skip to content
This repository has been archived by the owner on Jul 4, 2023. It is now read-only.

update-bash: git related improvement #48508

Closed
wants to merge 1 commit into from
Closed

update-bash: git related improvement #48508

wants to merge 1 commit into from

Conversation

xu-cheng
Copy link
Member

  • Use git function instead of refreshing bash cache on git path.
  • Better which_git:
    • Set HOMEBREW_GIT as result.
    • Take user's setting of HOMEBREW_GIT and GIT env variable into
      account.

cc @MikeMcQuaid @UniqMartin

@@ -2,22 +2,38 @@ brew() {
"$HOMEBREW_BREW_FILE" "$@"
}

git() {
"$HOMEBREW_GIT" "$@"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might want to run which_git if this isn't already set.

@xu-cheng
Copy link
Member Author

Updated and tested locally.

@@ -2,22 +2,41 @@ brew() {
"$HOMEBREW_BREW_FILE" "$@"
}

git() {
[[ -z "$HOMEBREW_GIT" ]] && HOMEBREW_GIT="$(which_git 2>/dev/null)"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should just error out if it's empty; it won't produce an error as-is.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder that we should add set -e and set -o pipefail in bin/brew. It's important especially in subshell.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is it's not very user friendly; things will just fail and it's nearly impossible to tell what and why.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But without it, error here when git is run in subshell will have strange result.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeh, I get that, I just think it's a pretty major change that should be handled in another PR along with e.g. a trap to improve the messaging.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🆒

@xu-cheng
Copy link
Member Author

Any comment before I 🚢


if [[ -n "$git_path" ]]
then
git_path="$(chdir "${git_path%/*}" && pwd -P)/${git_path##*/}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure ${git_path%/*} behaves the same as dirname? I'd probably rather we used dirname and the raw git string here; the performance implications are minimal (this is not a critical path) and the readability is better using them.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure ${git_path%/*} behaves the same as dirname?

Yes. In fact, we use this for years in bin/brew.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It behaves differently if the string doesn't contain a slash at all, but otherwise it's doing the same. For the mentioned case dirname will return . while ${git_path%/*} will return the original string.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I will change it to dirname when pulling.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I will change it to dirname when pulling.

That's not what I was trying to imply. Does it make sense to have something like git-2.2 in one of the variables, with the expectation that it will be looked up in PATH? If yes, the whole construct doesn't make sense and will fail, no matter if we use dirname or not.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about:

  if [[ -n "$HOMEBREW_GIT" ]]
  then
    git_path="$HOMEBREW_GIT"
  elif [[ -n "$GIT" ]]
  then
    git_path="$GIT"
  else
    git_path="git"
  fi

  git_path="$(which "$git_path" 2>/dev/null)"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like something that would work in all scenarios I can currently think of. And it should be guaranteed to return a path that contains a slash. 👍

@MikeMcQuaid
Copy link
Member

One comment otherwise 👍

@@ -2,22 +2,41 @@ brew() {
"$HOMEBREW_BREW_FILE" "$@"
}

git() {
[[ -n "$HOMEBREW_GIT" ]] || exit 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use odie instead?

* Use git function instead of refreshing bash cache on `git` path.
* Better `which_git`:
  * Take user's setting of `HOMEBREW_GIT` and `GIT` env variable into
    account.
  * Always expand git path.
  * Only check Xcode installation for OS X.
@xu-cheng xu-cheng closed this in e942726 Jan 28, 2016
@xu-cheng xu-cheng deleted the bash-git branch January 28, 2016 11:06
@Homebrew Homebrew locked and limited conversation to collaborators Jul 10, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants