Code Monkey home page Code Monkey logo

getgitinfo's Introduction

GetGitInfo

###app 内部获取git信息: 思路,通过script脚本获取到想到的信息然后存入info.plist中,然后需要的时候再从info.plist中取出。

1. 在xcode的build phase中加入script:

#最后一次提交的SHA
git_version=$(git log -1 --format="%h")

#当前的分支
git_branch=$(git symbolic-ref --short -q HEAD)

#最后一次提交的作者
git_last_commit_user=$(git log -1 --pretty=format:'%an')

#最后一次提交的时间
git_last_commit_date=$(git log -1 --format='%cd')

#编译时间
build_time=$(date)

info_plist="${BUILT_PRODUCTS_DIR}/${EXECUTABLE_FOLDER_PATH}/Info.plist"
/usr/libexec/PlistBuddy -c "Set :'GitCommitSHA'       '${git_version}'"                "${info_plist}"
/usr/libexec/PlistBuddy -c "Set :'GitCommitBranch'    '${git_branch}'"                 "${info_plist}"
/usr/libexec/PlistBuddy -c "Set :'GitCommitUser'      '${git_last_commit_user}'"       "${info_plist}"
/usr/libexec/PlistBuddy -c "Set :'GitCommitDate'      '${git_last_commit_date}'"       "${info_plist}"
/usr/libexec/PlistBuddy -c "Set :'BuildTime'          '${build_time}'"                 "${info_plist}"

2. 在info.plist中加入对象的键值对:

	<key>GitCommitSHA</key>
    <string></string>
    <key>GitCommitBranch</key>
    <string></string>
    <key>GitCommitUser</key>
    <string></string>
    <key>GitCommitDate</key>
    <string></string>
    <key>BuildTime</key>
    <string></string>

3. 带代码获取并使用:


NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
    
    _commitLabel.text = [NSString stringWithFormat:@"最后提交SHA:%@", [infoDic objectForKey:@"GitCommitSHA"]];
    
    _branchLabel.text = [NSString stringWithFormat:@"当前所在分支:%@", [infoDic objectForKey:@"GitCommitBranch"]];
    
    _authorLabel.text = [NSString stringWithFormat:@"最后提交用户:%@", [infoDic objectForKey:@"GitCommitUser"]];
    
    _dateLabel.text = [NSString stringWithFormat:@"最后提交时间:%@", [infoDic objectForKey:@"GitCommitDate"]];
    
    _buildTimeLabel.text = [NSString stringWithFormat:@"本次编译时间:%@", [infoDic objectForKey:@"BuildTime"]];

展示图片

getgitinfo's People

Contributors

y500 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.