Skip to content

Instantly share code, notes, and snippets.

@RoyXiang
Created November 4, 2012 10:58
Show Gist options
  • Save RoyXiang/4011338 to your computer and use it in GitHub Desktop.
Save RoyXiang/4011338 to your computer and use it in GitHub Desktop.

Revisions

  1. Roy Xiang revised this gist Nov 17, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion updateGit.py
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    #! python2
    #!/usr/bin/env python
    # -*- coding: utf-8 -*-

    import os
  2. Roy Xiang revised this gist Jun 19, 2013. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions updateGit.py
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    #! python
    #! python2
    # -*- coding: utf-8 -*-

    import os
    @@ -9,7 +9,7 @@ def updateGit():
    cwd = os.getcwd()
    git = os.path.abspath(os.path.join(cwd, '.git'))
    myURLs = r'https://github.com/RoyXiang/', r'[email protected]:RoyXiang/'

    if os.path.exists(git):
    if os.path.isdir(git):
    config = os.path.join(git, 'config')
  3. Roy Xiang revised this gist Dec 15, 2012. 1 changed file with 4 additions and 3 deletions.
    7 changes: 4 additions & 3 deletions updateGit.py
    Original file line number Diff line number Diff line change
    @@ -3,6 +3,7 @@

    import os
    import re
    import subprocess

    def updateGit():
    cwd = os.getcwd()
    @@ -35,10 +36,10 @@ def updateGit():
    if url != None:
    if not (lines[i][url.start(1):url.end(1)]).startswith(myURLs):
    if part.group(2) == 'origin':
    os.system('git pull')
    subprocess.call(['git', 'pull'])
    else:
    os.system('git fetch ' + part.group(2))
    os.system('git merge ' + part.group(2) + '/master')
    subprocess.call(['git', 'fetch', part.group(2)])
    subprocess.call(['git', 'merge', part.group(2) + '/master'])
    break
    else:
    i = i + 1
  4. Roy Xiang revised this gist Dec 15, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion updateGit.py
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,7 @@
    def updateGit():
    cwd = os.getcwd()
    git = os.path.abspath(os.path.join(cwd, '.git'))
    myURLs = r'[email protected]:', r'https://github.com/RoyXiang/', r'[email protected]:RoyXiang/'
    myURLs = r'https://github.com/RoyXiang/', r'[email protected]:RoyXiang/'

    if os.path.exists(git):
    if os.path.isdir(git):
  5. Roy Xiang revised this gist Nov 5, 2012. 1 changed file with 4 additions and 3 deletions.
    7 changes: 4 additions & 3 deletions updateGit.py
    Original file line number Diff line number Diff line change
    @@ -28,9 +28,9 @@ def updateGit():
    for i in range(len(lines)):
    part = re.match(r'^\[([\w]+)(?:\s"([^\]]+)")?\]$', lines[i])
    if part != None:
    i = i + 1
    if part.group(1) == 'remote':
    while True:
    i = i + 1
    url = re.match(r'^\s*url\s*=\s*([^\s]+)$', lines[i])
    if url != None:
    if not (lines[i][url.start(1):url.end(1)]).startswith(myURLs):
    @@ -40,10 +40,11 @@ def updateGit():
    os.system('git fetch ' + part.group(2))
    os.system('git merge ' + part.group(2) + '/master')
    break
    else:
    i = i + 1
    elif part.group(1) == 'submodule':
    i = i + 1
    url = re.match(r'^\s*url\s*=\s*([^\s]+)$', lines[i])
    print 'Entering \'' + part.group(2) + '\''
    print 'Entering \"' + part.group(2) + '\"'
    path = os.path.abspath(os.path.join(cwd, part.group(2)))
    os.chdir(path)
    updateGit()
  6. Roy Xiang revised this gist Nov 5, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion updateGit.py
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,7 @@
    def updateGit():
    cwd = os.getcwd()
    git = os.path.abspath(os.path.join(cwd, '.git'))
    myURLs = r'https://github.com/RoyXiang/', r'[email protected]:RoyXiang/'
    myURLs = r'[email protected]:', r'https://github.com/RoyXiang/', r'[email protected]:RoyXiang/'

    if os.path.exists(git):
    if os.path.isdir(git):
  7. Roy Xiang created this gist Nov 4, 2012.
    53 changes: 53 additions & 0 deletions updateGit.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,53 @@
    #! python
    # -*- coding: utf-8 -*-

    import os
    import re

    def updateGit():
    cwd = os.getcwd()
    git = os.path.abspath(os.path.join(cwd, '.git'))
    myURLs = r'https://github.com/RoyXiang/', r'[email protected]:RoyXiang/'

    if os.path.exists(git):
    if os.path.isdir(git):
    config = os.path.join(git, 'config')
    else:
    gitfile = open(git, 'r')
    for line in gitfile:
    gitdir = re.match(r'^gitdir\:\s*(.*)$', line)
    if gitdir != None:
    config = os.path.join(cwd, line[gitdir.start(1):gitdir.end(1)], 'config')
    break
    config = os.path.abspath(config)
    else:
    print 'This is not a git foler!'
    return

    lines = open(config, 'r').readlines()
    for i in range(len(lines)):
    part = re.match(r'^\[([\w]+)(?:\s"([^\]]+)")?\]$', lines[i])
    if part != None:
    if part.group(1) == 'remote':
    while True:
    i = i + 1
    url = re.match(r'^\s*url\s*=\s*([^\s]+)$', lines[i])
    if url != None:
    if not (lines[i][url.start(1):url.end(1)]).startswith(myURLs):
    if part.group(2) == 'origin':
    os.system('git pull')
    else:
    os.system('git fetch ' + part.group(2))
    os.system('git merge ' + part.group(2) + '/master')
    break
    elif part.group(1) == 'submodule':
    i = i + 1
    url = re.match(r'^\s*url\s*=\s*([^\s]+)$', lines[i])
    print 'Entering \'' + part.group(2) + '\''
    path = os.path.abspath(os.path.join(cwd, part.group(2)))
    os.chdir(path)
    updateGit()
    os.chdir(cwd)

    if __name__ == '__main__':
    updateGit()