Git Aliases not working - linux

I have specified certain aliases in the .gitconfig file located in /home/myUser/.gitconfig as below (I am pasting the entire file settings):
[user]
name = myName
email = myEmail#email.com
[core]
autocrlf = true
safecrlf = true
[push]
default = simple
[alias]
co = checkout
ci = commit
st = status
br = branch
hist = log --pretty=format:'%h %ad | %s%d [%an]' --graph --date=short
type = cat-file -t
dump = cat-file -p
I am having a problem specifically with that hist alias. Sometimes I get the desired output when y execute de git hist (I mean the format specified in the .gitconfig for the hist alias); and some other times it is not recognized. I tried restarting the terminal an the same happens: sometimes it works and some other times don't.
Would appreciate any help, thanks a lot!

Related

Python git package get tag and commit

I would like to print a git commit and the tag in my Python code.
How can I do this using git package?
When I am going to my Bitbucket I see
tag: 73-2-g46b9856
commit checksum: 46b9856
How can I retrieve this info from git package?
I have done the following:
import git
repo = git.Repo(search_parent_directories=True)
sha = repo.head.object.hexsha
So I assume you already have the checksum you want in the sha variable.
At this point, there's a post for how to get the tags and looking for a specific tag associated with that sha in this link: Get tags of a commit
# Example code for clarity
import git
repo = git.Repo(search_parent_directories=True)
sha = repo.head.object.hexsha
tagmap = {}
for t in repo.tags:
tagmap.setdefault(repo.commit(t), []).append(t)
tags = tagmap[repo.commit(sha)] # Warning: Your latest commit might not have a tag associated with it so this will throw an error right now.
print(tags)
Here is what solved my issue:
repo = git.Repo(search_parent_directories = True)
sha = repo.head.object.hexsha
commit_chksum = repo.git.rev_parse(sha, short = 7)
tag = subprocess.check_output(["git", "describe", "--always"]).strip().decode()

execute snakemake rule as last rule

I tried to create a snakemake file to run sortmeRNA pipeline:
SAMPLES = ['test']
READS=["R1", "R2"]
rule all:
input: expand("Clean/4.Unmerge/{exp}.non_rRNA_{read}.fastq", exp = SAMPLES, read = READS)
rule unzip:
input:
fq = "trimmed/{exp}.{read}.trimd.fastq.gz"
output:
ofq = "Clean/1.Unzipped/{exp}.{read}.trimd.fastq"
shell: "gzip -dkc < {input.fq} > {output.ofq}"
rule merge_paired:
input:
read1 = "Clean/1.Unzipped/{exp}.R1.trimd.fastq",
read2 = "Clean/1.Unzipped/{exp}.R2.trimd.fastq"
output:
il = "Clean/2.interleaved/{exp}.il.trimd.fastq"
shell: "merge-paired-reads.sh {input.read1} {input.read2} {output.il}"
rule sortmeRNA:
input:
ilfq = "Clean/2.interleaved/{exp}.il.trimd.fastq"
output:
reads_rRNA = "Clean/3.sorted/{exp}_reads_rRNA",
non_rRNA = "Clean/3.sorted/{exp}_reads_nonRNA"
params:
silvabac = "rRNA_databases/silva-bac-16s-id90.fasta,index/silva-bac-16s-db:rRNA_databases/silva-bac-23s-id98.fasta,index/silva-bac-23s-db",
silvaarc = "rRNA_databases/silva-arc-16s-id95.fasta,index/silva-arc-16s-db:rRNA_databases/silva-arc-23s-id98.fasta,index/silva-arc-23s-db",
silvaeuk = "rRNA_databases/silva-euk-18s-id95.fasta,index/silva-euk-18s-db:rRNA_databases/silva-euk-28s-id98.fasta,index/silva-euk-28s-db",
rfam = "rRNA_databases/rfam-5s-database-id98.fasta,index/rfam-5s-db:rRNA_databases/rfam-5.8s-database-id98.fasta,index/rfam-5.8s-db",
acc = "--num_alignments 1 --fastx --log -a 20 -m 64000 --paired_in -v"
log:
"Clean/sortmeRNAlogs/{exp}_sortmeRNA.log"
shell:'''
sortmerna --ref {params.silvabac}:{params.silvaarc}:{params.silvaeuk}:{params.rfam} --reads {input.ilfq} --aligned {output.reads_rRNA} --other {output.non_rRNA} {params.acc}
'''
rule unmerge_paired:
input:
inun = "Clean/3.sorted/{exp}_reads_nonRNA.fastq"
output:
R1 = "Clean/4.Unmerge/{exp}.non_rRNA_R1.fastq",
R2 = "Clean/4.Unmerge/{exp}.non_rRNA_R2.fastq"
shell:"unmerge-paired-reads.sh {input.inun} {output.R1} {output.R2}"
This worked fine !. But for 1 sample it produced an output with size ~53 GB. I have 90 samples to run and cannot afford huge disk space. I tried to make output of rules unzip,merge_paired,sortmeRNA as temp(), but upon executing unmerge_paired raises "Missing input files exception" error.
I also tried to add rule_remove to delete all those intermediate directories. But that is not executed as last rule, rather somewhere in the middle raising error again !. Is there any efficient way to do this ?
The error that occurs is:
MissingInputException in line 45 of sortmeRNA_pipeline_memv2.0.snakefile:
Missing input files for rule unmerge_paired:
Clean/3.sorted/test_reads_nonRNA.fastq
Also please note that, rule sortmeRNA requires a string for output and produces string.fastq file, which is then input into rule unmerge_paired !
Thanks.
For Snakemake to connect the input of one rule to the output of another, they will need to be identical. The way you describe the output of sortmeRNA and the input unmerge_paired do not work together, whether you put temp() around it or not.
rule sortmeRNA:
input:
ilfq = "Clean/2.interleaved/{exp}.il.trimd.fastq"
output:
reads_rRNA = temp("Clean/3.sorted/{exp}_reads_rRNA.fastq"),
non_rRNA = temp("Clean/3.sorted/{exp}_reads_nonRNA.fastq")
params:
reads_rRNA = "Clean/3.sorted/{exp}_reads_rRNA",
non_rRNA = "Clean/3.sorted/{exp}_reads_nonRNA"
shell:
'''
sortmerna --aligned {params.reads_rRNA} --other {params.non_rRNA} ...
'''
rule unmerge_paired:
input:
inun = "Clean/3.sorted/{exp}_reads_nonRNA.fastq" # or rules.sortmeRNA.output.non_rRNA
output:
R1 = "Clean/4.Unmerge/{exp}.non_rRNA_R1.fastq",
R2 = "Clean/4.Unmerge/{exp}.non_rRNA_R2.fastq"
shell:
"unmerge-paired-reads.sh {input.inun} {output.R1} {output.R2}"
I removed all the stuff which isn't necessary to understand what is going on, you will have to place those back obviously. I changed the output of sortmeRNA to the actual output of the rule (and made them temp). I also added two params, which are the same as the output but then without the fastq extension.

Pygit2: Need help on how to walk on all commits in all repo's branches

I'd need to walk on entire repo's branches commits. I have tried this but with no success. :
for branch_name in list(repo.branches.remote):
try:
branch = repo.lookup_branch(branch_name)
ref = repo.lookup_reference(branch.name)
repo.checkout(ref)
for commit in repo.walk(branch.target, pygit2.GIT_SORT_TIME):
print(commit.id.hex)
Any help would be appreciated, thanks.
This is what I have:
def iterate_repository(dir: str) -> None:
repo = pygit2.Repository(dir)
for branch_name in list(repo.branches.remote):
branch = repo.branches.get(branch_name)
latest_commit_id = branch.target
latest_commit = repo.revparse_single(latest_commit_id.hex)
for commit in repo.walk(latest_commit.id, pygit2.GIT_SORT_TIME):
print(commit.id.hex)
Expanding from that should be relatively easy. What I do is gather statistics from files included in a commit.

How can I add the build version to a scons build

At the moment I'm using some magic to get the current git revision into my scons builds.. I just grab the version a stick it into CPPDEFINES.
It works quite nicely ... until the version changes and scons wants to rebuild everything, rather than just the files that have changed - becasue the define that all files use has changed.
Ideally I'd generate a file using a custom builder called git_version.cpp and
just have a function in there that returns the right tag. That way only that one file would be rebuilt.
Now I'm sure I've seen a tutorial showing exactly how to do this .. but I can't seem to track it down. And I find the custom builder stuff a little odd in scons...
So any pointers would be appreciated...
Anyway just for reference this is what I'm currently doing:
# Lets get the version from git
# first get the base version
git_sha = subprocess.Popen(["git","rev-parse","--short=10","HEAD"], stdout=subprocess.PIPE ).communicate()[0].strip()
p1 = subprocess.Popen(["git", "status"], stdout=subprocess.PIPE )
p2 = subprocess.Popen(["grep", "Changed but not updated\\|Changes to be committed"], stdin=p1.stdout,stdout=subprocess.PIPE)
result = p2.communicate()[0].strip()
if result!="":
git_sha += "[MOD]"
print "Building version %s"%git_sha
env = Environment()
env.Append( CPPDEFINES={'GITSHAMOD':'"\\"%s\\""'%git_sha} )
You don't need a custom Builder since this is just one file. You can use a function (attached to the target version file as an Action) to generate your version file. In the example code below, I've already computed the version and put it into an environment variable. You could do the same, or you could put your code that makes git calls in the version_action function.
version_build_template="""/*
* This file is automatically generated by the build process
* DO NOT EDIT!
*/
const char VERSION_STRING[] = "%s";
const char* getVersionString() { return VERSION_STRING; }
"""
def version_action(target, source, env):
"""
Generate the version file with the current version in it
"""
contents = version_build_template % (env['VERSION'].toString())
fd = open(target[0].path, 'w')
fd.write(contents)
fd.close()
return 0
build_version = env.Command('version.build.cpp', [], Action(version_action))
env.AlwaysBuild(build_version)

Receiving "MERGE" 200 OK error when committing using trac-post-commit-hook

When running a commit with the trac-post-commit-hook I receive a MERGE 200 OK error, I understand that this means that the commit has succeeded on the server but the file status has not updated on my local machine. But I can't find anyway to fix this issue. Would this be a problem with my setup or something in the script. I'm using stock standard script from the trac site, I'm committing through tortoiseSVN to VisualSVN Server which is hosted on a windows 2008 server. When I run the script through a command line I receive no errors, I only receive this error through TortoiseSVN.
Your problem with the Trac post-commit hook sounds like this:
http://ariejan.net/2007/05/21/merge-request-failed-on-pathtofile/
I've had this problems for hooks that had nothing to do with Trac. From post-commit I called some other script that did svnlook changed and cat in the repository, and I got MERGE 200 OK error. The solution was to call the other script in the background so that the hook exits immediately after starting the script.
I got this error using Trac & Subversion under Debian "Lenny".
For me it boiled down to a bug in Trac. In trac.util.datefmt:
def to_timestamp(dt):
"""Return the corresponding POSIX timestamp"""
if dt:
diff = dt - _epoc
return diff.days * 86400 + diff.seconds
else:
return 0
Where dt is a timestamp. So convert to a datetime first:
def to_timestamp(dt):
"""Return the corresponding POSIX timestamp"""
if dt:
dtt = to_datetime(dt)
diff = dtt - _epoc
return diff.days * 86400 + diff.seconds
else:
return 0
Now we have to fix a problem in the trac-post-commit-hook script, since the 'href' and 'abs_href' attributes of trac.env.Environment are get-only properties (there is no setter):
--- trac/trac-post-commit-hook (revision 8)
+++ trac/trac-post-commit-hook (working copy)
## -152,11 +152,7 ##
self.author = chgset.author
self.rev = rev
self.msg = "(In [%s]) %s" % (rev, chgset.message)
self.now = int(time.time())
- if url is None:
- url = self.env.config.get('trac', 'base_url')
- self.env.href = Href(url)
- self.env.abs_href = Href(url)
This is all on Debian "Lenny", trac 0.11.1-2.1

Resources