LoginSignup
5
1

More than 1 year has passed since last update.

git-filter-repo NameError: name 'git' is not defined

Posted at

事象 : Scoopでインストールしたgit-filter-repoが動かない

  • 環境
    • Windows10 Pro バージョン21H1
    • git version 2.35.1.windows.1
    • Python 3.8.5
    • pip 20.2.4

git-filter-repoを使おうと思い「Scoopをインストール」して「Scoopでgit-filter-repoをインストール」しました。
しかし、エラーになって動きません。

# PowerShellに切替える
$ powershell
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

新しいクロスプラットフォームの PowerShell をお試しください https://aka.ms/pscore6

# セキュリティポリシーが初期値(Restricted)場合は、「RemoteSigned」へ変更する
PS C:\path\to> Get-ExecutionPolicy
Restricted     
PS C:\path\to> Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process

# Scoopをインストールする
PS C:\path\to> Invoke-Expression (New-Object System.Net.WebClient).DownloadString('https://get.scoop.sh')
Initializing...
Downloading...
Extracting...
Creating shim...
Adding ~\scoop\shims to your path.
Scoop was installed successfully!
Type 'scoop help' for instructions.

# 常用しているBashに切替える
PS C:\path\to> bash

# Scoopでgit-filter-repoをインストール
$ scoop install git-filter-repo
Installing 'git-filter-repo' (2.34.0) [64bit]
Downloading https://github.com/newren/git-filter-repo/archive/v2.34.0.zip (-1 B)...

Checking hash of v2.34.0.zip ... ok.
Extracting v2.34.0.zip ... done.
Running pre-install script...
Linking ~\scoop\apps\git-filter-repo\current => ~\scoop\apps\git-filter-repo\2.34.0
Creating shim for 'git-filter-repo'.
Running post-install script...
'git-filter-repo' (2.34.0) was installed successfully!
'git-filter-repo' suggests installing 'python'.

# しかし、動かない・・・・
$ git filter-repo -h
Traceback (most recent call last):
  File "C:\Users\chovin\scoop\apps\git-filter-repo\current\git_filter_repo.py", line 1, in <module>
    git-filter-repo
NameError: name 'git' is not defined

原因 : 不明

いろいろ調べても試しても状況は変わりらず、原因は分かりませんでした。

  1. 試したこと
    1. scoop/apps/git-filter-repo/2.34.0/git-filter-repoの1行目のシェ版を#!/usr/bin/env python3から#!/usr/bin/env pythonに変える
    2. ターミナルのシェルをBashではなくPowerShellにしてから、Scoopでgit-filter-repoをインストールする
    3. 既存のGitとは別にScoopでGitをインストールする
    4. 既存のPythonとは別にScoopでPythonをインストールする

対応 : pipでgit-filter-repoをインストールする

git-filter-repoのINSTALL.mdを見て深く考えずに「Scoop」を使ってインストールしました。

This list covers at least Windows (Scoop), Mac OS X (Homebrew), and Linux (most the rest). Note that I do not curate this list (and have no interest in doing so); https://repology.org tracks who packages these versions.
git-filter-repo/INSTALL.md

しかし、どうせPythonが必要になるのであればpipを使えばいいことに思い当たりました。この思い付きが功を奏しました。
参考 : git-filter-repo · PyPI

# Scoopのgit-filter-repoをアンインストールする
$ scoop uninstall git-filter-repo
Uninstalling 'git-filter-repo' (2.34.0).
Removing shim 'git-filter-repo'.
Removing shim 'git-filter-repo.cmd'.
Unlinking ~\scoop\apps\git-filter-repo\current
'git-filter-repo' was uninstalled.

# Scoop自体もアンインストールする
$ scoop uninstall scoop
WARN  This will uninstall Scoop and all the programs that have been installed with Scoop!
Are you sure? (yN): y
Removing ~\scoop\shims from your path.
Scoop has been uninstalled.

# pipでgit-filter-repoをインストールする
$ pip install git-filter-repo
Collecting git-filter-repo
  Downloading git_filter_repo-2.34.0-py2.py3-none-any.whl (99 kB)
     |████████████████████████████████| 99 kB 1.3 MB/s 
Installing collected packages: git-filter-repo
Successfully installed git-filter-repo-2.34.0
WARNING: You are using pip version 20.2.4; however, version 22.0.4 is available.
You should consider upgrading via the 'c:\apps\python38\python.exe -m pip install --upgrade pip' command.

# 動いた!
$ git filter-repo -h
Rewrite (or analyze) repository history

    git-filter-repo destructively rewrites history (unless --analyze or
    --dry-run are given) according to specified rules.  It refuses to do any
    rewriting unless either run from a clean fresh clone, or --force was
    given.
#...省略...
5
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
1