Last active
January 1, 2016 08:09
-
-
Save GothAck/8116551 to your computer and use it in GitHub Desktop.
Adding to the GIT Index with Sublimerge
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
function sli () { | |
if [ -z "$1" ] || [ "$1" = "-h" ]; then | |
echo "sli - Sublimerge add to GIT index" | |
echo "Usage:" | |
echo "sli [options] {path to file}" | |
echo | |
echo "Call this function in the root of the GIT working tree after using the custom Sublimerge comparison" | |
return 0 | |
fi | |
GIT_FILE="$1" | |
TEMP_FILE="/tmp/sublimerge/$1@HEAD" | |
git show :"$GIT_FILE" |\ | |
git diff --no-index -- - "$TEMP_FILE" |\ | |
sed 's|^diff --git.*$|'"diff --git a/$GIT_FILE b/$GIT_FILE"'|' |\ | |
sed '/^\(---\|+++\)/s|^\(.\{5\}\).*|\1/'"$GIT_FILE"'|' |\ | |
git apply --cached --verbose; | |
if [ "$?" -gt "0" ]; then | |
echo "There were no changes to add to the git index" | |
else | |
git diff --cached --stat "$GIT_FILE" | cat | |
fi | |
# rm "$TEMP_FILE" | |
} |
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
{ | |
"custom_comparisons": [ | |
/************************************* GIT *************************************/ | |
/* | |
* Custom Git comparison. Displays quick panel with modified files and allows to compare working copy to HEAD to see uncommited changes. | |
*/ | |
{ | |
"name": "Show uncommited changes (index)...", //comparison name | |
"requires": "git", //What does it require. Currently 'git', 'svn' 'hg' or null (if doesn't require any of VCS) | |
"steps": [ //comparison is divided into steps. You can define more steps when needed. | |
{ | |
"quick_panel": { //Displays a Quick Panel with given attributes | |
"name": "modified_file", //Quick Panel name. Used to populate a variable 'modified_file' with seleted item value | |
"source": { //Data source | |
"execute": { //Execute a shell command | |
"command": "{config:git_executable_path} status --porcelain --untracked-files=no", | |
"directory": "{sublimerge:repo_root}" //Set a command working directory | |
}, | |
"item": { //Single item extractor | |
"regexp": "^\\s+M\\s+\"?(.*?)\"?$", //Regular expression to parse each output line | |
"caption": ["@1"], //Caption is an array. Each item is another line. @n - placeholder for regular expression match | |
"value": "@1" //Value must be a single string | |
}, | |
"empty_message": "There are no uncommited changes" //Message to be displayed when data source is empty (no items created) | |
} | |
} | |
}, | |
{ //define variables | |
"define": { | |
"right_file": "{sublimerge:repo_root}/{modified_file}", | |
// Custom tmp path including sublimerge so we don't accidentally clobber other tmp files | |
"left_file": "{sublimerge:temp_dir}/sublimerge/{modified_file}@HEAD" | |
} | |
}, | |
{ | |
"compare": { //Executes file comparison | |
"execute": { //Execute a shell command. Please note about 'modified_file' variable which we defined in previous step | |
// Note the mkdir | |
"command": "mkdir -p \"{left_file|dirname}\" ;{config:git_executable_path} show :\"./{modified_file}\" > \"{left_file}\"", | |
"directory": "{sublimerge:repo_root}" | |
}, | |
"left": { //Left file | |
"file": "{left_file}", //Full file path | |
"temporary": false // Keep tmp left_file so we can add it's difference to the git index | |
}, | |
"right": { | |
"file": "{right_file}", | |
"temporary": false //This file is our working copy, so is not temporary | |
} | |
} | |
} | |
] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Huh, it's in the Custom Comparisons - User file, however I'd not read the documentation and had copied the custom_comparisons key from the Default file >_<