Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Use --work-tree in 'native' git method #162

Closed
wants to merge 2 commits into from

2 participants

Andreas Loupasakis Brandon Keepers
Andreas Loupasakis

There are cases like e.g. when we want to git diff origin/master to inspect the changes between the local working directory and another commit/head/whatever, in which the command is executed in a folder other than the repository's one. So, even if the --git-dir argument is passed correctly the working directory is not identified as it should and the working dir diff is returned taking into account the PWD. This is fixed by passing the --work-tree parameter with the correct value to the git options.

alup added some commits
Andreas Loupasakis alup Use work_dir option to let the user pass the work_tree as arg
This may help in specific cases e.g. when we want to issue a diff
request like "git diff origin/master" for a repository in a different
folder than the PWD.
bd21fac
Andreas Loupasakis alup Fix spec to take into account the new work_dir option e97f137
Andreas Loupasakis

@rtomayko any chance this to get merged :)?

Brandon Keepers
Collaborator

Grit is no longer maintained. See #183 and check out libgit2/rugged.

Brandon Keepers bkeepers closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 2, 2013
  1. Andreas Loupasakis

    Use work_dir option to let the user pass the work_tree as arg

    alup authored
    This may help in specific cases e.g. when we want to issue a diff
    request like "git diff origin/master" for a repository in a different
    folder than the PWD.
  2. Andreas Loupasakis
This page is out of date. Refresh to see the latest.
Showing with 14 additions and 5 deletions.
  1. +10 −4 lib/grit/git.rb
  2. +4 −1 test/test_git.rb
14 lib/grit/git.rb
View
@@ -282,6 +282,9 @@ def apply_patch(options={}, head_sha=nil, patch=nil)
# use that number of seconds; when false or 0, disable timeout.
# :base - Set false to avoid passing the --git-dir argument when
# invoking the git command.
+ # :work_dir - Set false to avoid passing the --work-tree argument when
+ # invoking the git command. (GIT_WORK_TREE or --work-tree=<directory> is
+ # not allowed without specifying GIT_DIR or --git-dir=<directory>.)
# :env - Hash of environment variable key/values that are set on the
# child process.
# :raise - When set true, commands that exit with a non-zero status
@@ -325,15 +328,18 @@ def native(cmd, options = {}, *args, &block)
return run(prefix, cmd, '', options, args) if args[-1].to_s[0] == ?|
# more options
- input = options.delete(:input)
- timeout = options.delete(:timeout); timeout = true if timeout.nil?
- base = options.delete(:base); base = true if base.nil?
- chdir = options.delete(:chdir)
+ input = options.delete(:input)
+ timeout = options.delete(:timeout); timeout = true if timeout.nil?
+ base = options.delete(:base); base = true if base.nil?
+ work_dir = options.delete(:work_dir); work_dir = true if work_dir.nil?
+ chdir = options.delete(:chdir)
# build up the git process argv
argv = []
argv << Git.git_binary
argv << "--git-dir=#{git_dir}" if base
+ # GIT_WORK_TREE (or --work-tree=<directory>) not allowed without specifying GIT_DIR (or --git-dir=<directory>)
+ argv << "--work-tree=#{work_tree}" if work_dir && base
argv << cmd.to_s.tr('_', '-')
argv.concat(options_to_argv(options))
argv.concat(args)
5 test/test_git.rb
View
@@ -114,7 +114,10 @@ def test_fs_delete
def test_passing_env_to_native
args = [
{ 'A' => 'B' },
- Grit::Git.git_binary, "--git-dir=#{@git.git_dir}", "help", "-a",
+ Grit::Git.git_binary,
+ "--git-dir=#{@git.git_dir}",
+ "--work-tree=#{@git.work_tree}",
+ "help", "-a",
{:input => nil, :chdir => nil, :timeout => Grit::Git.git_timeout, :max => Grit::Git.git_max_size}
]
p = Grit::Git::Child.new(*args)
Something went wrong with that request. Please try again.