0

I am trying to write a basic script that is pulling replicating the contents of one directory into another one, but making some modifications along the way. The items written in the new directory are then committed to a git repo.

import git

repo = git.Repo("/path/to/repo")
repo.index.add(["list","of","files"])
commit = repo.index.commit=(message="foo Bar")

But when I navigate to that destination directory and run git status it shows that all the newly written files are untracked. I have previously pushed the commit generate in the method above to a remote successfully, but cannot figure out why the commit appears, for lack of a better way of saying, to have not been written to disk.

I have tried passing the message with and without an explicit argument assignment, as well as with and without author information.

2
  • Does repo refer to git.Repo('/path/to/destination/directory/')?
    – ElpieKay
    Commented Oct 13, 2023 at 1:22
  • @ElpieKay, yes. I'll flesh out the example code.
    – Panduar
    Commented Oct 13, 2023 at 13:54

1 Answer 1

0

I figured it out. The paths being added need to be relative to the CWD or else absolute. I had thought they were supposed to be relative to the root directory of the repository, since all of the paths of the blobs in the repository object are.

import git, os

# setup paths
repo_path = "/path/to/repo"
relative_paths = ["CHANGELOG","README.md","VERSION"]
absolute_paths = [os.path.join(repo_path, path) for path in relative_paths]

# create Repo obj
repo = git.Repo(repo_path)

# add files to repo
repo.index.add(absolute_paths)

# commit changes
commit = repo.commit("commit message goes here")

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.