是否存在查看捆绑程序中git命令的日志?

时间:2019-04-17 16:26:36

标签: ruby git bundler

我正在使用bundle install从公共和私有git仓库混合安装一些Ruby gem。

问题在于,通过git安装一个特定的gem之后,本地目录会被该gem的源代码污染。就像git repo已经完全改变了。

是否有办法记录捆绑程序正在运行的所有git命令,并确保将gem的git存储库放入正确的路径?

  1. 向Gemfile添加新的宝石
  2. 运行bundle install
  3. 检查README.markdown,现在其中的文本完全不同:

    # activerecord-import [![Build Status](https://travis-ci.org/zdennis/activerecord-import.svg?branch=master)](https://travis-ci.org/zdennis/activerecord-import)
    

要恢复我的仓库,我先运行git reflog,然后运行git reset --hard来获取正确的提交。看来在安装捆绑软件期间,git命令运行正在对特定分支进行检出,该分支将覆盖git repo中的所有文件。

2 个答案:

答案 0 :(得分:2)

我不知道这是否可以帮助您解决实际问题,但问题的答案是,您可以通过设置git环境变量来查看所有GIT_TRACE命令正在执行。在macOS,Linux等上,其外观类似于GIT_TRACE=1 bundle install。在Windows上,该方法将有所不同。

以下是具有一个依赖项的全新Gemfile的输出:

$ cat Gemfile
# frozen_string_literal: true
source "https://rubygems.org"
gem 'rack', git: 'https://github.com/rack/rack'

$ GIT_TRACE=1 bundle install
Fetching https://github.com/rack/rack
12:43:02.753769 git.c:415               trace: built-in: git clone https://github.com/rack/rack /Users/jordanr/.rbenv/gems/2.6.0/cache/bundler/git/rack-02d63969ed912ff0486a199e1ea3aa78127fbb67 --bare --no-hardlinks --quiet
12:43:02.800426 run-command.c:637       trace: run_command: unset GIT_DIR; ssh git@github.com 'git-upload-pack '\''rack/rack'\'''
12:43:06.059759 run-command.c:637       trace: run_command: git index-pack --stdin --fix-thin '--keep=fetch-pack 23789 on jordanr.local' --check-self-contained-and-connected
12:43:06.067881 git.c:415               trace: built-in: git index-pack --stdin --fix-thin '--keep=fetch-pack 23789 on jordanr.local' --check-self-contained-and-connected
12:43:06.945711 run-command.c:637       trace: run_command: git rev-list --objects --stdin --not --all --quiet
12:43:06.951101 git.c:415               trace: built-in: git rev-list --objects --stdin --not --all --quiet
12:43:06.974513 git.c:415               trace: built-in: git rev-parse --verify master
12:43:06.991681 git.c:415               trace: built-in: git fetch --force --quiet --tags /Users/jordanr/.rbenv/gems/2.6.0/cache/bundler/git/rack-02d63969ed912ff0486a199e1ea3aa78127fbb67
12:43:06.993341 run-command.c:637       trace: run_command: unset GIT_PREFIX; 'git-upload-pack '\''/Users/jordanr/.rbenv/gems/2.6.0/cache/bundler/git/rack-02d63969ed912ff0486a199e1ea3aa78127fbb67'\'''
12:43:07.000949 git.c:415               trace: built-in: git upload-pack /Users/jordanr/.rbenv/gems/2.6.0/cache/bundler/git/rack-02d63969ed912ff0486a199e1ea3aa78127fbb67
12:43:07.012806 run-command.c:637       trace: run_command: git rev-list --objects --stdin --not --all --quiet
12:43:07.022792 run-command.c:637       trace: run_command: git rev-list --objects --stdin --not --all --quiet
12:43:07.027701 git.c:415               trace: built-in: git rev-list --objects --stdin --not --all --quiet
12:43:07.034718 run-command.c:1553      run_processes_parallel: preparing to run up to 1 tasks
12:43:07.034753 run-command.c:1585      run_processes_parallel: done
12:43:07.034796 run-command.c:637       trace: run_command: git gc --auto --quiet
12:43:07.039832 git.c:415               trace: built-in: git gc --auto --quiet
12:43:07.050538 git.c:415               trace: built-in: git reset --hard 23580211825877c7ed3be5dd4f2996e67aa40a4e
12:43:07.074736 git.c:415               trace: built-in: git version
12:43:07.085179 git.c:659               trace: exec: git-submodule deinit --all --force
12:43:07.086081 run-command.c:637       trace: run_command: git-submodule deinit --all --force
12:43:07.124885 git.c:659               trace: exec: git-sh-i18n--envsubst --variables 'usage: $dashless $USAGE'
12:43:07.125490 run-command.c:637       trace: run_command: git-sh-i18n--envsubst --variables 'usage: $dashless $USAGE'
12:43:07.138222 git.c:659               trace: exec: git-sh-i18n--envsubst 'usage: $dashless $USAGE'
12:43:07.138930 run-command.c:637       trace: run_command: git-sh-i18n--envsubst 'usage: $dashless $USAGE'
12:43:07.158914 git.c:415               trace: built-in: git rev-parse --git-dir
12:43:07.166961 git.c:415               trace: built-in: git rev-parse --git-path objects
12:43:07.173881 git.c:415               trace: built-in: git rev-parse -q --git-dir
12:43:07.187418 git.c:415               trace: built-in: git rev-parse --show-prefix
12:43:07.193585 git.c:415               trace: built-in: git rev-parse --show-toplevel
12:43:07.203435 git.c:415               trace: built-in: git submodule--helper deinit --force --all
Fetching gem metadata from https://rubygems.org/
Resolving dependencies...
Using bundler 2.0.1
Using rack 2.1.0 from https://github.com/rack/rack (at master@2358021)
Bundle complete! 1 Gemfile dependency, 2 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.

答案 1 :(得分:1)

看起来问题出在gem和捆绑器上,一次建议使用git ls-files来获取gemspec文件中属于gem的所有文件的列表。

更改gemspec.files以使用Dir.glob似乎是解决方案。

有关捆绑程序github存储库的更多信息:https://github.com/bundler/bundler/issues/2287