Requirement:
- Commit and push files to GitHub repository from a python script.
- The credentials should be included in the script.
Issue:
- If credentials are provided in the script the commit operation is executing and throwing the following error,
Traceback (most recent call last): File "/home/amith/example.py", line 14, in <module> repo.index.add(folder_path) AttributeError: 'Repository' object has no attribute 'index'
- If credentials are, not provided in the script the commit operation is working properly by providing it on the terminal.
I need to integrate this script in Django application which should accept the credentials from the configuration file.
I have tried the following links but nothing has worked for me yet. - link1 - link2 - link3
from git import Repo
from github import Github
from pdb import set_trace as bp
repo_dir = '--------'
repo = Repo(repo_dir)
# using username and password
g = Github("-----", "------")
folder_path = '----------'
commit_message = 'Add New file'
repo.index.add(folder_path)
repo.index.commit(commit_message)
origin = repo.remote('origin')
origin.push()
So, I am getting this error "AttributeError: 'Repository' object has no attribute 'index'".
Complete error -
Traceback (most recent call last):
File "/home/amith/example.py", line 14, in <module>
repo.index.add(folder_path)
AttributeError: 'Repository' object has no attribute 'index'
repo
variable actually contains? Ideally, just before the exception is thrown, i.e. on line 14? – Aerostatics