git » git-arr » commit df00293

git: Add '--' to "git rev-list" runs to avoid ambiguous arguments

author Alberto Bertogli
2014-12-31 17:01:28 UTC
committer Alberto Bertogli
2014-12-31 17:07:38 UTC
parent 7898b2becdc9ad35b0d853bc5d46be24a05a6a48

git: Add '--' to "git rev-list" runs to avoid ambiguous arguments

If there is a branch and a file with the same name, git-arr will fail to
generate, as git will complain when running git rev-list.

For example, if there is both a file and a branch called "hooks" in the
repository, git-arr would fail as follows:

=== git-arr running: ['git', '--git-dir=/some/repo', 'rev-list', '--max-count=1', '--header', u'hooks'])
fatal: ambiguous argument 'hooks': both revision and filename
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
Traceback (most recent call last):
  File "./git-arr", line 457, in <module>
    main()
  File "./git-arr", line 452, in main
    skip_index = len(opts.only) > 0)
  File "./git-arr", line 388, in generate
    branch_mtime = r.commit(bn).committer_date.epoch
AttributeError: 'NoneType' object has no attribute 'committer_date'

To fix that, this patch appends a "--" as the last argument to rev-list, which
indicates that it has completed the revision list, which disambiguates the
argument.

While at it, a minor typo in a comment is also fixed.

Signed-off-by: Alberto Bertogli <albertito@blitiri.com.ar>

git-arr +1 -1
git.py +2 -0

diff --git a/git-arr b/git-arr
index 418f883..b9c9d46 100755
--- a/git-arr
+++ b/git-arr
@@ -380,7 +380,7 @@ def generate(output, skip_index = False):
 
             # To avoid regenerating files that have not changed, we will
             # instruct write_to() to set their mtime to the branch's committer
-            # date, and then compare against it to decide wether or not to
+            # date, and then compare against it to decide whether or not to
             # write.
             branch_mtime = r.commit(bn).committer_date.epoch
 
diff --git a/git.py b/git.py
index 8aa9eb1..bddca70 100644
--- a/git.py
+++ b/git.py
@@ -253,6 +253,7 @@ class Repo:
             cmd.max_count = limit
 
         cmd.arg(ref)
+        cmd.arg('--')
 
         for l in cmd.run():
             yield l.rstrip('\n')
@@ -273,6 +274,7 @@ class Repo:
         cmd.header = None
 
         cmd.arg(ref)
+        cmd.arg('--')
 
         info_buffer = ''
         count = 0