0

Need to pull information about metadata changes from the project in the git (there is a local copy), namely: The number of commits per file (code, metadata) for 2 weeks on a certain branch on the folder na_gold'force-app/main/default'

import os
import time
import git
import datetime

Changedata = {}

MY_PATH = os.chdir(r'C:\Users\vsi\int\sfdevops_metrics\.project\na_gold')
repo = git.Repo(MY_PATH)
repo.git.checkout('Staging')

I can't figure out how to do it yet, because there's not a word in the documentation

Miekrif
  • 55
  • 7
  • `os.chdir` does not return anything, so `MY_PATH` is just set to `None`. So you're calling `git.Repo(None)`, which is probably not going to work very well. As for the rest: once you have a handle on a repository, you'll need to enumerate the commits of interest, and inspect the files in them. This is probably a lot harder to do in Python than in the shell, but either way, that's a program you need to write. – torek Jan 11 '22 at 10:15
  • I can't agree with you, the script works properly with this line, since when reading only commits, it gives information – Miekrif Jan 11 '22 at 10:24
  • Perhaps `git.Repo(None)` means "use the current working directory", so that you're reading whatever repository you're in now. Ah: https://gitpython.readthedocs.io/en/stable/reference.html#module-git.repo.base says that if you provide `None`, `gitpython` checks `$GIT_DIR` in the environment first, and if that's not set, uses the current directory. This does not seem to be what you *want* though. (In particular, what do you want if `GIT_DIR` *is* set? As it is, you're relocating to the given directory, so that's what you want if it's *not* set.) – torek Jan 11 '22 at 10:28
  • If i format this line without os.chdir(), all still work and still give me same thing, all right, i do what you mean agree, thx for this but i want have info about change file(or metadata,code), in simple directory, how we can do this? – Miekrif Jan 11 '22 at 11:16
  • Consider command-line Git (I haven't used GitPython): we might run `git log --since=2.weeks.ago --name-status`. The output will show each commit plus, for each ordinary (non-merge) commit, the result of diffing the commit's parent vs the commit, with `--name-status` shown, so that we know for each file whether it's newly `A`dded, `R`enamed, `D`eleted, or `M`odified (or several other less likely status-es). – torek Jan 11 '22 at 11:46
  • Your job will be: take each such result and use it to accumulate information about each file. Translating the command-line version to GitPython is also part of your job here. – torek Jan 11 '22 at 11:47
  • if translate your example on python, we have this line for diff_mod in previous_commit.diff('Staging').iter_change_type('A'): print(diff_mod) but output empty – Miekrif Jan 11 '22 at 12:25
  • I haven't used GitPython, but `diff('Staging')` certainly seems wrong. You want a commit-vs-commit diff. – torek Jan 12 '22 at 01:04

1 Answers1

0

This line give info

file = repo.git.log('--since=2.weeks', '--name-only')

All scrip have next lines

import git
import re
import collections

j = collections.defaultdict(int)
Changedata = {}
#MY_PATH = '/home/bot_slack_git/na_gold/'
MY_PATH1 = r'C:\Users\vsi\int\sfdevops_metrics\.project\na_gold\force-app\main\default'
MY_PATH = r'C:\Users\vsi\int\na_gold'
repo = git.Repo(MY_PATH)
file = repo.git.log('--since=2.weeks', '--name-only')
Miekrif
  • 55
  • 7