Created
October 13, 2016 18:18
-
-
Save neuromusic/9581214cae72804e6ad00e3091e6b46e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 49, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"git_repo = r\"C:\\Users\\justink\\Code\\stimulus_code\"" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 41, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"import os\n", | |
"\n", | |
"def find_current_branch(repo):\n", | |
" '''\n", | |
" identifies the current branch for a repository\n", | |
" '''\n", | |
" HEAD = os.path.join(repo,'.git','HEAD')\n", | |
" \n", | |
" with open(HEAD) as f:\n", | |
" lines = f.readlines()\n", | |
" \n", | |
" assert len(lines)==1\n", | |
" return lines[0].split(' ')[-1].strip()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 48, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"def which_commit(repo):\n", | |
" \n", | |
" current_branch = find_current_branch(repo)\n", | |
" \n", | |
" ref = os.path.join(repo,'.git',current_branch)\n", | |
" \n", | |
" try:\n", | |
" with open(ref) as f:\n", | |
" lines = f.readlines()\n", | |
"\n", | |
" assert len(lines)==1\n", | |
" return lines[0].strip()\n", | |
" except IOError:\n", | |
" return current_branch" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 50, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"refs/heads/clean-pyc\n", | |
"8446f31965b9dd9391e82117495c117de7b2af0e\n" | |
] | |
} | |
], | |
"source": [ | |
"print find_current_branch(git_repo)\n", | |
"print which_commit(git_repo)" | |
] | |
} | |
], | |
"metadata": { | |
"anaconda-cloud": {}, | |
"kernelspec": { | |
"display_name": "Python [Root]", | |
"language": "python", | |
"name": "Python [Root]" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 2 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython2", | |
"version": "2.7.12" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment