2

im currently working on a program, which should control a git repository through pexpect.

Simple commands like git status are working, but commands like git diff --name-status ... don't. I get the following error message: WARNING: terminal is not fully functional.

All the solutions i've found, were to fix the problem on Windows or Mac.

Heres a codesnippet from my program:

my_bash = pexpect.spawn('/bin/bash', cwd="/home/xxx/clone_repo/local.repo/")
my_bash.logfile = sys.stdout
my_bash.sendline(git diff --name-status branch1 branch2)

Does someone know a solution to this problem? Can i run pexpect with a more functional terminal for example?

greetings Johnny

KevKosDev
  • 811
  • 2
  • 9
  • 31

1 Answers1

3

I get the following error message: WARNING: terminal is not fully functional.

That's a warning, not an error.

Can i run pexpect with a more functional terminal for example?

You could (see, e.g., https://github.com/docker/docker/issues/8631; note that it's critical that you mention details like OS and environment; I am just guessing here)—but unless you are writing tests that must behave like a human being interacting on a terminal, you should not bother. To drive Git from programs, use the parts of Git that are designed to be program-driven. Instead of git diff, run git diff-tree, for instance:

my_bash = pexpect.spawn('/bin/bash', cwd="/home/xxx/clone_repo/local.repo/")
my_bash.logfile = sys.stdout
my_bash.sendline('git diff --name-status branch1 branch2')

you can do this:

proc = subprocess.Popen(['git', 'diff-tree', '-r',
                         '--name-status', 'branch1', 'branch2'],
                         shell=False, cwd='/home/xxx/clone_repo/local.repo')

out, err = proc.communicate()
status = proc.wait()

and then work with the results from this. You get more direct control over the program, and by using git diff-tree, which is a "plumbing command", you get output that is designed to be machine-readable. See Which are the plumbing and porcelain commands?

(By using shell=False you also guard against a common security issue.)

Community
  • 1
  • 1
torek
  • 448,244
  • 59
  • 642
  • 775