get_git_version无法找到版本号

Ch *_*han 6 git django

在我从文件中引发执行此错误时version.py有一种方法get_git_version()./manage.py runserverversion.py

提出ValueError("找不到版本号!")

def get_git_version(abbrev=4):
    # Read in the version that's currently in RELEASE-VERSION.

    release_version = read_release_version()

    # First try to get the current version using "git describe".

    version = call_git_describe(abbrev)

    # If that doesn't work, fall back on the value that's in
    # RELEASE-VERSION.

    if version is None:
        version = release_version

    # If we still don't have anything, that's an error.

    if version is None:
        raise ValueError("Cannot find the version number!")

    # If the current version is different from what's in the
    # RELEASE-VERSION file, update the file to be current.

    if version != release_version:
        write_release_version(version)

    # Finally, return the current version.

    return version


def read_release_version():
    try:
        f = open("RELEASE-VERSION", "r")

        try:
            version = f.readlines()[0]
            return version.strip()

        finally:
            f.close()
    except:
        return None
Run Code Online (Sandbox Code Playgroud)

Cha*_*esB 4

该脚本需要来自 git 带注释的标记 ( call_git_describe()) 的版本号,或者通过在名为 的文件中查找版本号来获取版本号RELEASE-VERSION。失败是因为这两件事都没有找到,所以修复其中之一。

在您的项目中运行此命令来为当前提交创建带注释的标签:

git tag 1.0 -m "this is version 1.0"
Run Code Online (Sandbox Code Playgroud)

我倾向于使用标签进行版本管理,但文本文件中的版本也很好,YMMV。