1 """Python GIT interface
5 Copyright (C) 2005, Catalin Marinas <catalin.marinas@gmail.com>
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License version 2 as
9 published by the Free Software Foundation.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 import sys
, os
, re
, gitmergeonefile
22 from shutil
import copyfile
24 from stgit
import basedir
25 from stgit
.utils
import *
26 from stgit
.out
import *
27 from stgit
.run
import *
28 from stgit
.config
import config
31 class GitException(Exception):
34 # When a subprocess has a problem, we want the exception to be a
35 # subclass of GitException.
36 class GitRunException(GitException
):
47 """An author, committer, etc."""
48 def __init__(self
, name
= None, email
= None, date
= '',
50 self
.name
= self
.email
= self
.date
= None
51 if name
or email
or date
:
57 assert not (name
or email
or date
)
59 m
= re
.match(r
'^(.+)<(.+)>(.*)$', s
)
61 return [x
.strip() or None for x
in m
.groups()]
62 self
.name
, self
.email
, self
.date
= parse_desc(desc
)
63 def set_name(self
, val
):
66 def set_email(self
, val
):
69 def set_date(self
, val
):
73 if self
.name
and self
.email
:
74 return '%s <%s>' % (self
.name
, self
.email
)
76 raise GitException
, 'not enough identity data'
79 """Handle the commit objects
81 def __init__(self
, id_hash
):
82 self
.__id
_hash
= id_hash
84 lines
= GRun('git-cat-file', 'commit', id_hash
).output_lines()
85 for i
in range(len(lines
)):
88 break # we've seen all the header fields
89 key
, val
= line
.split(' ', 1)
94 elif key
== 'committer':
95 self
.__committer
= val
97 pass # ignore other headers
98 self
.__log
= '\n'.join(lines
[i
+1:])
100 def get_id_hash(self
):
101 return self
.__id
_hash
106 def get_parent(self
):
107 parents
= self
.get_parents()
113 def get_parents(self
):
114 return GRun('git-rev-list', '--parents', '--max-count=1', self
.__id
_hash
115 ).output_one_line().split()[1:]
117 def get_author(self
):
120 def get_committer(self
):
121 return self
.__committer
127 return self
.get_id_hash()
129 # dictionary of Commit objects, used to avoid multiple calls to git
136 def get_commit(id_hash
):
137 """Commit objects factory. Save/look-up them in the __commits
142 if id_hash
in __commits
:
143 return __commits
[id_hash
]
145 commit
= Commit(id_hash
)
146 __commits
[id_hash
] = commit
150 """Return the list of file conflicts
152 conflicts_file
= os
.path
.join(basedir
.get(), 'conflicts')
153 if os
.path
.isfile(conflicts_file
):
154 f
= file(conflicts_file
)
155 names
= [line
.strip() for line
in f
.readlines()]
162 files
= [os
.path
.join(basedir
.get(), 'info', 'exclude')]
163 user_exclude
= config
.get('core.excludesfile')
165 files
.append(user_exclude
)
168 def tree_status(files
= None, tree_id
= 'HEAD', unknown
= False,
169 noexclude
= True, verbose
= False, diff_flags
= []):
170 """Returns a list of pairs - (status, filename)
173 out
.start('Checking for changes in the working directory')
183 cmd
= ['git-ls-files', '-z', '--others', '--directory',
184 '--no-empty-directory']
186 cmd
+= ['--exclude=%s' % s
for s
in
187 ['*.[ao]', '*.pyc', '.*', '*~', '#*', 'TAGS', 'tags']]
188 cmd
+= ['--exclude-per-directory=.gitignore']
189 cmd
+= ['--exclude-from=%s' % fn
190 for fn
in exclude_files()
191 if os
.path
.exists(fn
)]
193 lines
= GRun(*cmd
).raw_output().split('\0')
194 cache_files
+= [('?', line
) for line
in lines
if line
]
197 conflicts
= get_conflicts()
200 cache_files
+= [('C', filename
) for filename
in conflicts
]
203 for line
in GRun('git-diff-index', *(diff_flags
+ [tree_id
, '--'] + files
)
205 fs
= tuple(line
.rstrip().split(' ',4)[-1].split('\t',1))
206 if fs
[1] not in conflicts
:
207 cache_files
.append(fs
)
214 def local_changes(verbose
= True):
215 """Return true if there are local changes in the tree
217 return len(tree_status(verbose
= verbose
)) != 0
221 hr
= re
.compile(r
'^[0-9a-f]{40} refs/heads/(.+)$')
222 for line
in GRun('git-show-ref', '--heads').output_lines():
224 heads
.append(m
.group(1))
231 """Verifies the HEAD and returns the SHA1 id that represents it
236 __head
= rev_parse('HEAD')
240 """Returns the name of the file pointed to by the HEAD link
242 return strip_prefix('refs/heads/',
243 GRun('git-symbolic-ref', 'HEAD').output_one_line())
245 def set_head_file(ref
):
246 """Resets HEAD to point to a new ref
248 # head cache flushing is needed since we might have a different value
252 GRun('git-symbolic-ref', 'HEAD', 'refs/heads/%s' % ref
).run()
253 except GitRunException
:
254 raise GitException
, 'Could not set head to "%s"' % ref
256 def set_ref(ref
, val
):
257 """Point ref at a new commit object."""
259 GRun('git-update-ref', ref
, val
).run()
260 except GitRunException
:
261 raise GitException
, 'Could not update %s to "%s".' % (ref
, val
)
263 def set_branch(branch
, val
):
264 set_ref('refs/heads/%s' % branch
, val
)
267 """Sets the HEAD value
271 if not __head
or __head
!= val
:
275 # only allow SHA1 hashes
276 assert(len(__head
) == 40)
278 def __clear_head_cache():
279 """Sets the __head to None so that a re-read is forced
286 """Refresh index with stat() information from the working directory.
288 GRun('git-update-index', '-q', '--unmerged', '--refresh').run()
290 def rev_parse(git_id
):
291 """Parse the string and return a verified SHA1 id
294 return GRun('git-rev-parse', '--verify', git_id
).output_one_line()
295 except GitRunException
:
296 raise GitException
, 'Unknown revision: %s' % git_id
305 def branch_exists(branch
):
306 return ref_exists('refs/heads/%s' % branch
)
308 def create_branch(new_branch
, tree_id
= None):
309 """Create a new branch in the git repository
311 if branch_exists(new_branch
):
312 raise GitException
, 'Branch "%s" already exists' % new_branch
314 current_head
= get_head()
315 set_head_file(new_branch
)
316 __set_head(current_head
)
318 # a checkout isn't needed if new branch points to the current head
322 if os
.path
.isfile(os
.path
.join(basedir
.get(), 'MERGE_HEAD')):
323 os
.remove(os
.path
.join(basedir
.get(), 'MERGE_HEAD'))
325 def switch_branch(new_branch
):
326 """Switch to a git branch
330 if not branch_exists(new_branch
):
331 raise GitException
, 'Branch "%s" does not exist' % new_branch
333 tree_id
= rev_parse('refs/heads/%s^{commit}' % new_branch
)
334 if tree_id
!= get_head():
337 GRun('git-read-tree', '-u', '-m', get_head(), tree_id
).run()
338 except GitRunException
:
339 raise GitException
, 'git-read-tree failed (local changes maybe?)'
341 set_head_file(new_branch
)
343 if os
.path
.isfile(os
.path
.join(basedir
.get(), 'MERGE_HEAD')):
344 os
.remove(os
.path
.join(basedir
.get(), 'MERGE_HEAD'))
347 if not ref_exists(ref
):
348 raise GitException
, '%s does not exist' % ref
349 sha1
= GRun('git-show-ref', '-s', ref
).output_one_line()
351 GRun('git-update-ref', '-d', ref
, sha1
).run()
352 except GitRunException
:
353 raise GitException
, 'Failed to delete ref %s' % ref
355 def delete_branch(name
):
356 delete_ref('refs/heads/%s' % name
)
358 def rename_ref(from_ref
, to_ref
):
359 if not ref_exists(from_ref
):
360 raise GitException
, '"%s" does not exist' % from_ref
361 if ref_exists(to_ref
):
362 raise GitException
, '"%s" already exists' % to_ref
364 sha1
= GRun('git-show-ref', '-s', from_ref
).output_one_line()
366 GRun('git-update-ref', to_ref
, sha1
, '0'*40).run()
367 except GitRunException
:
368 raise GitException
, 'Failed to create new ref %s' % to_ref
370 GRun('git-update-ref', '-d', from_ref
, sha1
).run()
371 except GitRunException
:
372 raise GitException
, 'Failed to delete ref %s' % from_ref
374 def rename_branch(from_name
, to_name
):
375 """Rename a git branch."""
376 rename_ref('refs/heads/%s' % from_name
, 'refs/heads/%s' % to_name
)
377 if get_head_file() == from_name
:
378 set_head_file(to_name
)
379 reflog_dir
= os
.path
.join(basedir
.get(), 'logs', 'refs', 'heads')
380 if os
.path
.exists(reflog_dir
) \
381 and os
.path
.exists(os
.path
.join(reflog_dir
, from_name
)):
382 rename(reflog_dir
, from_name
, to_name
)
385 """Add the files or recursively add the directory contents
387 # generate the file list
390 if not os
.path
.exists(i
):
391 raise GitException
, 'Unknown file or directory: %s' % i
394 # recursive search. We only add files
395 for root
, dirs
, local_files
in os
.walk(i
):
396 for name
in [os
.path
.join(root
, f
) for f
in local_files
]:
397 if os
.path
.isfile(name
):
398 files
.append(os
.path
.normpath(name
))
399 elif os
.path
.isfile(i
):
400 files
.append(os
.path
.normpath(i
))
402 raise GitException
, '%s is not a file or directory' % i
406 GRun('git-update-index', '--add', '--').xargs(files
)
407 except GitRunException
:
408 raise GitException
, 'Unable to add file'
410 def __copy_single(source
, target
, target2
=''):
411 """Copy file or dir named 'source' to name target+target2"""
413 # "source" (file or dir) must match one or more git-controlled file
414 realfiles
= GRun('git-ls-files', source
).output_lines()
415 if len(realfiles
) == 0:
416 raise GitException
, '"%s" matches no git-controled files' % source
418 if os
.path
.isdir(source
):
419 # physically copy the files, and record them to add them in one run
421 re_string
='^'+source
+'/(.*)$'
422 prefix_regexp
= re
.compile(re_string
)
423 for f
in [f
.strip() for f
in realfiles
]:
424 m
= prefix_regexp
.match(f
)
426 raise Exception, '"%s" does not match "%s"' % (f
, re_string
)
427 newname
= target
+target2
+'/'+m
.group(1)
428 if not os
.path
.exists(os
.path
.dirname(newname
)):
429 os
.makedirs(os
.path
.dirname(newname
))
431 newfiles
.append(newname
)
434 else: # files, symlinks, ...
435 newname
= target
+target2
436 copyfile(source
, newname
)
440 def copy(filespecs
, target
):
441 if os
.path
.isdir(target
):
442 # target is a directory: copy each entry on the command line,
443 # with the same name, into the target
444 target
= target
.rstrip('/')
446 # first, check that none of the children of the target
447 # matching the command line aleady exist
448 for filespec
in filespecs
:
449 entry
= target
+ '/' + os
.path
.basename(filespec
.rstrip('/'))
450 if os
.path
.exists(entry
):
451 raise GitException
, 'Target "%s" already exists' % entry
453 for filespec
in filespecs
:
454 filespec
= filespec
.rstrip('/')
455 basename
= '/' + os
.path
.basename(filespec
)
456 __copy_single(filespec
, target
, basename
)
458 elif os
.path
.exists(target
):
459 raise GitException
, 'Target "%s" exists but is not a directory' % target
460 elif len(filespecs
) != 1:
461 raise GitException
, 'Cannot copy more than one file to non-directory'
464 # at this point: len(filespecs)==1 and target does not exist
466 # check target directory
467 targetdir
= os
.path
.dirname(target
)
468 if targetdir
!= '' and not os
.path
.isdir(targetdir
):
469 raise GitException
, 'Target directory "%s" does not exist' % targetdir
471 __copy_single(filespecs
[0].rstrip('/'), target
)
474 def rm(files
, force
= False):
475 """Remove a file from the repository
479 if os
.path
.exists(f
):
480 raise GitException
, '%s exists. Remove it first' %f
482 GRun('git-update-index', '--remove', '--').xargs(files
)
485 GRun('git-update-index', '--force-remove', '--').xargs(files
)
493 """Return the user information.
497 name
=config
.get('user.name')
498 email
=config
.get('user.email')
499 __user
= Person(name
, email
)
503 """Return the author information.
508 # the environment variables take priority over config
510 date
= os
.environ
['GIT_AUTHOR_DATE']
513 __author
= Person(os
.environ
['GIT_AUTHOR_NAME'],
514 os
.environ
['GIT_AUTHOR_EMAIL'],
521 """Return the author information.
526 # the environment variables take priority over config
528 date
= os
.environ
['GIT_COMMITTER_DATE']
531 __committer
= Person(os
.environ
['GIT_COMMITTER_NAME'],
532 os
.environ
['GIT_COMMITTER_EMAIL'],
538 def update_cache(files
= None, force
= False):
539 """Update the cache information for the given files
544 cache_files
= tree_status(files
, verbose
= False)
546 # everything is up-to-date
547 if len(cache_files
) == 0:
550 # check for unresolved conflicts
551 if not force
and [x
for x
in cache_files
552 if x
[0] not in ['M', 'N', 'A', 'D']]:
553 raise GitException
, 'Updating cache failed: unresolved conflicts'
556 add_files
= [x
[1] for x
in cache_files
if x
[0] in ['N', 'A']]
557 rm_files
= [x
[1] for x
in cache_files
if x
[0] in ['D']]
558 m_files
= [x
[1] for x
in cache_files
if x
[0] in ['M']]
560 GRun('git-update-index', '--add', '--').xargs(add_files
)
561 GRun('git-update-index', '--force-remove', '--').xargs(rm_files
)
562 GRun('git-update-index', '--').xargs(m_files
)
566 def commit(message
, files
= None, parents
= None, allowempty
= False,
567 cache_update
= True, tree_id
= None, set_head
= False,
568 author_name
= None, author_email
= None, author_date
= None,
569 committer_name
= None, committer_email
= None):
570 """Commit the current tree to repository
577 # Get the tree status
578 if cache_update
and parents
!= []:
579 changes
= update_cache(files
)
580 if not changes
and not allowempty
:
581 raise GitException
, 'No changes to commit'
583 # get the commit message
586 elif message
[-1:] != '\n':
589 # write the index to repository
591 tree_id
= GRun('git-write-tree').output_one_line()
597 env
['GIT_AUTHOR_NAME'] = author_name
599 env
['GIT_AUTHOR_EMAIL'] = author_email
601 env
['GIT_AUTHOR_DATE'] = author_date
603 env
['GIT_COMMITTER_NAME'] = committer_name
605 env
['GIT_COMMITTER_EMAIL'] = committer_email
606 commit_id
= GRun('git-commit-tree', tree_id
,
607 *sum([['-p', p
] for p
in parents
], [])
608 ).env(env
).raw_input(message
).output_one_line()
610 __set_head(commit_id
)
614 def apply_diff(rev1
, rev2
, check_index
= True, files
= None):
615 """Apply the diff between rev1 and rev2 onto the current
616 index. This function doesn't need to raise an exception since it
617 is only used for fast-pushing a patch. If this operation fails,
618 the pushing would fall back to the three-way merge.
621 index_opt
= ['--index']
628 diff_str
= diff(files
, rev1
, rev2
)
631 GRun('git-apply', *index_opt
).raw_input(
632 diff_str
).discard_stderr().no_output()
633 except GitRunException
:
638 def merge(base
, head1
, head2
, recursive
= False):
639 """Perform a 3-way merge between base, head1 and head2 into the
646 # this operation tracks renames but it is slower (used in
647 # general when pushing or picking patches)
649 # discard output to mask the verbose prints of the tool
650 GRun('git-merge-recursive', base
, '--', head1
, head2
652 except GitRunException
, ex
:
656 # the fast case where we don't track renames (used when the
657 # distance between base and heads is small, i.e. folding or
658 # synchronising patches)
660 GRun('git-read-tree', '-u', '-m', '--aggressive',
661 base
, head1
, head2
).run()
662 except GitRunException
:
663 raise GitException
, 'git-read-tree failed (local changes maybe?)'
665 # check the index for unmerged entries
667 stages_re
= re
.compile('^([0-7]+) ([0-9a-f]{40}) ([1-3])\t(.*)$', re
.S
)
669 for line
in GRun('git-ls-files', '--unmerged', '--stage', '-z'
670 ).raw_output().split('\0'):
674 mode
, hash, stage
, path
= stages_re
.findall(line
)[0]
676 if not path
in files
:
678 files
[path
]['1'] = ('', '')
679 files
[path
]['2'] = ('', '')
680 files
[path
]['3'] = ('', '')
682 files
[path
][stage
] = (mode
, hash)
684 if err_output
and not files
:
685 # if no unmerged files, there was probably a different type of
686 # error and we have to abort the merge
687 raise GitException
, err_output
689 # merge the unmerged files
692 # remove additional files that might be generated for some
693 # newer versions of GIT
694 for suffix
in [base
, head1
, head2
]:
697 fname
= path
+ '~' + suffix
698 if os
.path
.exists(fname
):
702 if gitmergeonefile
.merge(stages
['1'][1], stages
['2'][1],
703 stages
['3'][1], path
, stages
['1'][0],
704 stages
['2'][0], stages
['3'][0]) != 0:
708 raise GitException
, 'GIT index merging failed (possible conflicts)'
710 def status(files
= None, modified
= False, new
= False, deleted
= False,
711 conflict
= False, unknown
= False, noexclude
= False,
713 """Show the tree status
718 cache_files
= tree_status(files
, unknown
= True, noexclude
= noexclude
,
719 diff_flags
= diff_flags
)
720 all
= not (modified
or new
or deleted
or conflict
or unknown
)
735 cache_files
= [x
for x
in cache_files
if x
[0] in filestat
]
737 for fs
in cache_files
:
738 if files
and not fs
[1] in files
:
741 out
.stdout('%s %s' % (fs
[0], fs
[1]))
743 out
.stdout('%s' % fs
[1])
745 def diff(files
= None, rev1
= 'HEAD', rev2
= None, diff_flags
= []):
746 """Show the diff between rev1 and rev2
752 return GRun('git-diff-tree', '-p',
753 *(diff_flags
+ [rev1
, rev2
, '--'] + files
)).raw_output()
757 return GRun('git-diff-index', '-p', '-R',
758 *(diff_flags
+ [rev2
, '--'] + files
)).raw_output()
760 return GRun('git-diff-index', '-p',
761 *(diff_flags
+ [rev1
, '--'] + files
)).raw_output()
765 # TODO: take another parameter representing a diff string as we
766 # usually invoke git.diff() form the calling functions
767 def diffstat(files
= None, rev1
= 'HEAD', rev2
= None):
768 """Return the diffstat between rev1 and rev2."""
769 return GRun('git-apply', '--stat', '--summary'
770 ).raw_input(diff(files
, rev1
, rev2
)).raw_output()
772 def files(rev1
, rev2
, diff_flags
= []):
773 """Return the files modified between rev1 and rev2
777 for line
in GRun('git-diff-tree', *(diff_flags
+ ['-r', rev1
, rev2
])
779 result
.append('%s %s' % tuple(line
.split(' ', 4)[-1].split('\t', 1)))
781 return '\n'.join(result
)
783 def barefiles(rev1
, rev2
):
784 """Return the files modified between rev1 and rev2, without status info
788 for line
in GRun('git-diff-tree', '-r', rev1
, rev2
).output_lines():
789 result
.append(line
.split(' ', 4)[-1].split('\t', 1)[-1])
791 return '\n'.join(result
)
793 def pretty_commit(commit_id
= 'HEAD', diff_flags
= []):
794 """Return a given commit (log + diff)
796 return GRun('git-diff-tree',
798 + ['--cc', '--always', '--pretty', '-r', commit_id
])
801 def checkout(files
= None, tree_id
= None, force
= False):
802 """Check out the given or all files
806 GRun('git-read-tree', '--reset', tree_id
).run()
807 except GitRunException
:
808 raise GitException
, 'Failed git-read-tree --reset %s' % tree_id
810 cmd
= ['git-checkout-index', '-q', '-u']
814 GRun(*(cmd
+ ['--'])).xargs(files
)
816 GRun(*(cmd
+ ['-a'])).run()
818 def switch(tree_id
, keep
= False):
819 """Switch the tree to the given id
824 GRun('git-read-tree', '-u', '-m', get_head(), tree_id
).run()
825 except GitRunException
:
826 raise GitException
, 'git-read-tree failed (local changes maybe?)'
830 def reset(files
= None, tree_id
= None, check_out
= True):
831 """Revert the tree changes relative to the given tree_id. It removes
838 cache_files
= tree_status(files
, tree_id
)
839 # files which were added but need to be removed
840 rm_files
= [x
[1] for x
in cache_files
if x
[0] in ['A']]
842 checkout(files
, tree_id
, True)
843 # checkout doesn't remove files
844 map(os
.remove
, rm_files
)
846 # if the reset refers to the whole tree, switch the HEAD as well
850 def fetch(repository
= 'origin', refspec
= None):
851 """Fetches changes from the remote repository, using 'git-fetch'
861 command
= config
.get('branch.%s.stgit.fetchcmd' % get_head_file()) or \
862 config
.get('stgit.fetchcmd')
863 GRun(*(command
.split() + args
)).run()
865 def pull(repository
= 'origin', refspec
= None):
866 """Fetches changes from the remote repository, using 'git-pull'
876 command
= config
.get('branch.%s.stgit.pullcmd' % get_head_file()) or \
877 config
.get('stgit.pullcmd')
878 GRun(*(command
.split() + args
)).run()
881 """Repack all objects into a single pack
883 GRun('git-repack', '-a', '-d', '-f').run()
885 def apply_patch(filename
= None, diff
= None, base
= None,
887 """Apply a patch onto the current or given index. There must not
888 be any local changes in the tree, otherwise the command fails
900 orig_head
= get_head()
906 GRun('git-apply', '--index').raw_input(diff
).no_output()
907 except GitRunException
:
911 # write the failed diff to a file
912 f
= file('.stgit-failed.patch', 'w+')
915 out
.warn('Diff written to the .stgit-failed.patch file')
920 top
= commit(message
= 'temporary commit used for applying a patch',
923 merge(base
, orig_head
, top
)
925 def clone(repository
, local_dir
):
926 """Clone a remote repository. At the moment, just use the
929 GRun('git-clone', repository
, local_dir
).run()
931 def modifying_revs(files
, base_rev
, head_rev
):
932 """Return the revisions from the list modifying the given files."""
933 return GRun('git-rev-list', '%s..%s' % (base_rev
, head_rev
), '--', *files
936 def refspec_localpart(refspec
):
937 m
= re
.match('^[^:]*:([^:]*)$', refspec
)
941 raise GitException
, 'Cannot parse refspec "%s"' % line
943 def refspec_remotepart(refspec
):
944 m
= re
.match('^([^:]*):[^:]*$', refspec
)
948 raise GitException
, 'Cannot parse refspec "%s"' % line
951 def __remotes_from_config():
952 return config
.sections_matching(r
'remote\.(.*)\.url')
954 def __remotes_from_dir(dir):
955 d
= os
.path
.join(basedir
.get(), dir)
956 if os
.path
.exists(d
):
962 """Return the list of remotes in the repository
964 return (set(__remotes_from_config())
965 |
set(__remotes_from_dir('remotes'))
966 |
set(__remotes_from_dir('branches')))
968 def remotes_local_branches(remote
):
969 """Returns the list of local branches fetched from given remote
973 if remote
in __remotes_from_config():
974 for line
in config
.getall('remote.%s.fetch' % remote
):
975 branches
.append(refspec_localpart(line
))
976 elif remote
in __remotes_from_dir('remotes'):
977 stream
= open(os
.path
.join(basedir
.get(), 'remotes', remote
), 'r')
979 # Only consider Pull lines
980 m
= re
.match('^Pull: (.*)\n$', line
)
982 branches
.append(refspec_localpart(m
.group(1)))
984 elif remote
in __remotes_from_dir('branches'):
985 # old-style branches only declare one branch
986 branches
.append('refs/heads/'+remote
);
988 raise GitException
, 'Unknown remote "%s"' % remote
992 def identify_remote(branchname
):
993 """Return the name for the remote to pull the given branchname
994 from, or None if we believe it is a local branch.
997 for remote
in remotes_list():
998 if branchname
in remotes_local_branches(remote
):
1001 # if we get here we've found nothing, the branch is a local one
1005 """Return the git id for the tip of the parent branch as left by
1010 stream
= open(os
.path
.join(basedir
.get(), 'FETCH_HEAD'), "r")
1012 # Only consider lines not tagged not-for-merge
1013 m
= re
.match('^([^\t]*)\t\t', line
)
1016 raise GitException
, "StGit does not support multiple FETCH_HEAD"
1018 fetch_head
=m
.group(1)
1021 # here we are sure to have a single fetch_head
1025 """Return a list of all refs in the current repository.
1028 return [line
.split()[1] for line
in GRun('git-show-ref').output_lines()]