
from __future__ import print_function
import shutil, tempfile
from subprocess import check_call

class Git:
  def __init__(self, dir):
    self.dir = dir

  def __call__(self, *args):
    check_call(['git'] + list(args), cwd=self.dir)

dir = tempfile.mkdtemp()
try:
  git = Git(dir)
  git('clone', '-b', 'coverity', 'git@github.com:cppformat/cppformat.git', dir)
  git('merge', '-X', 'theirs', '--no-commit', 'origin/master')
  git('reset', 'HEAD', '.travis.yml')
  git('checkout', '--', '.travis.yml')
  git('commit', '-m', 'Update coverity branch')
  git('push')
finally:
  shutil.rmtree(dir)


from __future__ import print_function
import shutil, tempfile
from subprocess import check_output, STDOUT

class Git:
  def __init__(self, dir):
    self.dir = dir

  def __call__(self, *args):
    output = check_output(['git'] + list(args), cwd=self.dir, stderr=STDOUT)
    print(output)
    return output

dir = tempfile.mkdtemp()
try:
  git = Git(dir)
  git('clone', '-b', 'coverity', 'git@github.com:cppformat/cppformat.git', dir)
  output = git('merge', '-X', 'theirs', '--no-commit', 'origin/master')
  if 'Fast-forward' not in output:
    git('reset', 'HEAD', '.travis.yml')
    git('checkout', '--', '.travis.yml')
    git('commit', '-m', 'Update coverity branch')
  git('push')
finally:
  shutil.rmtree(dir)

Handle fast forward in update-coverity-branch.py
Handle fast forward in update-coverity-branch.py
  
  from __future__ import print_function
  import shutil, tempfile
- from subprocess import check_call
+ from subprocess import check_output, STDOUT
  
  class Git:
    def __init__(self, dir):
      self.dir = dir
  
    def __call__(self, *args):
-     check_call(['git'] + list(args), cwd=self.dir)
+     output = check_output(['git'] + list(args), cwd=self.dir, stderr=STDOUT)
+     print(output)
+     return output
  
  dir = tempfile.mkdtemp()
  try:
    git = Git(dir)
    git('clone', '-b', 'coverity', 'git@github.com:cppformat/cppformat.git', dir)
-   git('merge', '-X', 'theirs', '--no-commit', 'origin/master')
+   output = git('merge', '-X', 'theirs', '--no-commit', 'origin/master')
+   if 'Fast-forward' not in output:
-   git('reset', 'HEAD', '.travis.yml')
+     git('reset', 'HEAD', '.travis.yml')
-   git('checkout', '--', '.travis.yml')
+     git('checkout', '--', '.travis.yml')
-   git('commit', '-m', 'Update coverity branch')
+     git('commit', '-m', 'Update coverity branch')
    git('push')
  finally:
    shutil.rmtree(dir)
  
Handle fast forward in update-coverity-branch.py
## Code Before:

from __future__ import print_function
import shutil, tempfile
from subprocess import check_call

class Git:
  def __init__(self, dir):
    self.dir = dir

  def __call__(self, *args):
    check_call(['git'] + list(args), cwd=self.dir)

dir = tempfile.mkdtemp()
try:
  git = Git(dir)
  git('clone', '-b', 'coverity', 'git@github.com:cppformat/cppformat.git', dir)
  git('merge', '-X', 'theirs', '--no-commit', 'origin/master')
  git('reset', 'HEAD', '.travis.yml')
  git('checkout', '--', '.travis.yml')
  git('commit', '-m', 'Update coverity branch')
  git('push')
finally:
  shutil.rmtree(dir)

## Instruction:
Handle fast forward in update-coverity-branch.py
## Code After:

from __future__ import print_function
import shutil, tempfile
from subprocess import check_output, STDOUT

class Git:
  def __init__(self, dir):
    self.dir = dir

  def __call__(self, *args):
    output = check_output(['git'] + list(args), cwd=self.dir, stderr=STDOUT)
    print(output)
    return output

dir = tempfile.mkdtemp()
try:
  git = Git(dir)
  git('clone', '-b', 'coverity', 'git@github.com:cppformat/cppformat.git', dir)
  output = git('merge', '-X', 'theirs', '--no-commit', 'origin/master')
  if 'Fast-forward' not in output:
    git('reset', 'HEAD', '.travis.yml')
    git('checkout', '--', '.travis.yml')
    git('commit', '-m', 'Update coverity branch')
  git('push')
finally:
  shutil.rmtree(dir)
