{"thread":{"id":"41531","subject":"[PATCH v2] contrib/subtree: add repo url to commit messages","startedAt":"2016-02-26T08:43:57Z","lastAt":"2016-02-26T08:43:57Z","messageCount":1,"participants":["Mathias Nyman"],"isPatch":true,"patchVersion":2,"patchTotal":null},"messages":[{"id":"279502","messageId":"20160226084357.GA25889@iki.fi","threadId":"41531","inReplyTo":null,"subject":"[PATCH v2] contrib/subtree: add repo url to commit messages","fromName":"Mathias Nyman","fromEmail":"mathias.nyman@iki.fi","sentAt":"2016-02-26T08:43:57Z","receivedAt":"2016-02-26T08:43:57Z","isPatch":true,"sender":{"key":"mathias.nyman@iki.fi","avatar":null},"body":"For recalling where a subtree came from; git-subtree operations 'add'\nand 'pull', when called with the <repository> parameter add this to the\ncommit message:\n    git-subtree-repo: <repo_url>\n\nOther operations that don't have the <repository> information, like\n'merge' and 'add' without <repository>, are unchanged. Users with such a\nworkflow will continue to be on their own with the --message parameter,\nif they'd like to record where the subtree came from.\n\nSigned-off-by: Mathias Nyman <mathias.nyman@iki.fi>\nBased-on-patch-by: Nicola Paolucci <npaolucci@atlassian.com>\nThanks-to: Aleksi Aalto <aga@iki.fi>\n---\n contrib/subtree/git-subtree.sh | 54 ++++++++++++++++++++++++++++++++----------\n 1 file changed, 42 insertions(+), 12 deletions(-)\n\ndiff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh\nindex 7a39b30..dd1f70e 100755\n--- a/contrib/subtree/git-subtree.sh\n+++ b/contrib/subtree/git-subtree.sh\n@@ -335,6 +335,7 @@ add_msg()\n \tdir=\"$1\"\n \tlatest_old=\"$2\"\n \tlatest_new=\"$3\"\n+\trepo=\"$4\" # optional\n \tif [ -n \"$message\" ]; then\n \t\tcommit_message=\"$message\"\n \telse\n@@ -347,6 +348,11 @@ add_msg()\n \t\tgit-subtree-mainline: $latest_old\n \t\tgit-subtree-split: $latest_new\n \tEOF\n+\n+\tif [ -n \"$repo\" ]; then\n+\t\trepo_url=$(get_repository_url \"$repo\")\n+\t\techo \"git-subtree-repo: $repo_url\"\n+\tfi\n }\n \n add_squashed_msg()\n@@ -382,6 +388,7 @@ squash_msg()\n \tdir=\"$1\"\n \toldsub=\"$2\"\n \tnewsub=\"$3\"\n+\trepo=\"$4\" # optional\n \tnewsub_short=$(git rev-parse --short \"$newsub\")\n \t\n \tif [ -n \"$oldsub\" ]; then\n@@ -397,6 +404,10 @@ squash_msg()\n \techo\n \techo \"git-subtree-dir: $dir\"\n \techo \"git-subtree-split: $newsub\"\n+\tif [ -n \"$repo\" ]; then\n+\t\trepo_url=$(get_repository_url \"$repo\")\n+\t\techo \"git-subtree-repo: $repo_url\"\n+\tfi\n }\n \n toptree_for_commit()\n@@ -440,12 +451,13 @@ new_squash_commit()\n \told=\"$1\"\n \toldsub=\"$2\"\n \tnewsub=\"$3\"\n+\trepo=\"$4\" # optional\n \ttree=$(toptree_for_commit $newsub) || exit $?\n \tif [ -n \"$old\" ]; then\n-\t\tsquash_msg \"$dir\" \"$oldsub\" \"$newsub\" | \n+\t\tsquash_msg \"$dir\" \"$oldsub\" \"$newsub\" \"$repo\" |\n \t\t\tgit commit-tree \"$tree\" -p \"$old\" || exit $?\n \telse\n-\t\tsquash_msg \"$dir\" \"\" \"$newsub\" |\n+\t\tsquash_msg \"$dir\" \"\" \"$newsub\" \"$repo\" |\n \t\t\tgit commit-tree \"$tree\" || exit $?\n \tfi\n }\n@@ -517,6 +529,16 @@ ensure_valid_ref_format()\n \t    die \"'$1' does not look like a ref\"\n }\n \n+get_repository_url()\n+{\n+\trepo=$1\n+\trepo_url=$(git config --get remote.$repo.url)\n+\tif [ -z \"$repo_url\" ]; then\n+\t\trepo_url=$repo\n+\tfi\n+\techo $repo_url\n+}\n+\n cmd_add()\n {\n \tif [ -e \"$dir\" ]; then\n@@ -548,17 +570,18 @@ cmd_add()\n cmd_add_repository()\n {\n \techo \"git fetch\" \"$@\"\n-\trepository=$1\n+\trepo=$1\n \trefspec=$2\n \tgit fetch \"$@\" || exit $?\n \trevs=FETCH_HEAD\n-\tset -- $revs\n+\tset -- $revs $repo\n \tcmd_add_commit \"$@\"\n }\n \n cmd_add_commit()\n {\n-\trevs=$(git rev-parse $default --revs-only \"$@\") || exit $?\n+\trevs=$(git rev-parse $default --revs-only \"$1\") || exit $?\n+\trepo=\"$2\" # optional\n \tset -- $revs\n \trev=\"$1\"\n \t\n@@ -575,12 +598,12 @@ cmd_add_commit()\n \tfi\n \t\n \tif [ -n \"$squash\" ]; then\n-\t\trev=$(new_squash_commit \"\" \"\" \"$rev\") || exit $?\n+\t\trev=$(new_squash_commit \"\" \"\" \"$rev\" \"$repo\") || exit $?\n \t\tcommit=$(add_squashed_msg \"$rev\" \"$dir\" |\n \t\t\t git commit-tree $tree $headp -p \"$rev\") || exit $?\n \telse\n \t\trevp=$(peel_committish \"$rev\") &&\n-\t\tcommit=$(add_msg \"$dir\" \"$headrev\" \"$rev\" |\n+\t\tcommit=$(add_msg \"$dir\" \"$headrev\" \"$rev\" \"$repo\" |\n \t\t\t git commit-tree $tree $headp -p \"$revp\") || exit $?\n \tfi\n \tgit reset \"$commit\" || exit $?\n@@ -610,6 +633,7 @@ cmd_split()\n \t\tunrevs=\"$(find_existing_splits \"$dir\" \"$revs\")\"\n \tfi\n \t\n+\trev=\"$1\"\n \t# We can't restrict rev-list to only $dir here, because some of our\n \t# parents have the $dir contents the root, and those won't match.\n \t# (and rev-list --follow doesn't seem to solve this)\n@@ -683,14 +707,19 @@ cmd_split()\n \n cmd_merge()\n {\n-\trevs=$(git rev-parse $default --revs-only \"$@\") || exit $?\n+\trevs=$(git rev-parse $default --revs-only \"$1\") || exit $?\n \tensure_clean\n-\t\n \tset -- $revs\n \tif [ $# -ne 1 ]; then\n \t\tdie \"You must provide exactly one revision.  Got: '$revs'\"\n \tfi\n+\tdo_merge \"$@\"\n+}\n+\n+do_merge()\n+{\n \trev=\"$1\"\n+\trepo=\"$2\" # optional\n \t\n \tif [ -n \"$squash\" ]; then\n \t\tfirst_split=\"$(find_latest_squash \"$dir\")\"\n@@ -704,7 +733,7 @@ cmd_merge()\n \t\t\tsay \"Subtree is already at commit $rev.\"\n \t\t\texit 0\n \t\tfi\n-\t\tnew=$(new_squash_commit \"$old\" \"$sub\" \"$rev\") || exit $?\n+\t\tnew=$(new_squash_commit \"$old\" \"$sub\" \"$rev\" \"$repo\") || exit $?\n \t\tdebug \"New squash commit: $new\"\n \t\trev=\"$new\"\n \tfi\n@@ -730,12 +759,13 @@ cmd_pull()\n \tif [ $# -ne 2 ]; then\n \t    die \"You must provide <repository> <ref>\"\n \tfi\n+\trepo=$1\n \tensure_clean\n \tensure_valid_ref_format \"$2\"\n \tgit fetch \"$@\" || exit $?\n \trevs=FETCH_HEAD\n-\tset -- $revs\n-\tcmd_merge \"$@\"\n+\tset -- $revs $repo\n+\tdo_merge \"$@\"\n }\n \n cmd_push()\n-- \n2.7.1\n"}]}