How to get updated files via gitpython? - gitpython

I'm trying to get the paths of all the changed files in this current branch, compared to master.
I've tried
repo = Repo("path/to/repo")
files_changed = [item.a_path for item in repo.index.diff("master").iter_change_type("D")]
for f in files_changed:
print(f)
and I have few questions about the results:
When using R iter_change_type to get the files that are renamed, it only gives the new path. How do I get the original path of the file?
When using D iter_change_type, it gives all the files that are added instead of deleted. And A iter_change_type gives all the files that are deleted instead of added. Shouldn't this be the other way around?

Related

How to be able to find folders whose name keeps changing in shell/bash?

So I'm looking for a way for my shell to find the folder with the code behind the folder name that keeps changing, in the data/app/ folder, for example the folder "com.tencent.ig-yHGLSvh42dYO-GNMFS9WxA==". Which always changes only in the part after "com.tencent.ig-", the second "-" and "==". Full path "data/app/com.tencent.ig-yHGLSvh42dYO-GNMFS9WxA==/"
Code that can find the location of a folder so I can change the contents of that folder. If possible the code is contained in a variable so I can use it like so:
findfolder = (Code)؜
؜printf $findfolder

How do you delete a file with gitPython

How do you delete a file with gitPython?
repo.delete([file_to_delete])
says that there is no delete method.
The problem I had was that I was deleting the file from the repository but not the working tree. The answer is to do the following:
repo.index.remove([file_to_delete],working_tree = True)
Without the working_tree argument the file is left in the working tree even though it is not in the repository.

Create a directory structure from a path in gradle/groovy

I am implementing a diff package generation task in my project's gradle build from the git command line output. Currently I have a method which will give me a list of changed files from git diff --name-only. What I would like to do is create a directory structure in a new directory which matches the paths of each file. For example: inputting the string repo/dir/file.java would create in an output directory if not already created and inside it the directories head/repo/dir with the current file.java and prev/repo/dir with the previous file.java.
My current plan is to split the string repo/dir/file.java on the forward slash, and create directories until the last element of the split result, then write the file there. but nothing I have been able to come up with in gradle is nice or clean. I am wondering if there is a nicer way to create directories from a string like that.
My current plan is to split the string repo/dir/file.java on the forward slash, and create directories until the last element of the split result
Rather than splitting your string manually, you could try using File.mkdirs():
File newDirectoryStructureParent = new File('some/path/to/parent/dir')
def s = 'repo/dir/file.java'
def newContainer = new File(s, newDirectoryStructureParent).getParent()
newContainer.mkdirs()
everyone
In this part of my code you can just work around Path not File!
At the first you can define Path and second need check that path exist or not, if not mkdirs can make it ;)
Its help when you unknown about that path exist or not /
File fullPath = new File('/tmp/Test1')
if (!fullPath.exists())
fullPath.mkdirs()

How to restore a folder structure 7Zip'd with split volume option?

I 7Zip'd a multi-gig folder which contained many folders each with many files using the split to volumes (9Meg) option. 7Zip created files of type .zip.001,
.zip.002, etc. When I extract .001 it appears to work correctly but I get an 'unexpected end of data' error. 7Zip does not automatically go to .002. When I extract .002, it also gives the same error and it does not continue the original folder/file structure. Instead it extracts a zip file in the same folder as the previously extracted files. How do I properly extract split files to obtain the original folder/file structure? Thank you.

Where do the files created with File.new actually get stored in Ruby?

I am creating files from within Ruby scripts and adding stuff to them. But where are these files stored that I am creating?
I'm very new to this, sorry!
The files are created at whatever location you specified. For instance:
f = File.new("another_test.txt","w+")
that will create the file in the current working directory. You specify the path along with the file name. For example:
f = File.new("~/Desktop/another_test.txt","w+") # will create the file on the desktop.
For more details, check the File documentation.
Updated:
Included mu is too short correction.

Resources