8000 IndexFile.add: Fixed incorrect path handling if path rewriting was de… · scoop09/GitPython@8caeec1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8caeec1

Browse files
committed
IndexFile.add: Fixed incorrect path handling if path rewriting was desired and absolute paths were given
Commit.create_from_tree: fixed critical bug that would cause it to create a branch named master by default, instead of the reference actually set ( which is master in many, but not all cases ) - in fact it could be detached as well, we would fail ungracefully although we could assume master then ... although we cant really make the decision Repo.is_dirty: improved its abiility to deal with empty repositories and a missing head. Weird thing is that the test always worked fine with the previous code, but it didn't work for me in a similar situation without this change at least
1 parent de5bc8f commit 8caeec1

File tree

3 files changed

+10
-9
lines changed
  • lib/git
    • < 8000 div class="PRIVATE_TreeView-item-level-line prc-TreeView-TreeViewItemLevelLine-KPSSL">
      objects
  • 3 files changed

    +10
    -9
    lines changed

    lib/git/index.py

    Lines changed: 7 additions & 6 deletions
    Original file line numberDiff line numberDiff line change
    @@ -907,8 +907,9 @@ def add(self, items, force=True, fprogress=lambda *args: None, path_rewriter=Non
    907907
    must be a path relative to our repository.
    908908
    909909
    If their sha is null ( 40*0 ), their path must exist in the file system
    910-
    as an object will be created from the data at the path.The handling
    911-
    now very much equals the way string paths are processed, except that
    910+
    relative to the git repository as an object will be created from
    911+
    the data at the path.
    912+
    The handling now very much equals the way string paths are processed, except that
    912913
    the mode you have set will be kept. This allows you to create symlinks
    913914
    by settings the mode respectively and writing the target of the symlink
    914915
    directly into the file. This equals a default Linux-Symlink which
    @@ -945,6 +946,7 @@ def add(self, items, force=True, fprogress=lambda *args: None, path_rewriter=Non
    945946
    is not identical to the layout of the actual files on your hard-dist.
    946947
    If not None and ``items`` contain plain paths, these paths will be
    947948
    converted to Entries beforehand and passed to the path_rewriter.
    949+
    Please note that entry.path is relative to the git repository.
    948950
    949951
    :return:
    950952
    List(BaseIndexEntries) representing the entries just actually added.
    @@ -962,8 +964,9 @@ def add(self, items, force=True, fprogress=lambda *args: None, path_rewriter=Non
    962964

    963965
    if paths and path_rewriter:
    964966
    for path in paths:
    965-
    abspath = os.path.join(self.repo.working_tree_dir, path)
    966-
    blob = Blob(self.repo, Blob.NULL_HEX_SHA, os.stat(abspath).st_mode, path)
    967+
    abspath = os.path.abspath(path)
    968+
    gitrelative_path = abspath[len(self.repo.working_tree_dir)+1:]
    969+
    blob = Blob(self.repo, Blob.NULL_HEX_SHA, os.stat(abspath).st_mode, gitrelative_path)
    967970
    entries.append(BaseIndexEntry.from_blob(blob))
    968971
    # END for each path
    969972
    del(paths[:])
    @@ -1197,8 +1200,6 @@ def move(self, items, skip_errors=False, **kwargs):
    11971200

    11981201
    return out
    11991202

    1200-
    1201-
    12021203
    @default_index
    12031204
    def commit(self, message, parent_commits=None, head=True):
    12041205
    """

    lib/git/objects/commit.py

    Lines changed: 2 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -357,9 +357,9 @@ def create_from_tree(cls, repo, tree, message, parent_commits=None, head=False):
    357357
    try:
    358358
    repo.head.commit = new_commit
    359359
    except ValueError:
    360-
    # head is not yet set to master - create it and set it
    360+
    # head is not yet set to the ref our HEAD points to.
    361361
    import git.refs
    362-
    master = git.refs.Head.create(repo, 'master', commit=new_commit)
    362+
    master = git.refs.Head.create(repo, repo.head.ref, commit=new_commit)
    363363
    repo.head.reference = master
    364364
    # END handle empty repositories
    365365
    # END advance head handling

    lib/git/repo.py

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -526,7 +526,7 @@ def is_dirty(self, index=True, working_tree=True, untracked_files=False):
    526526
    default_args = ('--abbrev=40', '--full-index', '--raw')
    527527
    if index:
    528528
    # diff index against HEAD
    529-
    if os.path.isfile(self.index.path) and \
    529+
    if os.path.isfile(self.index.path) and self.head.is_valid() and \
    530530
    len(self.git.diff('HEAD', '--cached', *default_args)):
    531531
    return True
    532532
    # END index handling

    0 commit comments

    Comments
     (0)
    0