#!/bin/sh # Use this tool to rewrite your .git/remotes/ files into the config. source git-sh-setup if test -d "$GIT_DIR"/remotes { echo "Rewriting $GIT_DIR/remotes" > !2 global error := '0' # rewrite into config do { cd "$GIT_DIR"/remotes ls | while read f { global name := $[printf $f | tr -c "A-Za-z0-9-" ".] sed -n \ -e "s/^URL:[ ]*\(.*\)$/remote.$name.url \1 ./p" \ -e "s/^Pull:[ ]*\(.*\)$/remote.$name.fetch \1 ^$ /p" \ -e "s/^Push:[ ]*\(.*\)$/remote.$name.push \1 ^$ /p" \ < $f } echo done } | while read key value regex { matchstr $key { done { if test $error = 0 { mv "$GIT_DIR"/remotes "$GIT_DIR"/remotes.old } } * { echo "git config $key "$value" $regex" git config $key $value $regex || global error := '1' } } } } (CommandList children: [ (C {(.)} {(git-sh-setup)}) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(-d)} {(DQ ($ VSub_Name "$GIT_DIR")) (/remotes)} {(Lit_Other "]")}) terminator: ) ] action: [ (SimpleCommand words: [{(echo)} {(DQ ("Rewriting ") ($ VSub_Name "$GIT_DIR") (/remotes))}] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[38])] ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:error) op:Equal rhs:{(0)} spids:[42])] spids: [42] ) (Pipeline children: [ (BraceGroup children: [ (C {(cd)} {(DQ ($ VSub_Name "$GIT_DIR")) (/remotes)}) (Pipeline children: [ (C {(ls)}) (While cond: [(Sentence child:(C {(read)} {(f)}) terminator:)] body: (DoGroup children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:name) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(printf)} {(DQ ($ VSub_Name "$f"))}) (C {(tr)} {(-c)} {(DQ (A-Za-z0-9-))} {(DQ (.))}) ] negated: False ) ] ) left_token: spids: [76 96] ) } spids: [75] ) ] spids: [75] ) (SimpleCommand words: [ {(sed)} {(-n)} {(-e)} { (DQ ("s/^URL:[ \t]*") (EscapedLiteralPart token: ) (".*") (EscapedLiteralPart token:) (Lit_Other "$") (/remote.) ($ VSub_Name "$name") (".url ") (EscapedLiteralPart token:) (" ./p") ) } {(-e)} { (DQ ("s/^Pull:[ \t]*") (EscapedLiteralPart token: ) (".*") (EscapedLiteralPart token:) (Lit_Other "$") (/remote.) ($ VSub_Name "$name") (".fetch ") (EscapedLiteralPart token:) (" ^") (Lit_Other "$") (" /p") ) } {(-e)} { (DQ ("s/^Push:[ \t]*") (EscapedLiteralPart token: ) (".*") (EscapedLiteralPart token:) (Lit_Other "$") (/remote.) ($ VSub_Name "$name") (".push ") (EscapedLiteralPart token:) (" ^") (Lit_Other "$") (" /p") ) } ] redirects: [ (Redir op_id: Redir_Less fd: -1 arg_word: {(DQ ($ VSub_Name "$f"))} spids: [160] ) ] ) ] spids: [72 167] ) ) ] negated: False ) (C {(echo)} {(KW_Done done)}) ] spids: [50] ) (While cond: [ (Sentence child: (C {(read)} {(key)} {(value)} {(regex)}) terminator: ) ] body: (DoGroup children: [ (Case to_match: {($ VSub_Name "$key")} arms: [ (case_arm pat_list: [{(KW_Done done)}] action: [ (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {($ VSub_Name "$error")} {(Lit_Other "=")} {(0)} {(Lit_Other "]")} ) terminator: ) ] action: [ (C {(mv)} {(DQ ($ VSub_Name "$GIT_DIR")) (/remotes)} {(DQ ($ VSub_Name "$GIT_DIR")) (/remotes.old)} ) ] spids: [-1 217] ) ] spids: [-1 233] ) ] spids: [200 201 235 -1] ) (case_arm pat_list: [{(Lit_Other "*")}] action: [ (C {(echo)} {(DQ ("git config ") ($ VSub_Name "$key") (" ")) ($ VSub_Name "$value") (DQ (" ") ($ VSub_Name "$regex")) } ) (AndOr children: [ (C {(git)} {(config)} {($ VSub_Name "$key")} {(DQ ($ VSub_Name "$value"))} {($ VSub_Name "$regex")} ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:error) op: Equal rhs: {(1)} spids: [270] ) ] spids: [270] ) ] op_id: Op_DPipe ) ] spids: [238 239 273 -1] ) ] spids: [193 197 276] ) ] spids: [190 279] ) ) ] negated: False ) ] spids: [-1 27] ) ] spids: [-1 281] ) ] )